Skip to navigation

Collect Invoice

View as Markdown

Collect payment on an invoice.

Called by the Restate workflow handler for:

  • Initial payment (checkout)
  • Subscription renewal
  • Dunning retries

Handles invoices in DRAFT, OPEN, or PAST_DUE state. DRAFT invoices are finalized before processor attempt.

Requirements:

  • Invoice must be in DRAFT, OPEN, or PAST_DUE state
  • Invoice must have a payment method (for payment to be attempted)

Headers:

  • Idempotency-Key: Optional key to prevent duplicate payment attempts

Forcing a hard-declined card (ignore_hard_decline: true):

  • Charges the card named by payment_method_id even when it is on this invoice’s hard-decline list. The charge is restricted to that card: there is no fallback to the customer’s other cards, and a decline (hard or soft) answers 402. The card can still be tried on more than one of your processors.
  • Manual collection only (API key or dashboard). An automated caller gets 400. payment_method_id is required, else 400.
  • You take the risk of retrying a card the issuer declined. The flag does not add or remove entries on the hard-decline list; a new hard decline is still recorded.
  • It does not override: a card-level decline (lost, stolen, fraud, do not retry) on this invoice’s payment, for a card on its hard-decline list, on the card or on another saved copy of it, also for a customer with one saved card, unless the card network’s Account Updater has since given the card a new card number; the card network limit of 15 attempts per card in 30 days; an Account Updater refresh in flight; merchant-initiated charge support; the dunning attempt limit; an RBI e-mandate hold; a stopped subscription; or an invoice that cannot be collected.
  • On Airwallex, card-level decline codes are not visible yet, so an Airwallex card-level decline is not detected and the card is charged.
  • Use a new Idempotency-Key when you add the flag, and when you retry after a 422. A key replays its first response, whatever its status, and does not look at the request body.

Returns (422 Unprocessable - Forced Card Cannot Be Tried, ignore_hard_decline):

  • Nothing is charged and the invoice is not changed. detail is one of:
    • “The card issuer declined the chosen card as lost, stolen, fraud, or do not retry. ignore_hard_decline does not override this decline.”
    • “The chosen card has reached the card network limit of 15 attempts in 30 days.”
    • “The card network is updating the chosen card (Account Updater). Try again when the update is complete.”
    • “The chosen payment method does not support merchant-initiated charges.”
    • “The chosen card is expired and the customer has a newer copy of the same card. Collect again with payment_method_id set to the newer copy:” followed by that copy’s ID.
    • “The chosen payment method is not active, so it cannot be charged.”

Returns (200 OK - Payment Succeeded):

  • invoice_id: ID of the invoice
  • invoice_status: “paid” (invoice fully paid)
  • subscription_id: ID of linked subscription (if any)
  • payment_status: “paid” or “processing” (ACH/bank transfer pending)
  • payment_error: null
  • error_message: null (deprecated, use payment_error)
  • orchestrator_summary: null

Returns (402 Payment Required - Payment Failed):

  • invoice_id: ID of the invoice

  • invoice_status: “past_due” or “open” (invoice not paid)

  • subscription_id: ID of linked subscription (if any)

  • payment_status: “failed”, “requires_action”, “no_payment_method”, “skipped”, “on_session_checkout_invoice”, “hard_cap_exceeded”, or “subscription_cancelled”

    The last three answer 402 because nothing was collected:

    • on_session_checkout_invoice: the invoice was created by a hosted checkout (CIT). Automated retries are never attempted on it; a deliberate call to this endpoint IS attempted, so seeing this status here means the caller was an internal automated path.
    • hard_cap_exceeded / subscription_cancelled: previously answered 200 with a populated payment_error, which contradicted the guidance below. They are failures — no money moved — and now answer 402.
  • payment_error: Detailed processor decline reason (e.g., “Insufficient funds”, “Card declined”)

  • error_message: Same as payment_error (deprecated, kept for backward compatibility)

  • orchestrator_summary: High-level summary (e.g., “All payment methods exhausted”)

  • is_dunning: Whether this was a dunning retry attempt

  • dunning_attempt: Dunning attempt number (0 = first attempt)

Returns (200 OK - Collection Deferred, payment_status “au_deferred”):

  • The card is mid-refresh at the card network’s Account Updater, so no charge was attempted, no decline was recorded, and no retry was consumed. Retry shortly. This is NOT a payment — see the warning below.

Returns (200 OK - Collection Suppressed, payment_status “duplicate_suppressed”):

  • An automated caller arrived inside the previous attempt’s processor duplicate-submission window, so no charge was submitted, no decline was recorded and no retry was consumed. This is the fingerprint of an at-least-once re-invocation of a collect that already ran; the original run owns the next attempt, so the caller should stop rather than retry. Like “au_deferred”, this is NOT a payment — see the warning below.

Returns (200 OK - Collection Contended, payment_status “invoice_locked”):

  • Another operation held the invoice while the collection tried to claim it, so no charge was submitted, no decline was recorded and no retry was consumed (GH #4139). The invoice is left OPEN and collectible.
  • Retry with a NEW Idempotency-Key. Retrying with the SAME key replays this cached response for the key’s lifetime and never reaches the collection at all, so the invoice would silently stay uncollected. That is true of every response this endpoint caches; it matters here because this is the one outcome whose whole instruction is “try again”.
  • 200 rather than 402 deliberately. 402 means “payment required/failed”, so a caller that treats it as a decline is reading it correctly - the statement is simply false when no charge was attempted, and no care on the caller’s side can fix that. Callers were cancelling subscriptions and voiding invoices off the back of it, for customers whose cards were never contacted, even though the body already carried a distinguishable message - integrations branch on the status, not on the text. Like “au_deferred” and “duplicate_suppressed”, this is NOT a payment. The warning below is the part a caller CAN act on.

Returns (200 OK - Authorization Held, payment_status “authorization_held”):

  • The processor holds funds but has not captured them. The invoice stays OPEN. Do not retry or grant value. Like “au_deferred”, this is NOT a payment.

Returns (200 OK - Credit Quote Unfunded, payment_status “credit_quote_unfunded”):

  • The invoice’s customer-credit quote is no longer covered by the customer’s balance (they spent it on another invoice, or a live checkout of theirs is charging right now), so no charge was submitted, no decline was recorded and no retry was consumed. The invoice is left OPEN and unchanged.
  • Worth retrying, on a delay. Both causes clear on their own: a sibling checkout’s charger call ends within minutes, and the balance is re-funded by any refund or fresh credit grant. An automated collect hands its dunning slot back and is re-armed on the normal schedule; a manual caller can simply collect again later. To settle it immediately instead, void and re-issue the invoice — the new one quotes whatever credit remains.

Returns (200 OK - Invalid Attempt Count, payment_status “invalid_attempt_count”):

  • The invoice’s stored dunning attempt count is invalid, so first attempt or retry cannot be decided. No charge was submitted and the invoice is left unchanged. Do not retry. Contact PaymentKit support to repair the invoice.

CRITICAL for one-time product purchases: Only grant product access/credits when payment_status is “paid” or “processing”. HTTP 200 alone is not enough: “au_deferred”, “too_early”, “stale_trigger”, “duplicate_suppressed”, “invoice_locked”, “credit_quote_unfunded”, “authorization_held” and “invalid_attempt_count” all return 200 and all mean no money moved. Never grant access on HTTP 402 (payment failed).

Authentication

AuthorizationBearer

Bearer authentication of the form Bearer <token>, where token is your auth token.

Path parameters

external_idstringRequired
account_idstringRequired

Headers

X-Restate-Secret-Keystring or nullOptional
X-System-Reasonstring or nullOptional
Idempotency-Keystring or nullOptional>=8 characters
A unique key for this request. A retry with the same key returns the first response instead of running again, for 24 hours. Keys are per caller.

Request

This endpoint expects a nullable object.
payment_method_idstring or nullOptional
ID of the payment method to use for payment
ignore_hard_declinebooleanOptionalDefaults to false

Charge the card named by payment_method_id even if it is on this invoice’s hard-decline list. The charge is restricted to that card: there is no fallback to the customer’s other cards, and a decline answers HTTP 402. You take the risk of retrying a card the issuer declined. MANUAL collection only: an automated caller gets HTTP 400, and payment_method_id is required (HTTP 400 otherwise). A card-level decline (lost, stolen, fraud, do not retry) on this invoice’s payment, for a card on its hard-decline list, on the card or another saved copy of it, also for a customer with one saved card, are not overridden unless the card network’s Account Updater has since given the card a new card number. On Airwallex, card-level decline codes are not visible yet, so such a decline is not detected. The card network retry limit, an Account Updater refresh in flight, MIT support, the dunning attempt limit, an RBI e-mandate hold, a stopped subscription and collectibility still apply. When the card cannot be tried, the collect answers HTTP 422 before any charge, with one of these messages: “The card issuer declined the chosen card as lost, stolen, fraud, or do not retry. ignore_hard_decline does not override this decline.” “The chosen card has reached the card network limit of 15 attempts in 30 days.” “The card network is updating the chosen card (Account Updater). Try again when the update is complete.” “The chosen payment method does not support merchant-initiated charges.” “The chosen card is expired and the customer has a newer copy of the same card. Collect again with payment_method_id set to the newer copy:” (followed by the copy’s ID) “The chosen payment method is not active, so it cannot be charged.” Use a new Idempotency-Key when you add this flag or retry after a 422: a key replays its first response, whatever its status, and does not look at the request body.

Response

Successful Response

Errors

422
Unprocessable Entity Error