Skip to main content
Saving a card starts by creating a payment method via the Compago API. This returns a checkout URL where your customer securely enters their card details. Once the card is verified, it’s stored securely and you can charge it on demand.

Creating a Payment Method

Endpoint

API reference: 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. In LINK mode, you redirect the customer to the checkoutUrl 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 the checkoutUrl 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.
Embed the checkout URL in your page:
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
You can customize the verification amount:
Set the verification amount close to the actual amount you plan to charge the customer later. Issuer banks are more likely to automatically reject future charges that differ significantly from the verification amount, so a closer match reduces the risk of payment declines.
Some banks may show the verification charge as a pending transaction for a few days before it disappears. Consider notifying your customers about this.

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 your redirectUrl with two query parameters:
  • id: The Compago payment method ID
  • externalId: The external ID you provided when creating the payment method
For example, if you created a payment method with:
The customer will be redirected to:

Redirect Implementation

Using Iframe Events (EMBEDDED Mode)

In EMBEDDED mode, the checkout iframe sends postMessage 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:
Success event:
Error event:
Validate that event.data.type starts with COMPAGO_PAYMENT_METHOD_ before processing. This filters out unrelated postMessage events from other scripts or browser extensions.
Even when using iframe events, always verify the payment method status via the API before trusting the result. The COMPAGO_PAYMENT_METHOD_SUCCESS event confirms the checkout completed, but your backend should call GET /api/payment-method/{id} to confirm the status is ACTIVE before storing the card for future charges.

Best Practices

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.
Save the Compago payment method id in your database associated with the customer. You’ll need this ID to charge the card later.
Let customers know that a small temporary charge will appear on their statement during the card verification process. This prevents confusion and support requests.
If the checkout link expires before the customer saves their card, create a new payment method and send the customer the updated checkout URL.
Always use HTTPS URLs for your redirectUrl to ensure query parameters are transmitted securely.

Error Handling

Security Considerations

Never skip verification! The redirect URL is visible to the customer and could be manipulated. Always fetch the payment method status from Compago’s API using the id parameter before storing it.
Your redirect implementation should:
  1. Validate query parameters exist before processing
  2. Fetch payment method status from Compago API. Don’t trust the redirect alone
  3. Verify the externalId matches your records. Ensure it corresponds to a real customer in your system
  4. Check status is ACTIVE before allowing future charges
  5. 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.