Overview
This endpoint allows authenticated users to add a new payment method to their account. Payment methods are used to facilitate currency exchange transactions and can include bank transfers, mobile payments, and email-based payment services.Authentication
This endpoint requires authentication via theverifyToken middleware. Include a valid JWT token in the Authorization header.
Endpoint
/api/payments-methods/add
Request
Headers
Bearer token for authentication
Must be set to
application/jsonBody Parameters
The type of payment method being added. Common values include:
bank_transfer- For bank account transfersmobile_payment- For mobile payment servicesemail_payment- For email-based payment services
National identification number (CI - Cédula de Identidad) of the payment method owner. This is used for verification purposes.
Name of the bank for bank transfer payment methods. Required when
type is bank_transfer.Example: “Banco Nacional”, “Banco Provincial”Phone number for mobile payment methods. Required when
type is mobile_payment.Example: “+58 412-1234567”Full name of the person who owns the payment method. This should match the name associated with the bank account, phone number, or email payment service.
Email address for email-based payment services. Required when
type is email_payment.Example: “[email protected]”Example Requests
Response
Success Response (201 Created)
Returns the newly created payment method object with its assigned ID.Unique identifier assigned to the newly created payment method
Type of payment method that was created
National identification number associated with the payment method
Bank name (null if not applicable)
Phone number (null if not applicable)
Name of the payment method owner
Email address (null if not applicable)
Example Response
Error Responses
Implementation Details
- Controller:
paymentsController.createPaymentMethod - Middleware:
verifyToken(authentication required) - Database Operation: Inserts a new record into the
payment_methodstable - User Context: The user ID is automatically extracted from the JWT token via
req.user.id - Response Code: Returns HTTP 201 (Created) on success
Business Logic
- The endpoint extracts the authenticated user’s ID from the JWT token
- All payment method data from the request body is validated
- A new record is inserted into the
payment_methodstable with the user’s ID - The newly created payment method is returned with its database-assigned ID
- The user can then use this payment method for currency exchange transactions
Best Practices
- Validation: Ensure required fields match the payment method type (e.g.,
bankfor bank transfers,phonefor mobile payments) - Data Format: Use consistent formatting for phone numbers and identification numbers
- Security: Never expose sensitive banking information in logs or error messages
- User Experience: Validate payment method details on the client side before submission
- Uniqueness: Consider implementing checks to prevent duplicate payment methods