Payments
How payments work
Payment intents, attempts, the statuses a payment goes through, and which signal to trust before you deliver.
On this page
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_chargenames its most recent attempt. - A payment intent succeeds once. Even if a confirmation reaches us several times, there is one
success, one
payment_intent.succeededevent and one entry in your balance. amount_receivedis set when the payment succeeds;amount_refundedgrows with each refund. Both are in the payment intent'scurrency.
The lifecycle
- 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
| Status | What it means | What you do |
|---|---|---|
requires_payment_method | Nothing 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_action | Your 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). |
processing | Your customer has paid; the confirmation is on its way. | Wait for the webhook. Do not deliver yet. |
succeeded | The payment is confirmed and the amount matches. | Deliver the order. This is final. |
canceled | You 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:
| Code | Method | What happened |
|---|---|---|
card_declined | Card | The bank declined. decline_code may say more, such as insufficient_funds. |
expired_card | Card | The card has expired. |
authentication_failed | Card | 3-D Secure did not succeed. |
processing_error | Card, cash | The payment could not be processed. Your customer can try again. |
voucher_expired | Cash | The code was not paid before its deadline. |
voucher_refused | Cash | The 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_postorredirect_to_url, for a card: follow whichever is returned.form_postis an address and fields that your customer's browser posts to reach the card payment page;redirect_to_urlis an address your customer's browser opens, with nothing to post. See Card payments.display_voucher, for cash: thecode, theamount_to_pay(your amount plus a small stamp fee your customer pays),expires_at, a printableslip_url, andhosted_voucher_url, our voucher page.
Amounts and currency
- Every amount is an integer in the currency's smallest unit, centimes for dirhams:
25000is 250.00 MAD. Never send decimals. - You create a payment in
mad, in lowercase, and card and cash payments are charged in it. priceis what the payment intent was created with: anamountand acurrency. Changingamountwhile the payment is unpaid changes itspricetoo.- A payment charged in another currency than its price reads, in
amountandcurrency, what it is charged in, and so doamount_receivedandamount_refunded. When it was converted at our rate, itsconverted_fromholds the price it was converted from and therateused, in ten-thousandths of the price's currency for one unit of the other (108523is 10.8523 MAD for one). Otherwiseconverted_fromisnull. A charge carries the sameconverted_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, andconverted_fromisnull. conversiondecides for a currency the payment has no price of its own in:allowed, the default, converts the price at our rate;nonecharges your own prices only, and such a currency is not offered. Payment intents and checkout sessions show both;currency_optionsisnullwithout 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_invalidoncurrency_options.<currency>,amount_too_smalloramount_too_largeoncurrency_options.<currency>.amount. Withconversion: "none", a listed method without a price in a currency it charges in is refused withparameter_invalidonpayment_method_types. - While the payment is unpaid,
POST /v1/payment_intents/{id}takescurrency_options, which replaces them (nullremoves them), andconversion. 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 withamount_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:
- the webhook
payment_intent.succeeded, with a verified signature; - 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
| Event | When |
|---|---|
payment_intent.requires_action | A card page was opened or a cash code issued. |
payment_intent.processing | Your customer paid; the confirmation is on its way. |
payment_intent.succeeded | The payment is confirmed. Deliver. |
payment_intent.payment_failed | An attempt failed: declined, expired or refused. |
payment_intent.canceled | The payment was canceled. |
payment_intent.synced | A sync, or a confirmation that reached us late, changed the payment. See Sync a payment. |
charge.succeeded, charge.failed | An attempt succeeded or failed. |
review.opened | Something does not add up; nothing was credited. |
The full list is in Webhooks.