Endpoint
Note: This endpoint is under the
/api/reservations path, not /api/payments, as it’s part of the reservation creation flow.Description
Generates a payment preference (e.g., for MercadoPago) based on reservation information. This preference is used to initiate the payment process with external payment providers. See implementation inserver/src/modules/reservations/reservations.controller.ts:58-68.
Authentication
This endpoint requires Bearer token authentication. Include your access token in the
Authorization header.Request Body
Provide reservation information to generate the payment preference.ID of the client making the reservation
ID of the professional
Start time of the reservation in ISO 8601 format
End time of the reservation in ISO 8601 format
Type of session:
Virtual, Presencial, or empty stringAmount to charge for the reservation deposit
Response
Returns a payment preference object from the payment provider (structure depends on the provider, typically MercadoPago).Payment preference ID from the provider
URL where the user should be redirected to complete payment
URL for testing in sandbox environment
Example Request
Example Response
Error Responses
Bad Request
Unauthorized
Workflow
Create Reservation
Call Create With Payment with the payment information to finalize the reservation
Integration Notes
MercadoPago Integration
This endpoint integrates with MercadoPago’s preference API. The service layer handles:- Creating the preference with MercadoPago
- Setting callback URLs for success/failure
- Including reservation metadata
- Configuring payment methods
Payment Amount
Thedeposit_amount should match the professional’s configuration:
- Check Professional Settings for the required
deposit_amount - Ensure the amount matches to avoid discrepancies
Testing
For testing:- Use
sandbox_init_pointinstead ofinit_point - Use MercadoPago test credentials and test cards
- Payment provider typically offers a sandbox environment
Best Practices
- Always validate the deposit amount against professional settings
- Store the preference ID for reference
- Implement proper error handling for payment failures
- Set appropriate success and failure callback URLs
- Display clear payment instructions to users
- Handle edge cases (payment timeout, cancellation, etc.)
Related Endpoints
- Create With Payment - Create reservation after payment
- Professional Settings - Get deposit requirements
- Create Payment - Register payment record (if applicable)
Security
- Never expose your payment provider’s secret keys
- Validate all callback data from the payment provider
- Use HTTPS for all payment-related operations
- Implement webhook verification for payment notifications