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.
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_methodis the saved card. It must belong to the same merchant: another merchant's saved card answers404 resource_missing(parampayment_method), the same answer as an id that does not exist.initiated_byis required:customerwhen the cardholder is in your app choosing to pay now,merchantwhen 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_optionsandsave_payment_methodare refused withcard_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
| Answer | Meaning | What to do |
|---|---|---|
201, state: succeeded | Paid | Done |
201, failed, card_declined | The card was declined | Final for this reference. Tell the cardholder; try again later as a new attempt, or ask for another card |
201, failed, duplicate_transaction | The 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 it | Do 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_rejected | The Processor refused the request as invalid. Not a card decline | Final for this reference. Contact Monetize.Pay if it repeats |
201, failed, partial_approval, partial_approval.reversed: true | The card approved only part of the amount; Monetize.Pay voided it at once. A saved card is never charged for less than asked | Final for this reference. Treat as a decline |
201, failed, partial_approval, partial_approval.reversed: false | As above, but the void is not yet confirmed: part of the amount may still be held on the card | Do not charge that obligation again yet (rule 5 below) |
201, failed, processor_unverified | Unknown: the card may or may not have been charged | Stop (rule 3 below) |
502 processor_unavailable | The answer was lost; the payment stays pending | Retry the identical request (rule 1 below) |
409 payment_in_progress | A charge for this reference is still running, or the Processor answered and Monetize.Pay is still recording it | Wait Retry-After seconds and retry the identical request |
409 payment_method_unusable | The saved card cannot be charged (deleted, erased, the merchant disconnected or changed account). No payment was written | Rule 6 below |
409 payment_resume_method_unusable | A pending payment holds this reference and may have captured, and its card can no longer be used to finish it | Rule 6 below |
409 payment_resume_mismatch | You changed the card or the amount for a reference whose payment is still pending | Send the original body |
400 card_on_file_unavailable | Live mode, and saved cards are not switched on for your platform | See going-live |
403 insufficient_scope | The key lacks payment_methods:charge | Use 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
- On 502
processor_unavailable, or 409payment_in_progress, retry the identical request: sameIdempotency-Key, same body. At most 3 retries, spaced (for example 5 seconds, 1 minute, 5 minutes), all inside 15 minutes. - Never change the card, the amount or the
platform_referencefor that charge. The service refuses it (payment_resume_mismatch), and a new reference could be a second charge. - If it is still unknown, stop.
processor_unverifiedmeans "unknown", not "declined". Do not charge the cycle again under a new reference until the outcome is known. - A definite failure (
card_declined,duplicate_transaction,processor_rejected,card_not_saved, andpartial_approvalwhosepayment.failedevent sayspartial_approval.reversed: true) is final for that reference. A later attempt is a new logical charge with a new reference, on your own schedule. partial_approvalwithreversed: falseis unresolved: do not charge that obligation again untilpayment.reversed_latenames the transaction, the payment object'spartial_approval.reversedreads true, or Monetize.Pay resolves thestanding_authorizationalert.payment_method_unusable(409) wrote no payment: fix the cause and send again under a newIdempotency-Keywith 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").