Overview
Theauthorize() method is the core payment processing route that handles authorization requests from VTEX. It supports multiple authorization flows including immediate approval/denial, asynchronous processing, bank invoice generation, and redirect-based authentication.
Method signature
Parameters
The authorization request object from VTEX containing payment details.
Unique identifier for the payment transaction
VTEX transaction identifier
Payment method type (e.g., “Visa”, “Mastercard”, “BankInvoice”)
Name of the merchant requesting authorization
Payment amount in cents
Three-letter ISO currency code (e.g., “USD”, “BRL”)
Shopping cart details for the transaction
Response
The authorization response indicating the result of the payment authorization.
Echo of the payment identifier from the request
Authorization status:
approved, denied, or undefined (pending)Transaction identifier from the payment provider
Authorization identifier (present when approved)
Unique sequential number (NSU) for approved transactions
Milliseconds to wait before canceling pending transactions
URL for bank invoice payment (bank invoice flow)
URL to redirect user for authentication (redirect flow)
Human-readable status message
Authorization flows
Theauthorize() method implements different flows based on the payment method and card details:
- Immediate approval
- Immediate denial
- Async approved
- Async denied
- Bank invoice
- Redirect
Card number:
4444333322221111Immediately approves the authorization with all required identifiers.Implementation
The test suite implementation demonstrates key patterns:Key features
Idempotency
The implementation persists authorization responses and returns the same response for duplicate requests with the samepaymentId:
Asynchronous callbacks
For pending transactions, use thecallback() method to notify VTEX of final status:
Flow selection
The framework automatically selects the appropriate flow based on:- Payment method (bank invoice detection)
- Card details (specific test card numbers)
- Card tokenization status (tokenized cards trigger redirect)
Best practices
Always persist responses
Always persist responses
Store authorization responses to ensure idempotent behavior. VTEX may retry requests, and you must return the same response for the same
paymentId.Handle asynchronous flows properly
Handle asynchronous flows properly
For pending authorizations, return immediately with
status: undefined and use the callback mechanism to notify final status. Set appropriate delayToCancel values.Include all required fields
Include all required fields
Approved authorizations must include
tid, authorizationId, and nsu. Missing fields will cause VTEX to reject the response.Validate card details
Validate card details
Check card number format, expiration date, and security code before processing. Return appropriate denial messages for invalid data.