Creating a Payment Method
Endpoint
POST /payment-method
Authentication
Include your API key in the request headers:Request Body
Field Descriptions
Billing Information
Response
Code Examples
Display Modes
Compago supports two display modes for the card-saving checkout experience.LINK Mode (Default)
In LINK mode, you redirect the customer to thecheckoutUrl returned by the API. The customer completes the card-saving flow on a full-page Compago checkout page and is then redirected back to your redirectUrl.
This is the simplest integration. Just redirect the customer:
EMBEDDED Mode
In EMBEDDED mode, you embed thecheckoutUrl in an iframe on your own page. This keeps the customer on your site throughout the process. You can customize the checkout button appearance using buttonText and buttonColor.
In EMBEDDED mode, the iframe handles the entire card-saving flow. You can listen for iframe events to react to success and error states in real time, or use a
redirectUrl to handle the result via a page redirect. For more details, see Handling the Result.Verification Charge
When a customer saves their card, Compago places a small verification charge to validate that the card is real and has sufficient funds. This charge is automatically voided (reversed). The customer is not actually billed.- Default amount: 1 MXN
- Minimum amount: 1 MXN
- What happens: The charge appears temporarily on the customer’s statement and is then voided
Handling the Result
After a customer completes the card-saving checkout, you need to handle the result. There are two approaches depending on your integration.Using the Redirect URL
When a customer successfully saves their card, Compago redirects them back to yourredirectUrl with two query parameters:
id: The Compago payment method IDexternalId: The external ID you provided when creating the payment method
Redirect Implementation
Using Iframe Events (EMBEDDED Mode)
In EMBEDDED mode, the checkout iframe sendspostMessage events to the parent window so you can react to loading, success, and error states without waiting for a redirect.
Events Reference
Listening for Events
Event Payloads
Loading event:Best Practices
Always Verify Payment Method Status
Always Verify Payment Method Status
After the customer is redirected back, always fetch the payment method from the API to confirm its status is
ACTIVE before storing it for future charges.Store the Payment Method ID
Store the Payment Method ID
Save the Compago payment method
id in your database associated with the customer. You’ll need this ID to charge the card later.Inform Customers About the Verification Charge
Inform Customers About the Verification Charge
Let customers know that a small temporary charge will appear on their statement during the card verification process. This prevents confusion and support requests.
Handle Expiration Gracefully
Handle Expiration Gracefully
If the checkout link expires before the customer saves their card, create a new payment method and send the customer the updated checkout URL.
Use HTTPS for Redirect URLs
Use HTTPS for Redirect URLs
Always use HTTPS URLs for your
redirectUrl to ensure query parameters are transmitted securely.Error Handling
Security Considerations
Your redirect implementation should:- Validate query parameters exist before processing
- Fetch payment method status from Compago API. Don’t trust the redirect alone
- Verify the
externalIdmatches your records. Ensure it corresponds to a real customer in your system - Check status is
ACTIVEbefore allowing future charges - Log all redirect attempts for debugging and security monitoring
Next Steps
Charge a Saved Card
Learn how to charge a customer’s saved card on demand.
Manage Payment Methods
List, retrieve, and revoke saved payment methods.