To enable the Adyen POS Mobile SDK for iOS to handle transactions, you need to add code to your iOS POS app. This code starts a transaction with:
- A Terminal API request.
- The card reader as the payment interface to use.
- The presentation mode you want to use.
After you have added this code, payments take place as follows:
-
Your iOS POS app creates a Terminal API request that is serialized to JSON, or you receive the Terminal API request from your backend.
Tip
To help you create Terminal API requests, we provide a TerminalAPIKit for iOS on GitHub. Installation and usage instructions are in the repository's README. - You pass the Terminal API request to the Adyen POS Mobile SDK.
- The SDK checks if the session is still valid, and if necessary establishes a new session.
- The transaction starts on your mobile device. The SDK shows instructions for the customer on your mobile device.
- The SDK passes the Terminal API response to your POS app.
Use the warm-up function
To speed up initiating transactions, you can use the warm-up function. This function checks for a session and any configuration changes, and prepares the proximity reader on the iPhone. As a best practice, call the warm-up function:
- When the POS app starts. In other words, as soon as the app has the active state.
- When the POS app returns to the active state after running in the background.
To call the warm-up function:
try await paymentService.warmUp()
Handle a payment
In your iOS POS app, add code for the following steps:
-
If you create the Terminal API payment request in your POS app, use
PaymentService.installationId
asPOIID
in the MessageHeader of the payment request. (If you create the Terminal API payment request in the backend, the backend uses theinstallationId
from the/sessions
response.) -
Create an instance of
Payment.Request
usingPayment.Request(data:)
, and pass the Terminal API payment request from your POS app or backend.let transaction = try Payment.Request(data: requestData)
-
Get a
PaymentInterface
from an instance ofPaymentService
, usingPaymentService.getPaymentInterface(with:)
.Value Description cardReader
Use the card reader. let paymentService = PaymentService(...) let paymentInterface = try paymentService .getPaymentInterface(with: .cardReader)
-
Specify a
TransactionPresentationMode
that matches the UI framework of the POS app.Value Description viewModifier
The UI is embedded in a View
as aViewModifier
.presentingViewController
The UI is presented on top of the provided UIViewController
.
If you uselet presentationMode: TransactionPresentationMode = .viewModifier
TransactionPresentationMode.viewModifier
, apply it on your SwiftUI view as follows:Button(...) { // code to start the transaction }.transactionModal(with: {YOUR_INSTANCE_OF_PAYMENT_SERVICE})
-
Invoke
PaymentService.performTransaction(with:paymentInterface:presentationMode:)
on your instance ofPaymentService
.
The Adyen POS Mobile SDK checks for a session, starts the transaction, and shows screens on your mobile device to help the customer.let transactionResponse = await paymentService.performTransaction( with: transaction, paymentInterface: paymentInterface, presentationMode: presentationMode )
-
Check the
paymentResponse
that you receive. This is the Terminal API response with the result of the transaction, including any errors and data you can use to generate a receipt. -
Pass the
paymentResponse
to your POS app.
Handle a refund
There are two types of refund: referenced and unreferenced. The main difference is that a referenced refund is connected to the original payment, and an unreferenced refund isn't. That makes unreferenced refunds a bit riskier. For an overview of the differences, see Refund a payment.
Refunds are usually not processed synchronously. When you send a request for a referenced or unreferenced refund, the Terminal API response only confirms we received the request. Unreferenced refunds, however, can be processed synchronously. This depends on the card scheme and the country where the card is used. If processed synchronously, you receive an additional field in the Terminal API response: acquirerResponseCode
.
To learn the outcome of a refund, you need to set up webhooks.
Handle an unreferenced refund
The Terminal API request for an unreferenced refund is a payment request with an additional parameter:
PaymentData.PaymentType
: Refund
This means you can use the same code as for handling a payment. The only difference is the structure of the Terminal API payment request that you pass as the requestData
to the Payment.Request
.