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:

FieldMeaning
amount, currencyThe amount and currency of the payment
originAmountThe original amount, when it was converted
paymentMethod, paymentMethodTypeThe method key and the method type
termsAcceptedWhether the terms were accepted
hasPromotionCodeWhether a promotion code is sent (never the code)
payloadEverything else, sealed. It cannot be read, printed or reflected; the only thing it can do is submitToPraxis()

What the handler returns

ReturnWhat the cashier does
The outcome of payload.submitToPraxis()Goes on as with the default handler: processing, provider page, result
.notSubmittedNothing 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 .notSubmitted and 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.
🚧

Important

A handler cannot charge through your own payment provider. It never gets the card number, the CVV, the card token, the customer's contact data or any field value.


Did this page help you?