Handle synchronous and asynchronous results

Read a transaction's result from the response, and handle the results that arrive later.

Most transactions return their result in the response to POST /v1/transactions. Some return Pending instead, and the result arrives later, after the connection finishes processing. Use this guide to read the result in the response, wait for a Pending transaction, and retry a request that gets no answer.

The following diagram shows both paths:

sequenceDiagram
    participant P as Your platform
    participant Z as Preczn
    participant C as Connection
    P->>Z: POST /v1/transactions
    Z->>C: Transaction
    alt Synchronous result
        C-->>Z: Approved, declined, or error
        Z-->>P: Response with A, D, or E
        Z-->>P: Transaction webhook for the result
    else Asynchronous result
        C-->>Z: Accepted, not final
        Z-->>P: Response with P
        Z-->>P: transaction.pending webhook
        Note over C: Finishes processing
        C-->>Z: Final result
        Z-->>P: Transaction webhook for the new status
    end

Before you start, subscribe an endpoint to the transaction events. See Subscribe to webhooks.


Transaction status

Check authorization.status in the response. Branch your code on this value, not on processorCode or processorMessage, which differ by connection.

StatusMeaningResult in the response
AApprovedYes
DDeclinedYes
EErrorYes
PPendingNo, it arrives later

For D, read processorCode and processorMessage for the reason. For E, read errors. A follow-on transaction, such as a capture, void, or refund, can't act on a declined or errored transaction.

On some connections, a result can still change after the response. For example, a bank can return an approved bank account payment, and the transaction changes from A to D. Preczn sends a transaction webhook when that happens.


Pending transactions

A transaction returns P when the connection accepts it but hasn't finished processing it. Results that usually arrive later include the following:

  • Bank account payments, which the ACH network processes over several days.
  • Follow-on transactions, such as captures and refunds, on connections that confirm them later.
  • Card payments that the connection holds, such as for a 3D Secure challenge or a fraud review.

Which transactions return Pending, and for how long, depends on the connection. See the Processing transactions section of the connection's guide, linked from Supported connections.

The following example shows a Pending response:

{
    "id": "{transactionId}",
    "type": "sale",
    "amount": 5000,
    "merchantId": "{merchantId}",
    "authorization": {
        "status": "P",
        "processorCode": "{processorCode}",
        "processorMessage": "{processorMessage}"
    }
}

This response is abbreviated. For every field, see Process Transaction.

While a transaction is Pending, follow these rules:

  • Treat P as no result yet. Don't fulfill the order, and don't treat it as a failure.
  • Don't send a new sale or auth for the same order. If the Pending transaction is approved, the customer can pay twice.
  • Store the transaction id, and wait for the result.

The result reaches you in two ways:

  • Transaction webhook. When the connection reports the result, Preczn updates the transaction and sends the event that matches the new status: transaction.approved, transaction.declined, or transaction.errored. See Webhook events and Transaction webhook payloads.
  • Get Transaction. Send GET /v1/transactions/{transactionId} to read the transaction's current status at any time, such as when you reconcile or when a webhook didn't arrive.

Transaction events can arrive more than once and out of order, so apply the transaction's own fields instead of the order of arrival. See Duplicate notifications.

On some connections, a transaction can stay Pending in Preczn, for example when the merchant decides a held transaction in the connection's own portal. The connection's guide says when this happens.


Retries after a timeout or error

When a request times out before you get a response, or returns 500, you don't know whether Preczn processed the transaction. Retry the request with the same body and the same Idempotency-Key header that you sent the first time. See Idempotency keys.

What the retry returns depends on what happened to the first request:

First requestThe retry returns
Finished with A, D, or PThe first request's response, unchanged
Still processing409. Retry again with the same key
Finished with E, or failedA new transaction, processed as a new request
Used the key with another type or amount400 "Idempotency Error"

A replayed response shows the status from the time of the first request. If it shows P, the transaction may have changed since. Read its current status with GET /v1/transactions/{transactionId}.

⚠️

Send the key on the first request

A retry without the first request's Idempotency-Key is a new transaction, and it can charge the customer twice.


Did this page help you?