8. Payment handler
By default the SDK sends the payment to Praxis and does everything (CashierPaymentHandler.praxis). Pass a custom handler to run your own code when the customer pays: before the Praxis submit, or instead of it.
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:
| Field | Meaning |
|---|---|
| amount, currency | The amount and currency of the payment |
| originAmount | The original amount, when it was converted |
| paymentMethod, paymentMethodType | The method key and the method type |
| termsAccepted | Whether the terms were accepted |
| hasPromotionCode | Whether a promotion code is sent (never the code) |
| payload | Everything else, sealed. It cannot be read, printed or reflected; the only thing it can do is submitToPraxis() |
What the handler returns
| Return | What the cashier does |
|---|---|
| The outcome of payload.submitToPraxis() | Goes on 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(status, transactionID:) | Your code finished the payment another way. The cashier shows the result for that status (title and icon only). The transaction ID reaches the result and is never drawn |
Lifecycle and limits
- Once:
submitToPraxis()sends at most once. A second call returns.notSubmittedand sends nothing. - Timeout: the handler has 130 seconds, the time the cashier waits for a Praxis payment answer. After that the cashier treats the payment as sent with its answer lost: it shows the processing screen and reads the payment's result. A later
submitToPraxis()sends nothing. - Close:
close()on the session cancels the handler and closes the payload. - The handler runs on the main actor.
Updated about 8 hours ago
Did this page help you?