The verification page¶
When a customer finishes paying at the PSP, they are redirected back to a verification page that waits for the payment to land and then sends them on — to the thank-you page, or back into the payment flow if it failed. PaymentStatusController::get_status_data() is what that page asks, and it answers the same way for the server-rendered page, for its polling endpoint (wc-api/payments-hub/verify) and for the headless verifyPayment GraphQL query.
What the redirect carries¶
The accept and cancel URLs we send to Frisbii point at this page, and Frisbii appends its own parameters when it sends the customer back:
/checkout/verify-payment/660/?key=TcCTqjZbXALIX
&id=cs_475c79cfd1522e1362f9e6b55d5e8eb9
&invoice=dev-pt1-660
&customer=dev-pt1-64
&payment_method=ca_59123115b15e4087b15de0400ff2ae32
PaymentReturnContext::fromArray() reads them into a value object. Every value is user controlled and ends up in both a database lookup and a path segment of an outgoing API call, so anything that is not a plain handle is dropped — dropped, not cleaned up, so nothing the customer did not send can end up being looked up.
Pass it as the second argument:
Omitting it keeps the answer to local state, which is what a caller with no request behind it should do.
Why it matters: the retry problem¶
A customer whose payment failed and who then pays again goes through a checkout session, not a new charge. AgreementService::createAgreement() stores that session as a pending agreement and creates a payment row only once Frisbii has an invoice for it, because FrisbiiGateway::createAgreement() has no payment id to give it yet.
So between the second payment and the webhook that reports it, the newest payment row for the order is still the failed one. Reporting it tells a customer who has just paid that their payment failed, and offers them a button to pay a third time.
Two things prevent that:
- A pending agreement newer than the failed payment means an attempt is running. The answer is then
PENDINGwith no redirect, andattempt_in_flightistrue. OnlyFAILEDandCANCELEDare overridden this way — every other status already describes an attempt worth reporting. - The invoice is read back from the gateway rather than waited for. See below.
status is corrected rather than only flagged, because both clients treat a failed status as final before they look at the redirect. attempt_in_flight is extra signal for a client that wants it, not the thing that makes this work.
Reading the attempt back¶
Frisbii's webhooks are queued through Action Scheduler, so there is always a window where the customer is watching the page and local state is behind. ReturnContextSyncInterface closes it. FrisbiiWebhookHandler implements it, and the contract is registered only when Frisbii is configured — on a site without it, the page falls back to stored state.
syncFromReturnContext():
- Checks the handles belong to this order.
orderIdFromHandle()must resolve the invoice handle to this order id, and a customer handle, if given, must be one this order would be charged under — including theguest-<orderId>shape an order without an account uses. - Returns what is already stored if it records an outcome, without calling Frisbii.
- Takes a 10-second lock on the invoice handle and checks an hourly ceiling of 30 calls. The page polls every few seconds and can be left open; without both, it would be an unbounded stream of requests, and two concurrent polls could each create a row for the same attempt. The lock is
wp_cache_add()oradd_option()—get_transient()+set_transient()is two statements with a window between them, which is not a lock. - Reads
GET /v1/invoice/{handle}and attributes the result through the sameresolvePaymentForAttempt()the webhook path uses, naming the transaction. One handle can hold several attempts, and the transaction is the only thing that tells them apart. - Moves the payment with
PaymentStateService, driven by the invoice's current state rather than by an event type. A settled invoice found on a pending payment is authorized first, becausepaymentCaptured()only moves on fromAUTHORIZEDorCAPTURING.
Because both paths go through PaymentStateService, whichever arrives second is a no-op: its guards refuse a transition that has already happened, and PaymentEventHandler only touches orders that are still pending, failed or on-hold.
Nothing here throws. A gateway that is slow, unreachable, or has no invoice yet answers with whatever is stored, and the customer keeps waiting rather than seeing an error.
What comes back¶
| Key | Meaning |
|---|---|
transactionType | payment for an order, agreement for a subscription |
status | PaymentStatus/AgreementStatus value, or null when there is no transaction at all |
payment_link | Where to send the customer to pay, when there is somewhere |
redirect_url | Where the page should go next, or null while the outcome is unknown |
attempt_in_flight | true when a newer attempt is running than the status was read from |