Saltar al contenido principal
Once a customer has saved their card and the payment method status is ACTIVE, you can charge it at any time by calling the charge endpoint. No customer interaction is required. The charge is processed entirely server-side.

Overview

Charging a saved card allows you to:
  • Bill customers for subscriptions, memberships, or recurring services
  • Charge after service delivery (on-demand services, freight, freelance work)
  • Process payments when orders ship or milestones are reached

Prerequisites

Before charging a saved card:
  • The payment method must have a status of ACTIVE
  • You must have the payment method id (returned when creating the payment method)
  • The card must not be expired or revoked

Creating a Charge

These examples call the production host. While you build, replace https://api-harmony.compago.com with https://demo-api-harmony.compago.com and use a key from the Demo dashboard. See Environments.

Endpoint

API reference: POST /payment-method/{id}/payment

Authentication

Include your API key in the request headers:

Path Parameters

string
requerido
The unique identifier of the payment method to charge (UUID).

Request Body

Field Descriptions

Charging a card is unchanged. The contract you already use (amount, currency, description) is untouched, and holdFunds is optional and defaults to false, so a request that omits it charges the card immediately, exactly as it always has. Send holdFunds: true only when you want to hold funds instead of charging them.
holdFunds is the only name for this flag, and an unrecognized field is ignored rather than rejected. If you built against an earlier preview of the hold feature, check the name you send: there is no alias, so a request carrying any other spelling of this flag is treated as a request that set nothing, and the card is charged immediately instead of held. Confirm the response status is HELD before you treat a hold as placed.

Response

The response also carries the hold fields (heldAmount, heldAt, capturedAt, holdReleasedAt, holdExpiresAt, holdExpired, holdDaysRemaining). On a regular charge they are null, with holdExpired set to false. They are only populated on holds, and are documented in Hold Funds.

Code Examples

Checking Payment Status

After creating a charge, you can check its status at any time:
API reference: GET /payment-method/{id}/payment/{paymentId}

Choosing the deposit account

A business can receive its sales in more than one bank account, for example one per branch or per line of business. The accounts are registered in the dashboard, at Configuraciones → Organización → Cuentas bancarias, where the owner also decides how sales are shared between them: automatically, by a monthly amount for each account, by a percentage for each account, or manually, sale by sale. Send bankAccountId to decide where the money of one charge is deposited. A saved card can pay for several things, for example two subscriptions that belong to different accounts, so the account is chosen on each charge and is never remembered on the card:
bankAccountId is optional, and an integration that does not send it does not need to change. A charge made without it is deposited exactly as before.
  • List your accounts, and see how your business shares its sales, with GET /developer/v1/bank-account.
  • The account must be one of your own and must be verified. Otherwise the request is refused with BANK_ACCOUNT_NOT_AVAILABLE and the card is not charged.
  • null is the same as leaving the field out.
  • It works the same on a hold: the money is deposited in that account when you capture it.
  • The response returns bankAccountId: the account the charge is deposited in. Once the charge is approved, GET /developer/v1/payment/{id} returns it too.
  • If the account you named is removed before the charge is approved, the payment is deposited according to the rule of your business instead.

Splitting a payment between accounts

Send allocations to split the money of one charge between several of your bank accounts. Each part names an account and the amount it receives. It is how a store that sells on consignment pays each supplier their share of a sale, or how a business keeps the money of two lines of business apart. For example, a $1,500 MXN sale where $600 MXN belong to a supplier, who receives them whole:
The supplier’s account receives $600 MXN. The rest of the sale ($900 MXN) follows your deposit rule and pays Compago’s whole fee. Rules for the parts:
  • Up to 5 parts, on charges in MXN only, and never together with bankAccountId. What the parts leave counts as one more, so five parts must add up to the whole amount.
  • The parts may add up to less than amount: what they leave is deposited according to your deposit rule. They may not add up to more.
  • The fee and its IVA are worked out once on the whole payment. The tip, the fee and the IVA are shared out between the parts that pay the fee (and what your deposit rule receives), in proportion to their amounts. A part with absorbsFee: false receives no tip.
  • Every figure of a part is in centavos. The largest part that pays the fee takes the fraction of a centavo left over, so the parts always add up to the payment exactly.
  • If what is left for the parts that pay the fee does not cover the fee, every part pays its share of it, the ones with absorbsFee: false included, so leave enough of the amount to pay the fee.
  • When the parts add up to the whole amount, at least one of them must pay the fee (absorbsFee: true).
  • A request that breaks one of these rules fails with BANK_ACCOUNT_ALLOCATIONS_INVALID, and an account that is not one of your verified accounts fails with BANK_ACCOUNT_NOT_AVAILABLE. Either way, the card is not charged.
  • A refund made the same day is shared out between the parts in proportion to what each one received. A later refund is taken from your next settlements, never from an account that receives a part with absorbsFee: false.
  • Once the charge is approved, GET /developer/v1/payment/{id} returns the parts it was deposited in as allocations. On a hold, the parts apply when you capture it.
Your customer pays one amount and sees one payment. The split only decides where the money is deposited.

Idempotency (externalId)

POST /api/developer/v1/payment-method/{id}/payment accepts an optional externalId: your own key for this operation, up to 255 characters, unique across all payments in your organization. It is the supported way to make this endpoint safe to retry, and we recommend sending one on every charge. Without it, a retry after a timeout charges the card a second time. A network error tells you nothing about whether the bank approved the first attempt, so a blind retry of a $500 MXN charge can take $1,000 MXN. With an externalId, the retry returns the payment you already made.
This is not the payment method externalId. They are two different fields, one screen apart in these docs:
  • The payment method externalId, sent to POST /api/developer/v1/payment-method and documented in Manage Payment Methods, is your reference for the saved card or customer.
  • The payment externalId, sent to POST /api/developer/v1/payment-method/{id}/payment and documented here, is your idempotency key for one charge or hold.
They live in separate namespaces, so the same string may safely be used for both. They are never compared with each other.

Replay Behaviour

A declined attempt spends the externalId. This surprises people, so it is worth stating plainly: if the bank declines the charge, replaying the same externalId returns that decline again, it does not try the card a second time. To retry a declined charge you must send a new externalId, for example invoice-2025-01-8842-2.This is deliberate. An idempotency key names one attempt, not one intention. The endpoint cannot tell “my HTTP client retried” from “my operator pressed the button again”, and freeing the key on a decline would let a duplicate retry fire a second authorization at the issuer, which feeds their fraud heuristics and can produce a genuine double charge when the bank actually approved a request we recorded as declined.
Charges and holds share one externalId namespace, because both are created by this same endpoint. order-1 cannot exist as a charge and also as a hold. Replaying a key with a different holdFunds value than the original returns the original payment rather than an error, so keep the flag stable across your retries.
The key is echoed back as externalId on every payment response for a saved card (the charge itself, capture, release, refund, list and detail), so you can reconcile our payment id against your own order reference without keeping a mapping table.

Important Business Rules

Payment method must be ACTIVE. You can only charge payment methods with an ACTIVE status. Attempting to charge a PENDING, EXPIRED, or REVOKED payment method will result in a 400 error.
Card expiration. If the customer’s card has expired since it was saved, the charge will fail. In this case, you’ll need to create a new payment method and have the customer save an updated card.
Currency restriction. Only MXN (Mexican Peso) is currently supported. Charges in other currencies will be rejected.

Error Handling

A bankAccountId that cannot receive the payment answers 422, with its code and message inside error:

Next Steps

Hold Funds

Hold funds on a card with holdFunds, then capture them (in full or in part) or release them within 7 natural days.

Process Refunds

Issue full refunds for charges made against saved cards.

Manage Payment Methods

List, retrieve, and revoke payment methods and view payment history.