Overview
Thesettle() method handles settlement (capture) requests for previously authorized payments. Settlement is the process of capturing the authorized funds and initiating the transfer from the customer to the merchant. This typically occurs when an order is invoiced or shipped.
Method signature
Parameters
The settlement request object from VTEX.
Unique identifier for the original payment transaction
Unique identifier for this settlement request
Authorization identifier from the original authorization response
Amount to settle in cents (may be partial)
Transaction identifier from the original authorization
Response
The settlement response indicating the result of the settlement request.
Echo of the payment identifier from the request
Unique identifier for this settlement (present when approved)
Actual amount settled in cents (may differ from requested amount)
Response code from the payment provider
Human-readable message describing the settlement result
Echo of the request identifier from the request
Response types
- Approved
- Denied
Settlement was successfully processed and funds will be captured.
Implementation
The test suite implementation shows the basic pattern:Common scenarios
Full settlement
Capture the entire authorized amount:Partial settlement
Some payment providers support settling only part of the authorized amount:Multiple settlements
Handle multiple settlement requests for the same payment (split settlements):Idempotent settlements
Handle duplicate settlement requests:Helper methods
The@vtex/payment-provider package provides helper methods for creating responses:
Error handling
Authorization not found
Authorization not found
Authorization expired
Authorization expired
Already settled
Already settled
If the full amount has already been settled:
Amount exceeds authorization
Amount exceeds authorization
Provider error
Provider error
If the payment provider returns an error:
Best practices
- Validate authorization exists and is still valid before attempting settlement.
- Check authorization expiration - most providers only allow settlement within 5-7 days of authorization.
-
Implement idempotency by storing settlement responses and returning the same response for duplicate
requestIdvalues. - Support partial settlements if your payment provider allows capturing less than the authorized amount.
- Track total settled amount if supporting multiple settlements for the same authorization.
- Include detailed error messages to help merchants understand settlement failures.
- Log all settlement attempts for audit trails and reconciliation.
Payment lifecycle
Settlement can only occur for authorized payments that haven’t been cancelled. After settlement, only refund() operations are possible.Related routes
- authorize() - Create the initial authorization
- cancel() - Cancel an authorized payment before settlement
- refund() - Refund a settled payment