Payments

How payments work

Payment intents, attempts, the statuses a payment goes through, and which signal to trust before you deliver.

Open as Markdown
On this page
  1. Payment intents and attempts
  2. The lifecycle
  3. Each status, and what to do
  4. A canceled payment can still succeed
  5. When something does not add up
  6. Attempts
  7. Next actions
  8. Amounts and currency
  9. Redirects and webhooks: which one to trust
  10. Refunds
  11. Events you receive

Every payment, by card or in cash, is a payment intent: one object for one amount you want to collect, from creation to the money received. You create it yourself, or a checkout session or a payment link creates it for you. Its status tells you where it stands; your code reads it rather than guessing.

Payment intents and attempts

A payment intent can be tried several times. Each try is an attempt, also called a charge (ch_…): a card payment page opened, or a cash code issued. A declined card or an expired code ends the attempt, not the payment intent: your customer can try again, with the same method or another.

  • The intent's latest_charge names its most recent attempt.
  • A payment intent succeeds once. Even if a confirmation reaches us several times, there is one success, one payment_intent.succeeded event and one entry in your balance.
  • amount_received is set when the payment succeeds; amount_refunded grows with each refund. Both are in the payment intent's currency.

The lifecycle

The statuses of a payment intent
  • requires_payment_method → requires_action: card page or cash code
  • requires_action → processing: customer paid
  • processing → succeeded: confirmed, amount matches
  • requires_action → requires_payment_method: declined, failed or expired
  • processing → requires_payment_method
  • requires_payment_method → canceled: canceled or expired
  • requires_action → canceled: you cancel

A card payment confirmed at once can also go straight from requires_action to succeeded.

Each status, and what to do

StatusWhat it meansWhat you do
requires_payment_methodNothing is being paid: the payment was just created, or the last attempt failed.Send your customer to pay, or let them try again. last_payment_error says why the last attempt failed.
requires_actionYour customer has to act: finish on the card payment page, or pay the cash code at an agent.Wait. With your own page, show next_action (see below).
processingYour customer has paid; the confirmation is on its way.Wait for the webhook. Do not deliver yet.
succeededThe payment is confirmed and the amount matches.Deliver the order. This is final.
canceledYou canceled the payment, or its checkout session expired unpaid.Usually nothing: no money moves. A customer who was already paying can still pay: see below. Create a new payment if your customer comes back.

A canceled payment can still succeed

A payment you canceled can still succeed if your customer was already paying: they may still be on the card payment page when you cancel, and finish there. The same goes for an attempt that had expired. When the payment network confirms such a payment for the amount asked, no other attempt of the payment has succeeded, and the payment link it came from, if any, still has room, the payment intent becomes succeeded and is credited to you like any payment paid in time: amount_received is set, and canceled_at and cancellation_reason are cleared. You receive payment_intent.synced, then charge.succeeded and payment_intent.succeeded.

Listen for payment_intent.succeeded and payment_intent.synced, and refund the payment if you no longer want it. To ask for a payment's latest state yourself, see Sync a payment.

When something does not add up

If a payment is confirmed for another amount than the one asked, nothing is credited automatically. The payment intent stays in processing and gains a review object, with reason set to amount_mismatch, and you receive review.opened. Money that arrives on an attempt that had failed, or a second payment when your customer pays twice, is not credited either: its review has reason set to paid_after_end. Nor is a late payment for a payment link that is full by then: it opens a review too. A person on our side looks at each. In the sandbox, the cash scenarios let you trigger an amount_mismatch review.

Attempts

An attempt's status is pending, succeeded, failed, canceled or expired. A failed attempt carries failure_code and failure_message, and the intent copies them into last_payment_error:

CodeMethodWhat happened
card_declinedCardThe bank declined. decline_code may say more, such as insufficient_funds.
expired_cardCardThe card has expired.
authentication_failedCard3-D Secure did not succeed.
processing_errorCard, cashThe payment could not be processed. Your customer can try again.
voucher_expiredCashThe code was not paid before its deadline.
voucher_refusedCashThe payment network refused the code.

An attempt has a limited life: about 30 minutes for a card payment page, and the deadline of the code for cash (about three days). An attempt that runs out ends expired.

Next actions

While a payment intent is in requires_action, its next_action says what your customer must do. With hosted checkout or a payment link you never read it: our pages do the work. With your own page:

  • form_post or redirect_to_url, for a card: follow whichever is returned. form_post is an address and fields that your customer's browser posts to reach the card payment page; redirect_to_url is an address your customer's browser opens, with nothing to post. See Card payments.
  • display_voucher, for cash: the code, the amount_to_pay (your amount plus a small stamp fee your customer pays), expires_at, a printable slip_url, and hosted_voucher_url, our voucher page.

Amounts and currency

  • Every amount is an integer in the currency's smallest unit, centimes for dirhams: 25000 is 250.00 MAD. Never send decimals.
  • You create a payment in mad, in lowercase, and card and cash payments are charged in it.
  • price is what the payment intent was created with: an amount and a currency. Changing amount while the payment is unpaid changes its price too.
  • A payment charged in another currency than its price reads, in amount and currency, what it is charged in, and so do amount_received and amount_refunded. When it was converted at our rate, its converted_from holds the price it was converted from and the rate used, in ten-thousandths of the price's currency for one unit of the other (108523 is 10.8523 MAD for one). Otherwise converted_from is null. A charge carries the same converted_from.
  • A payment can also carry a price set per currency: your own price in another currency, in currency_options, by currency code, each { "amount": … } in that currency's smallest unit. Paid in one of those currencies, the payment is charged exactly that price: nothing is converted, and converted_from is null.
  • conversion decides for a currency the payment has no price of its own in: allowed, the default, converts the price at our rate; none charges your own prices only, and such a currency is not offered. Payment intents and checkout sessions show both; currency_options is null without any.
  • A price set per currency is only for a currency one of the listed payment methods charges in, never the payment's own, and it is held to that currency's limits when the payment is created or changed. Each refusal names its field in param: parameter_invalid on currency_options.<currency>, amount_too_small or amount_too_large on currency_options.<currency>.amount. With conversion: "none", a listed method without a price in a currency it charges in is refused with parameter_invalid on payment_method_types.
  • While the payment is unpaid, POST /v1/payment_intents/{id} takes currency_options, which replaces them (null removes them), and conversion. A payment made by a checkout session takes neither: its session's prices hold.
  • A cash payment is at least 100.00 MAD (10000); a card payment at least 1.00 MAD (100). A smaller amount is refused with amount_too_small, in test mode as in live mode.

Redirects and webhooks: which one to trust

Your customer comes back to your success_url after paying, but that return proves nothing: they can close the tab first, a cash payment is made days later at an agent, and anyone can type the address.

Deliver on one of these two signals only:

  1. the webhook payment_intent.succeeded, with a verified signature;
  2. the payment intent read from the API, with your secret key, showing status: "succeeded".

Use the return to thank your customer and show "We are confirming your payment"; then let the webhook do the rest.

Refunds

A succeeded card payment can be refunded, in full or in part, as long as the total refunded stays within the amount received. A refund is pending, then succeeded, failed or canceled. A cash payment cannot be refunded through AdProMaxPay: the money was handed over in cash, and there is no card to return it to. Settle it with your customer directly. See Refunds.

Events you receive

EventWhen
payment_intent.requires_actionA card page was opened or a cash code issued.
payment_intent.processingYour customer paid; the confirmation is on its way.
payment_intent.succeededThe payment is confirmed. Deliver.
payment_intent.payment_failedAn attempt failed: declined, expired or refused.
payment_intent.canceledThe payment was canceled.
payment_intent.syncedA sync, or a confirmation that reached us late, changed the payment. See Sync a payment.
charge.succeeded, charge.failedAn attempt succeeded or failed.
review.openedSomething does not add up; nothing was credited.

The full list is in Webhooks.