Payments API
Process payments and manage transactions using MercadoPago integration.Create Payment
Endpoint:POST /create-payment
Authentication: Not required (public endpoint)
Creates a payment and returns a MercadoPago checkout link.
Request Body
Total amount to charge (mutually exclusive with originalAmount)
Base amount before surcharges (mutually exclusive with amount)
Associated appointment/booking ID
Payment description (default: “Consulta Legal”)
Client user ID (“guest” for anonymous users)
Lawyer user ID (“consulta-general” for general consultations)
Redirect URL on successful payment
Redirect URL on failed payment
Redirect URL for pending payment
Client email address
Client name
Payment Calculation
The system automatically calculates:- Original Amount: Base price set by lawyer
- Client Surcharge: Platform fee paid by client (default 10%)
- Platform Fee: Commission kept by platform (default 20% of original)
- Lawyer Amount: Amount transferred to lawyer (80% of original)
platform_settings table.
Example Request
Response
Operation success status
Created payment ID (UUID)
MercadoPago checkout URL
Success message
Example Response
200 - Success
Error Responses
400 - Missing Fields
400 - Invalid Amount
500 - Server Error
Get Payment Status
Endpoint:GET /payment/:paymentId
Authentication: Not required
Path Parameters
Payment ID (UUID)
Response
Payment details
Payment ID
Base amount (CLP)
Surcharge amount (CLP)
Surcharge percentage (e.g., 0.1 for 10%)
Platform commission (CLP)
Platform fee percentage (e.g., 0.2 for 20%)
Amount for lawyer (CLP)
Currency code (“CLP”)
Payment status:
pending, succeeded, failedClient user ID
Lawyer user ID
Creation timestamp (ISO 8601)
Last update timestamp (ISO 8601)
Example Response
200 - Success
404 - Not Found
MercadoPago Webhook
Endpoint:POST /api/mercadopago/webhook
Authentication: MercadoPago signature validation
Receives payment notifications from MercadoPago.
Webhook Payload
Notification type (“payment”)
Event topic (“payment”)
Example Webhook Payload
Webhook Actions (Approved Payment)
When a payment is approved, the system:- Updates booking status to
confirmed - Creates user account if guest booking
- Creates/updates profile for the user
- Creates appointment record for lawyer dashboard
- Associates booking with user
- Sends email confirmations to client and lawyer
- Tracks payment event for analytics
Response
200 - OK
500 - Error
Manual Payment Reconciliation
Endpoint:POST /api/mercadopago/reconcile/:paymentId
Authentication: Secret header required
Use case: Backup endpoint if webhook delivery fails
Headers
Admin reconciliation secret (env:
MP_RECONCILE_SECRET)Path Parameters
MercadoPago payment ID (not upLegal payment ID)
Response
Reconciliation success
MercadoPago payment ID
Booking/appointment ID
Whether booking was updated
Created or found client user ID
Example Response
200 - Success
401 - Unauthorized
404 - Not Found
409 - Not Approved
Payment States
| Status | Description |
|---|---|
pending | Payment created, awaiting confirmation |
succeeded | Payment successful, funds transferred |
failed | Payment failed or rejected |
Currency
All payments are processed in Chilean Pesos (CLP). The minimum payment amount is 1,000 CLP.RLS Policies
Payments Table
- SELECT: Users can view their own payments (as client or lawyer)
- INSERT: Service role only (via RPC function)
- UPDATE: Service role only (via webhook)
- DELETE: Not allowed
Test Mode
MercadoPago sandbox credentials can be used for testing:- Test cards available at MercadoPago Developers
- Sandbox payments return
sandbox_init_pointinstead ofinit_point