Pay with Apple Pay

Svea App Wallet now supports processing payments with Apple Pay!

Apple Pay flow
info

Apple Pay will be available from version 2.1.0.

Setting up the app for Apple Pay

The client app can decide the logic to present the Apple Pay dialog to the user and to fill in the details for the dialog.
We do recommend going through Apple's documentation on setting up Apple Pay.
On top of setting up the app according to Apple's guidelines, please reach out to the Svea contact person to configure the Svea server to onboard for Apple Pay.

To sum up the above points with the flow chart, we recommend the following steps:

  1. Setup the app for Apple Pay.
  2. Create an ApplePay Payment by talking to the backend and receiving a payment token.
  3. Show the ApplePay dialog, get user authorization and pass in the PKPayment and token to Svea App Wallet.
info

We highly recommend showing the Apple Pay dialog at the latest possible point in the workflow, because iOS automatically dismisses the Apple Pay dialog after a short time-out with a failure message, even if the transaction actually could succeed after the timeout.

Paying with Apple Pay

As mentioned in the above flow chart, fetch the payment token from your backend and PKPayment from PassKit, and pass them to the Svea App Wallet method.

info

In the stage environment, the passed in PKPayment will not be used.
No real card data will be stored. This also means that the Apple Pay workflow will work fine on a simulator in stage environment.

ParameterDescription
paymentTokenA valid payment token from your backend.
pkPaymentThe PKPayment object sent to the client app from PassKit via PKPaymentAuthorizationControllerDelegate
receiveOnThe dispatch queue used when invoking the result callback handler. Defaults to main.
dismissPKPaymentAuthorizationViewControllerA completion handler to dismiss the PKPaymentAuthorizationViewController when the transaction takes longer than expected. Once we have a result, the onResult function will be called nonetheless.
onResultResult callback handler.
Please note
SveaWalletClient is deprecated in version 3.1.0. Use new class SveaAppWallet instead.
SveaAppWalletSveaWalletClient (deprecated)
Copy
Copied
SveaAppWallet.shared.payWithApplePay(paymentToken: token,
                                  pkPayment: pkPayment) { [weak self] in
    self?.pKPaymentAuthorizationViewController?.dismiss(animated: true)
} onResult: { result in
    switch result {
    case .success: print("Payment completed!")
    case let .failure(error): print("Could not complete payment, got error: \(error)")
    }
}
Copy
Copied
SveaWalletClient.shared.payWithApplePay(paymentToken: token,
                                        pkPayment: pkPayment) { [weak self] in
    self?.pKPaymentAuthorizationViewController?.dismiss(animated: true)
} onResult: { result in
    switch result {
    case .onSuccess: print("Payment completed!")
    case let .onFailure(error): print("Could not complete payment, got error: \(error)")
    }
}
info

Not passing a valid dismissPKPaymentAuthorizationViewController completionHandler would mean that the Apple Pay dialog will get dismissed with a false positive error for transactions that take a long time to complete, i.e, the transaction might actually succeed and the result would be a success, but iOS may automatically dismiss the dialog with an error message.

onSuccess

Returned when the payment was successful.

info

Please note that information about the purchase, such as the amount paid, is fetched from your backend.

onFailure

Returned when an error occurs. If this happens, the payment has failed.

Possible errors

Copy
Copied
case noPaymentTokenProvided          // A payment token has not been provided.
case failedToConfirmPayment          // The payment could not be confirmed.
case failedToConfirmPaymentStatus    // The status of the payment is unknown.
case failedToFetchPKPaymentTestToken // In stage environment, could not receive a mock PKPayment form the server to use instead of the real one.
case invalidPkPaymentProvided        // The PKPayment doesn't have any payload data
case failedToPay                     // The payment was not successful.
case unknownError                    // An unknown error occurred.