Payment handler
Overview
By default, CashierPaymentHandler.praxis sends the payment to Praxis and the SDK does everything. To step in, for example for your own risk check, pass a .custom handler:
let configuration = CashierConfiguration(paymentHandler: .custom { request in
guard await myRiskCheck(amount: request.amount, currency: request.currency) else {
return .notSubmitted
}
return await request.payload.submitToPraxis()
})What the handler gets
The handler runs once per tap on the final button, after every check passed and after the card is protected. It gets a CashierPaymentRequest:
| Property | Description | Format |
|---|---|---|
| amount, currency | The amount (major units; crypto in the minor units the payment sends) and currency of the payment. | Decimal, String |
| originAmount | The amount the customer entered in the base currency, for a cross-currency payment; nil otherwise. | Decimal? |
| paymentMethod | The method key. | String |
| paymentMethodType | "cc" for a card method; nil for other methods. | String? |
| termsAccepted | Whether the terms were accepted. | Bool |
| hasPromotionCode | Whether a promotion code is sent. Never the code itself. | Bool |
| payload | Everything else, sealed. | CashierPaymentPayload |
The payload cannot be read, printed or inspected. The only thing it can do is submitToPraxis(), which sends it to Praxis exactly as the default handler does.
What the handler returns
| Return | What the Cashier does |
|---|---|
| The outcome of request.payload.submitToPraxis() | Continues as with the default handler: processing, provider page, result. |
| .notSubmitted | Nothing was sent. The button stops being busy and the customer stays on the page. |
| .finished(_:transactionID:) | Your code finished the payment another way. The Cashier shows the result for that status (title and icon only). The transaction ID reaches CashierResult.transactionID. |
Payments finished outside PraxisWhen your handler returns
.finished, Praxis did not process the payment, so no Payment Notification follows for it. Confirm and reconcile such payments in the system that finished them, before you credit the customer. Every payment sent withsubmitToPraxis()is confirmed by the Payment Notification as usual.
Rules
- Once.
submitToPraxis()sends at most once. A second call returns.notSubmittedand sends nothing. - Timeout. The handler has 130 seconds. After that the Cashier treats the payment as sent with its answer lost: it shows the processing screen and reads the payment result. A later
submitToPraxis()sends nothing. - Close.
CashierSession.close()cancels the handler and closes the payload. - Main actor. The handler runs on the main actor.
A handler cannot charge through your own payment provider. It never gets the card number, CVV, card token, customer contact data or any field value.
Updated 8 days ago