Overview

Set the PrimerHeadlessUniversalCheckoutDelegate in order to receive callbacks from Primer SDK.

Callbacks can be used for managing the customer journey and trigger actions after specific events throughout the payment journey. See below for a breakdown of all callbacks supported within the Primer SDK.

primerHeadlessUniversalCheckoutDidCompleteCheckoutWithData

This method will be called with the when the payment has been completed, returning the payment's data.

⚠️ This method won't be called when you are using manual payment handling, or the vault manager.

1
func primerHeadlessUniversalCheckoutDidCompleteCheckoutWithData(_ data: PrimerCheckoutData)
swift
copy

Parameters

Properties
additionalInfo
PrimerCheckoutAdditionalInfo
direct subclasses
parameters
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
parameters
expiresAt
StringRequired
qrCodeUrl
String
qrCodeBase64
StringRequired
Subclasses
Properties
collectorViewController
UIViewController
Provides the bank account collector for ACH bank account selection.
ACHMandateAdditionalInfo
ACHAdditionalInfo

Provides an empty ACHMandateAdditionalInfo object to prompt the merchant to display the mandate information.

Example

12345678910111213
// 👇 Add thisimport PrimerSDK
// 👇 Conform to PrimerDelegateclass MyViewController: UIViewController, PrimerDelegate {
    // ...
    // 👇 Add this    func primerDidCompleteCheckoutWithData(_ data: PrimerCheckoutData) {        // Do something with the payment's data    }}
swift
copy

primerHeadlessUniversalCheckoutDidLoadAvailablePaymentMethods

This method will return the payment methods that should be displayed based on the current client session data.

1
func primerHeadlessUniversalCheckoutDidLoadAvailablePaymentMethods(_ paymentMethods: [PrimerHeadlessUniversalCheckout.PaymentMethod])
swift
copy

Parameters

Properties
paymentMethodType
StringRequired
supportedPrimerSessionIntents
[PrimerSessionIntent]Required
enum cases

Use checkout when you want go through the checkout flow

Use vault when you want to vault a payment method, so you can use the token to pay another time.

requiredInputDataClass
PrimerRawData.TypeOptional

primerHeadlessUniversalCheckoutDidTokenizePaymentMethod

This method will be called with the when the payment method has been is tokenized, returning the payment method's tokenization data. Use the token to create a payment on your backend. Make sure that you call the decisionHandler once your operation has been completed.

⚠️ This method will be called when you are using manual payment handling, or the vault manager.

1234
func primerHeadlessUniversalCheckoutDidTokenizePaymentMethod(    _ paymentMethodTokenData: PrimerPaymentMethodTokenData,    decisionHandler: @escaping (PrimerHeadlessUniversalCheckoutResumeDecision) -> Void)
swift
copy

Parameters

Properties
paymentMethodTokenData
PrimerPaymentMethodTokenData
parameters
id
String
paymentInstrumentData
PaymentInstrumentData
parameters
sessionInfo
SessionInfo
network
String
binData
BinData
threeDSecureAuthentication
ThreeDS.AuthenticationDetails
externalPayerInfo
ExternalPayerInfo
Additional Paypal data.
Properties
email
String
The payer's email address.
The payer's unique ID.
firstName
String?
The payer's given name.
lastName
String?
The payer's given surname.
shippingAddress
ShippingAddress
sessionData
SessionData
threeDSecureAuthentication
ThreeDS.AuthenticationDetails
token
StringRequired
vaultData
VaultData
decisionHandler
enum PrimerResumeDecisionRequired
cases

Call .succeed when you want to show the success screen, or finalize the flow successfully in case you have hidden the success screen.

Call .continueWithNewClientToken when the payment has entered in a PENDING state and a required action client token has been provided.

Example

12345678910111213141516171819202122232425262728293031
// 👇 Add thisimport PrimerSDK
// 👇 Conform to PrimerHeadlessUniversalCheckoutDelegateclass MyViewController: UIViewController, PrimerHeadlessUniversalCheckoutDelegate {
    // ...
    // 👇 Add this    func primerHeadlessUniversalCheckoutDidTokenizePaymentMethod(        _ paymentMethodTokenData: PrimerPaymentMethodTokenData,        decisionHandler: @escaping (PrimerResumeDecision) -> Void    ) {        // Create your payment        createPayment(with: paymentMethodTokenData.token) { res, err in            if let err = err {                // 👇 Call the decisionHandler to show the error screen with your custom error message                decisionHandler(.fail(withErrorMessage: "Oh no, something went wrong creating the payment..."))
            } else if let res = res {                if let newClientToken = res.requiredAction?.clientToken {                    // 👇 Call the decisionHandler with the new client token to continue the flow                    decisionHandler(.continueWithNewClientToken(requiredAction.clientToken))                } else {                    // 👇 Call the decisionHandler to show the success screen                    decisionHandler(.succeed())                }            }        }    }}
swift
copy

primerHeadlessUniversalCheckoutDidResumeWith

This method will be called providing a resumeToken so you can resume the payment.

⚠️

This method will be called when you are using PrimerPaymentHandling.MANUAL flow and when the payment is in a PENDING state.

1234
func primerHeadlessUniversalCheckoutDidResumeWith(    _ resumeToken: String,    decisionHandler: @escaping (PrimerHeadlessUniversalCheckoutResumeDecision) -> Void)
swift
copy

Parameters

Properties
resumeToken
StringRequired
decisionHandler
enum PrimerResumeDecisionRequired
cases

Call .succeed when you want to show the success screen, or finalize the flow successfully in case you have hidden the success screen.

Call .continueWithNewClientToken when the payment has entered in a PENDING state and a required action client token has been provided.

Example

12345678910111213141516171819202122232425262728293031
// 👇 Add thisimport PrimerSDK
// 👇 Conform to PrimerHeadlessUniversalCheckoutDelegateclass MyViewController: UIViewController, PrimerHeadlessUniversalCheckoutDelegate {
    // ...
    // 👇 Add this    func primerHeadlessUniversalCheckoutDidResumeWith(        _ resumeToken: String,        decisionHandler: @escaping (PrimerResumeDecision) -> Void    ) {        // Resume your payment        resumePayment(with: resumeToken) { res, err in            if let err = err {                // 👇 Call the decisionHandler to show the error screen with your custom error message                decisionHandler(.fail(withErrorMessage: "Oh no, something went wrong creating the payment..."))
            } else if let res = res {                if let newClientToken = res.requiredAction?.clientToken {                    // 👇 Call the decisionHandler with the new client token to continue the flow                    decisionHandler(.continueWithNewClientToken(requiredAction.clientToken))                } else {                    // 👇 Call the decisionHandler to show the success screen                    decisionHandler(.succeed())                }            }        }    }}
swift
copy

primerHeadlessUniversalCheckoutDidEnterResumePendingWithPaymentAdditionalInfo

This callback is trigger when the payment is not authorized as it’s an asynchronous alternative payment method, such as a voucher payment method, but the payment has stayed in a pending state.

⚠️

This method will be called only when using the PrimerPaymentHandling.auto flow.

1
func primerHeadlessUniversalCheckoutDidEnterResumePendingWithPaymentAdditionalInfo(_ additionalInfo: PrimerCheckoutAdditionalInfo?)
swift
copy

Parameters

Properties
additionalInfo
PrimerCheckoutAdditionalInfo
direct subclasses
parameters
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
parameters
expiresAt
StringRequired
qrCodeUrl
String
qrCodeBase64
StringRequired
Subclasses
Properties
collectorViewController
UIViewController
Provides the bank account collector for ACH bank account selection.
ACHMandateAdditionalInfo
ACHAdditionalInfo

Provides an empty ACHMandateAdditionalInfo object to prompt the merchant to display the mandate information.

primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo

This callback is trigger when the payment is not authorized as it’s an asynchronous alternative payment method, such as a voucher payment method.

⚠️

This method will be called only when using the PrimerPaymentHandling.auto flow.

1
func primerHeadlessUniversalCheckoutDidReceiveAdditionalInfo(_ additionalInfo: PrimerCheckoutAdditionalInfo?)
swift
copy

Parameters

Properties
additionalInfo
PrimerCheckoutAdditionalInfo
direct subclasses
parameters
expiresAt
StringRequired
couponCode
StringRequired
retailerName
StringRequired
parameters
expiresAt
StringRequired
qrCodeUrl
String
qrCodeBase64
StringRequired
Subclasses
Properties
collectorViewController
UIViewController
Provides the bank account collector for ACH bank account selection.
ACHMandateAdditionalInfo
ACHAdditionalInfo

Provides an empty ACHMandateAdditionalInfo object to prompt the merchant to display the mandate information.

primerHeadlessUniversalCheckoutDidFail

This method will be called when an error occurs. It may return PrimerCheckoutData if the error occurs after the payment creation.

1
func primerHeadlessUniversalCheckoutDidFail(withError err: Error, checkoutData: PrimerCheckoutData?)
swift
copy

Parameters

Properties
err
ErrorRequired

primerHeadlessUniversalCheckoutWillUpdateClientSession

This method will be called to notify you that the client session will be updated, e.g. a surcharge needs to be applied when a payment method has been chosen.

1
func primerHeadlessUniversalCheckoutWillUpdateClientSession()
swift
copy

primerHeadlessUniversalCheckoutDidUpdateClientSession

This method will be called to notify you that the client session has been updated, e.g. surcharge has been applied when a payment method has been chosen.

1
func primerHeadlessUniversalCheckoutDidUpdateClientSession(_ clientSession: PrimerClientSession)
swift
copy

Parameters

clientSession
PrimerClientSessionRequired

primerHeadlessUniversalCheckoutWillCreatePaymentWithData

This method will be called with just before the payment gets created, and lets you decide whether you want to proceed with the payment creation.

⚠️ This method will be called only when checking out using the auto flow.

1234
func primerHeadlessUniversalCheckoutWillCreatePaymentWithData(    _ data: PrimerCheckoutPaymentMethodData,    decisionHandler: @escaping (PrimerPaymentCreationDecision) -> Void)
swift
copy

Parameters

Properties
paymentMethodTokenData
PrimerPaymentMethodTokenData
parameters
id
String
paymentInstrumentData
PaymentInstrumentData
parameters
sessionInfo
SessionInfo
network
String
binData
BinData
threeDSecureAuthentication
ThreeDS.AuthenticationDetails
externalPayerInfo
ExternalPayerInfo
Additional Paypal data.
Properties
email
String
The payer's email address.
The payer's unique ID.
firstName
String?
The payer's given name.
lastName
String?
The payer's given surname.
shippingAddress
ShippingAddress
sessionData
SessionData
threeDSecureAuthentication
ThreeDS.AuthenticationDetails
token
StringRequired
vaultData
VaultData
decisionHandler
enum PrimerPaymentCreationDecisionRequired
cases

Call .continuePaymentCreation when you want to continue with the payment creation.

Call .abortPaymentCreation when you want to abort the payment. Optionally you can provide an error message to get presented on the error screen.

Example

12345678910111213141516
// 👇 Add thisimport PrimerSDK
// 👇 Conform to PrimerHeadlessUniversalCheckoutDelegateclass MyViewController: UIViewController, PrimerHeadlessUniversalCheckoutDelegate {
    // ...
    // 👇 Add this    func primerHeadlessUniversalCheckoutWillCreatePaymentWithData(        _ data: PrimerCheckoutPaymentMethodData,        decisionHandler: @escaping (PrimerPaymentCreationDecision) -> Void    ) {
    }}
swift
copy