Creating a Payment Method
Endpoint
POST /payment-method
Authentication
Include your API key in the request headers:Request Body
Field Descriptions
| Field | Type | Required | Description |
|---|---|---|---|
externalId | string | No | Your unique identifier for this payment method (e.g., customer ID). |
verificationAmount | number | No | Amount in MXN for the verification charge. Minimum 1 MXN. Defaults to 1 MXN. |
billingInformation | object | Yes | Customer billing details (see below). |
displayMode | string | No | "LINK" (default) for full-page redirect or "EMBEDDED" for iframe. See Display Modes. |
buttonText | string | No | Custom text for the checkout button (EMBEDDED mode only). |
buttonColor | string | No | Custom hex color for the checkout button, e.g. "#16A34A" (EMBEDDED mode only). |
redirectUrl | string | No | URL where the customer is redirected after saving their card. Compago appends id and externalId as query parameters. |
ttlMinutes | integer | No | Time-to-live in minutes for the checkout link. Minimum 1 minute. Defaults to 2,880 (48 hours). |
Billing Information
| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Customer’s email address. |
firstName | string | Yes | Customer’s first name. |
lastName | string | Yes | Customer’s last name. |
phoneNumber | string | Yes | Customer’s phone number (include country code, e.g., +521…). |
Response
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier of the payment method. Use this to charge, retrieve, or revoke it later. |
checkoutUrl | string | URL where the customer completes the card-saving process. |
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
| Event Type | Payload | When Fired |
|---|---|---|
COMPAGO_PAYMENT_METHOD_LOADING | { type } | Checkout iframe loads |
COMPAGO_PAYMENT_METHOD_SUCCESS | { type, data: { paymentMethodId, cardLastFour, cardNetwork, billingEmail } } | Card saved successfully |
COMPAGO_PAYMENT_METHOD_ERROR | { type, error: { code, message } } | Card verification fails |
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
| Status Code | Error | Solution |
|---|---|---|
| 400 | Invalid billing information | Ensure all required billing fields are provided and valid. |
| 400 | Missing organization context | Verify your organization settings are configured correctly. |
| 401 | Unauthorized | Check your API key is valid and included in headers. |
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.