Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 4 KB

integrateTokensEnterprise.md

File metadata and controls

87 lines (63 loc) · 4 KB

Integrate payment tokens using the Swedbank Pay SDK for iOS

Swedbank Pay SDK for iOS

Enterprise

This document only concerns merchants using the Enterprise integration, PaymentsOnly handles this differently. Read more on tokens for PaymentsOnly

Prerequisites

Before diving into advanced features you should have a working app and backend, that can handle purchases in debug-mode. This is described in detail in the readme file, and you can also look at the iOS Example app as a reference.

Remembering the payer

Returning customers are the best customers, and it is really easy to improve the experience by auto-filling the payment details. You can supply email and phone number to let the customer store the payment information and have SwedbankPay auto-fill it the next time. Just supply a unique reference along with these values when starting a new payment:

var paymentOrder = ... //create the paymentOrder as usual by calculating price, etc
payment.payer = .init(
	consumerProfileRef: nil, 
	email: "leia.ahlstrom@payex.com", 
	msisdn: "+46739000001", 
	payerReference: unique-identifier
)

Now the customer has the option to store card numbers or select one of the previously stored cards. More info in the documentation.

Payment tokens for later use

A common practice is to store a credit-card for later use, e.g. for subscriptions, and charge every month. To make this safe & secure you let SwedbankPay store the payment information and only keep a reference, a payment token. This token can later be used to make purchases, and there are two types of tokens that can be created. One for subscriptions, and one for later unscheduled purchases. They are created the same way, by setting generateUnscheduledToken = true or generateRecurrenceToken = true, in the paymentOrder and then either making a purchase or verifying a purchase (set the operation property to PaymentOrderOperation.verify).

var paymentOrder = ... //create the paymentOrder as usual by calculating price, etc
paymentOrder.generateRecurrenceToken = true
viewController.startPayment(paymentOrder: paymentOrder)

When expanding the paid property of this verified or purchased payment, there is an array with tokens one can save for later use. Here is an abbreviated example of what is received:

{
	"paymentOrder": {
		...
		"paid": {
			...
			"tokens": [
			    {
			        "type": "recurrence",
			        "token": "a7d7d780-98ba-4466-befe-e5428f716c30",
			        "name": "458109******3517",
			        "expiryDate": "12/2030"
			    },
			    {
			        "type": "unscheduled",
			        "token": "0c43b168-dcd5-45d1-b9c4-1fb8e273c799",
			        "name": "458109******3517",
			        "expiryDate": "12/2030"
			    }
			]
		}
	}
}

Then, to make an unscheduled purchase you simply add the unscheduledToken, or the recurrenceToken to the paymentOrder request. Obviously these purchases and the expanding of tokens is only needed to be done on the backend.

More info on unscheduled purchases.

More info on recurring purchases.