Mobile SDK

Payer Aware Payment Menu

schedule 3 min read

A payment menu tailored to the payer

Edit "Payer Aware Payment Menu" on GitHub

Payer Aware Payment Menu

Using Payer Aware Payment Menu involves managing payment tokens yourself. If you are using a Merchant Backend, you can have a payment order create payment tokens by setting the generatePaymentToken and payerReference fields of PaymentOrder and PaymentOrderPayer, respectively.

Android

1
2
3
4
5
6
7
8
val paymentOrder = PaymentOrder(
    ...,
    generatePaymentToken = true,
    payer = PaymentOrderPayer(
        payerReference = "user1234"
    )
    ...
)

iOS

1
2
3
4
paymentOrder.generatePaymentToken = true
paymentOrder.payer = PaymentOrderPayer(
    payerReference: "user1234"
)

Token Retrieval

The SDK contains a utility method to query a conforming Merchant Backend server for the payment tokens of a particular payerReference. Of course, you should have proper authentication in your implementation if you use this functionality, to prevent unauthorized access to other users’ tokens (the example implementation has the endpoint disabled by default).

The utility method allows you to add extra header to the request; these can be useful for implementing authentication.

Android

1
2
3
4
5
6
7
8
9
10
// N.B! getPayerOwnedPaymentTokens is a suspending function,
// so this call must be done inside suspending code.
// If the backend responds with a Problem, the call will throw
// a RequestProblemException.
val response = MerchantBackend.getPayerOwnedPaymentTokens(
    context,
    configuration,
    payerReference,
    "ExampleHeader", "ExampleValue"
)

iOS

1
2
3
4
5
6
7
8
9
10
11
12
13
let request = SwedbankPaySDK.MerchantBackend.getPayerOwnedPaymentTokens(
    configuration: configuration,
    payerReference: payerReference,
    extraHeaders: [
        "ExampleHeader": "ExampleValue"
    ]
) { result in
    // Use result here.
    // Be prepared for any errors of the type
    // SwedbankPaySDK.MerchantBackendError.
}
// If you need to cancel the request before it is complete, call
// request.cancel()

Token Use

To use a payment token with a Merchant Backend, create a payment order where you set the paymentToken field of PaymentOrder and the payerReference field of PaymentOrderPayer:

Android

1
2
3
4
5
6
7
8
val paymentOrder = PaymentOrder(
    ...,
    payer = PaymentOrderPayer(
        payerReference = "user1234"
    )
    paymentToken = "token"
    ...
)

iOS

1
2
3
4
paymentOrder.payer = PaymentOrderPayer(
    payerReference: "user1234"
)
paymentOrder.paymentToken = "token"

Your backend implementation should have proper authentication to prevent misuse of tokens. The example implementation will reject attempts to use paymentToken by default.

Add Stored Payment Instrument Details

The Merchant Backend allows you to set PaymentOrder.disableStoredPaymentDetails to use this feature as described in the Payment Menu Documentation.

As mentioned there, it is important that you have obtained consent from the user for storing payment details beforehand, if you use this feature.

Android

1
2
3
4
5
val paymentOrder = PaymentOrder(
    ...,
    disableStoredPaymentDetails = true
    ...
)

iOS

1
paymentOrder.disableStoredPaymentDetails = true