This guide is aimed at advanced users who want to create adyen integration for their custom iOS application.
You also need to install Spree Adyen extension before.
Requirements
- Adyen test account
- Set up
spree_adyen
spree extension
return_url
spree_adyen needs to be configured withreturn_url
.
Return url tells where shopper should be redirect after the payment from outside your application (for example klarna or most of others buy now pay later systems).
Use the custom URL for your app, like my-app://adyen
. Url can contain custom query params however do not include any personally identifiable information (PII) of your customer. Maximum length of the url is 1024 characters.
Note
The list of available library versions can be found on Official Adyen Documentation for iOS integration Current newest version available at the moment of writing the tutorial is 5.19.2.Resources
- Official Adyen Documentation for iOS integration
- Spree Adyen API docs - create payment_session and get payment_session
- Official Adyen example for iOS integration
- Apple Developer documentation on defining custom url scheme
Overview
The integration consists of two main components:- Spree Adyen: Provides API for your client and receive payment result from Adyen
- Your iOS client app: Shows the Drop-in UI and handles payment flow
Step 1: Install adyen with Swift Package Manager
repository URL:Step 2: Create the context
Create the instance of APIContext that includes client key and environment setting.environment
- Environment.test or Environment.live
clientKey
- client_key
from payment_sessions endpoint
Step 3: Create and set up session
Create a session using payment_session endpoint. Then set a configuration using data from the response:data
- available asadyen_data
in payment_session API responsesessionId
- available asadyen_id
in payment_session API response
Step 4. Configure Drop-in
Step 5: Initialize the DropInComponent class
Step 6: Show Drop-in in your app
action
field is redirect
you need to handle the redirect result.
Step 7. Handling the redirect result
If theaction
field returns redirect
the shopper is completing the payment outside of your application. You need to inform the Drop-in when the shopper returns to your app.
Here an example for a Custom Url scheme:
- implement the following in your
UIApplicationDelegate
:
Step 8: Show the shopper result of the payment
When the payment flow is finished, your instance of AdyenSession calls the didComplete method. Implement the following in your Drop-in configuration object.authorised
- payment authorisedrefused
- payment refusedpending
- payment pending (for payments with asynchronous flow like iDEAL). When the shopper completes the payment webhook will process process the payment.cancelled
- payment canceledreceived
- some payments needs more time to be processed. When the status is available webhook will process the paymenterror
- an error occurred when processing the payment. The response contains more details with the error code Your instance of AdyenSession calls the didFail method containing the error.
Step 8: Continue shopping experience
- Wait for backend to process the payment
- Continue shopping experience
1. Wait for backend to process the payment
backend after receiving webhook will change the state ofpayment_session
to one of the following state:
pending
- chosen payment method can take a while to completecompleted
- payment resulted in success, order completedcanceled
- payment canceled, payment isvoid
refused
- payment failed