Guides

Charge a saved card

Charge a saved payment method with method card_on_file, handle every outcome, and retry without ever charging twice.

A saved card (pm_..., see save-a-card) is charged with the same call as any payment, with method: card_on_file. The answer comes back in the same request, as for a keyed payment. You need the scope payment_methods:charge as well as payments:write: a key without it cannot charge a saved card.

POST /v1/payments
{"merchant_id":"mch_01j...","amount_cents":4900,"platform_reference":"sub-77-2026-12:a1","method":"card_on_file","payment_method":"pm_01j...","initiated_by":"merchant","description":"December membership"}

Send an Idempotency-Key. merchant_id is optional for method: card_on_file: without it, the MonetizePay-Account header, else the platform's only merchant in this mode (see save-a-card). Terminal and plain keyed payments still need it in the body.

  • payment_method is the saved card. It must belong to the same merchant: another merchant's saved card answers 404 resource_missing (param payment_method), the same answer as an id that does not exist.
  • initiated_by is required: customer when the cardholder is in your app choosing to pay now, merchant when your schedule or the merchant's staff started it (a renewal). It is a record only and changes nothing in the charge.
  • nonce, terminal_id, terminal_options and save_payment_method are refused with card_on_file.

One reference per attempt

Charge each obligation (a billing cycle, an invoice) under a reference and a key you derive from it, with an attempt number: {cycle_id}:a{attempt}, the same string for platform_reference and the Idempotency-Key. Start at attempt 1. Keep the same attempt for every retry of an unknown outcome, and move to the next attempt only after a definite failure. A reference made from the cycle alone could never be charged again after a decline, because the reference stays pinned to the failed payment. References starting with zp: are reserved for Monetize.Pay.

Outcomes

AnswerMeaningWhat to do
201, state: succeededPaidDone
201, failed, card_declinedThe card was declinedFinal for this reference. Tell the cardholder; try again later as a new attempt, or ask for another card
201, failed, duplicate_transactionThe Processor's duplicate screen refused a second equal charge on the card shortly after another. Not a card decline. In test mode only test card 4000 0000 0000 0135 (or tok_duplicate) gets itDo not ask for another card. Check the earlier charge is the one you meant. If a second equal charge is really intended, send it later as a new attempt
201, failed, processor_rejectedThe Processor refused the request as invalid. Not a card declineFinal for this reference. Contact Monetize.Pay if it repeats
201, failed, partial_approval, partial_approval.reversed: trueThe card approved only part of the amount; Monetize.Pay voided it at once. A saved card is never charged for less than askedFinal for this reference. Treat as a decline
201, failed, partial_approval, partial_approval.reversed: falseAs above, but the void is not yet confirmed: part of the amount may still be held on the cardDo not charge that obligation again yet (rule 5 below)
201, failed, processor_unverifiedUnknown: the card may or may not have been chargedStop (rule 3 below)
502 processor_unavailableThe answer was lost; the payment stays pendingRetry the identical request (rule 1 below)
409 payment_in_progressA charge for this reference is still running, or the Processor answered and Monetize.Pay is still recording itWait Retry-After seconds and retry the identical request
409 payment_method_unusableThe saved card cannot be charged (deleted, erased, the merchant disconnected or changed account). No payment was writtenRule 6 below
409 payment_resume_method_unusableA pending payment holds this reference and may have captured, and its card can no longer be used to finish itRule 6 below
409 payment_resume_mismatchYou changed the card or the amount for a reference whose payment is still pendingSend the original body
400 card_on_file_unavailableLive mode, and saved cards are not switched on for your platformSee going-live
403 insufficient_scopeThe key lacks payment_methods:chargeUse a key that has it

The payment object's partial_approval block is the source of truth for a partial approval: partial_approval.reversed turns true once the void is confirmed and never goes back. The payment.failed event carries the same block as it was at that moment, and payment.reversed_late announces a later confirmation. If you missed an event, read GET /v1/payments/{payment_id}. Do not retry with a new reference, and do not wait in a loop on the payment: wait for the webhook, or retrieve the payment.

Retry rules

  1. On 502 processor_unavailable, or 409 payment_in_progress, retry the identical request: same Idempotency-Key, same body. At most 3 retries, spaced (for example 5 seconds, 1 minute, 5 minutes), all inside 15 minutes.
  2. Never change the card, the amount or the platform_reference for that charge. The service refuses it (payment_resume_mismatch), and a new reference could be a second charge.
  3. If it is still unknown, stop. processor_unverified means "unknown", not "declined". Do not charge the cycle again under a new reference until the outcome is known.
  4. A definite failure (card_declined, duplicate_transaction, processor_rejected, card_not_saved, and partial_approval whose payment.failed event says partial_approval.reversed: true) is final for that reference. A later attempt is a new logical charge with a new reference, on your own schedule.
  5. partial_approval with reversed: false is unresolved: do not charge that obligation again until payment.reversed_late names the transaction, the payment object's partial_approval.reversed reads true, or Monetize.Pay resolves the standing_authorization alert.
  6. payment_method_unusable (409) wrote no payment: fix the cause and send again under a new Idempotency-Key with the same reference. payment_resume_method_unusable (409) means a pending payment holds the reference and may have captured: treat it as rule 3 (stop; do not charge again until the outcome is known). A partial sale that is never voided settles, and a new full charge on top is an overcharge by the partial amount.

"Known" means one of: the payment.succeeded or payment.failed webhook, a GET /v1/payments/{payment_id} that shows a final state with a code other than processor_unverified, or an answer from Monetize.Pay. A payment left pending for 15 minutes is ended by Monetize.Pay as failed / processor_unverified (the payment.failed event says so); its reference stays pinned. handle-every-payment-state explains how an unverified payment is resolved.

Deleting a card with a charge in flight

DELETE /v1/payment_methods/{payment_method_id} (and its twin POST /v1/payment_methods/{payment_method_id}/detach) answers 409 payment_method_in_use with Retry-After while a payment that uses the card is still pending: that payment may need the card to finish. Wait the seconds given and send the delete again. A pending payment is ended within 15 minutes, or kept longer only while Monetize.Pay is still recording an answer the Processor gave.

Refunds, voids and receipts

A saved-card payment is refunded, voided and receipted exactly like a keyed payment (refunds-and-voids); nothing needs the saved card, and deleting the card later changes nothing for past payments. In test mode Monetize.Pay's sandbox answers them, as for any keyed payment: void before settlement, refund after (sandbox, "Settlement").

Expired and replaced cards

Monetize.Pay does not refuse a charge because the card's printed expiry has passed, and a decline never marks the card unusable. There is no card updater: when a card is replaced, ask the cardholder to save the new one (as a new payment method) and delete the old one. The saved card's token is never shown and cannot be exported.

Test mode

Every test charge of a saved card is answered by Monetize.Pay's sandbox. Save "nonce": "tok_visa" to see charges succeed and "nonce": "tok_chargeDeclined" to see them declined (sandbox, "Test card tokens"). A card typed into the form works the same way: 4761 7390 0101 0010 succeeds and 4111 1111 1111 1111 is declined (save-a-card, "Testing in the sandbox").