• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Adyen iOS Drop-in and Components

GitHub Workflow Status Pod carthage compatible SwiftPM Coverage

Sonarcloud Status SonarCloud Bugs SonarCloud Vulnerabilities Maintainability Rating Reliability Rating Security Rating


iOS Logo

Adyen iOS

Adyen iOS provides you with the building blocks to create a checkout experience for your shoppers, allowing them to pay using the payment method of their choice.

You can integrate with Adyen iOS in two ways:

  • iOS Drop-in: an all-in-one solution, the quickest way to accept payments on your iOS app.
  • iOS Components: one Component per payment method and combine with your own payments flow.

Installation

Adyen iOS are available through either CocoaPods, Carthage or Swift Package Manager.

Minimum Requirements

  • iOS 12.0
  • Xcode 14.0
  • Swift 5.7

CocoaPods

  1. Add pod 'Adyen' to your Podfile.
  2. Run pod install.

You can install all modules or add individual modules, depending on your needs and integration type. The Adyen/WeChatPay module needs to be explicitly added to support WeChat Pay. The Adyen/SwiftUI module needs to be explicitly added to use the SwiftUI specific helpers.

pod 'Adyen'               // Add DropIn with all modules except WeChat Pay and SwiftUI.
// Add individual modules
pod 'Adyen/Card'          // Card components.
pod 'Adyen/Session'       // Handler for the simplified checkout flow.
pod 'Adyen/Encryption'    // Encryption module.
pod 'Adyen/Components'    // All other payment components except WeChat Pay.
pod 'Adyen/Actions'       // Action Components.
pod 'Adyen/WeChatPay'     // WeChat Pay Component.
pod 'Adyen/SwiftUI'       // SwiftUI apps specific module.

⚠️ Adyen/AdyenWeChatPay and AdyenWeChatPayInternal modules doesn't support any simulators and can only be tested on a real device.

Carthage

  1. Add github "adyen/adyen-ios" to your Cartfile.
  2. Run carthage update.
  3. Link the framework with your target as described in Carthage Readme.

You can add all modules or select individual modules to add to your integration. But make sure to include each module dependency modules.

  • AdyenDropIn: DropInComponent.
  • AdyenSession: handler for the simplified checkout flow.
  • AdyenCard: the card components.
  • AdyenComponents: all other payment components except WeChat Pay.
  • AdyenActions: action components.
  • AdyenEncryption: encryption.
  • AdyenWeChatPay: WeChat Pay component.
  • AdyenWeChatPayInternal: WeChat Pay component.
  • AdyenSwiftUI: SwiftUI apps specific module.

⚠️ AdyenWeChatPay and AdyenWeChatPayInternal modules doesn't support any simulators and can only be tested on a real device.

Swift Package Manager

  1. Follow Apple's Adding Package Dependencies to Your App guide on how to add a Swift Package dependency.
  2. Use https://github.com/Adyen/adyen-ios as the repository URL.
  3. Specify the version to be at least 4.9.0.

You can add all modules or select individual modules to add to your integration. The AdyenWeChatPay module needs to be explicitly added to support WeChat Pay. The AdyenSwiftUI module needs to be explicitly added to use the SwiftUI specific helpers.

  • AdyenDropIn: all modules except AdyenWeChatPay.
  • AdyenSession: handler for the simplified checkout flow.
  • AdyenCard: the card components.
  • AdyenComponents: all other payment components except WeChat Pay.
  • AdyenActions: action components.
  • AdyenEncryption: encryption.
  • AdyenWeChatPay: WeChat Pay component.
  • AdyenSwiftUI: SwiftUI apps specific module.

⚠️ Swift Package Manager for Xcode 12.0 and 12.1 has a know issue when it comes to importing a dependency that in turn depend on a binary dependencies. A workaround is described here.

⚠️ AdyenWeChatPay and AdyenWeChatPayInternal modules doesn't support any simulators and can only be tested on a real device.

Drop-in

The Drop-in handles the presentation of available payment methods and the subsequent entry of a customer's payment details. It is initialized with the response of /sessions, and handles the entire checkout flow under the hood.

Usage

Setting up the Drop-in

All Components need an AdyenContext. An instance of AdyenContext wraps your client key, environment, analytics configuration and so on. Please read more here about the client key and how to get one. Use Environment.test for environment. When you're ready to accept live payments, change the value to one of our live environments

let apiContext = try! APIContext(environment: componentsEnvironment, clientKey: clientKey)
let context = AdyenContext(apiContext: apiContext,
                           payment: payment)
let configuration = DropInComponent.Configuration()

Create an instance of AdyenSession.Configuration with the response you received from the /sessions call and the AdyenContext instance.

let configuration = AdyenSession.Configuration(sessionIdentifier: response.sessionId,
                                               initialSessionData: response.sessionData,
                                               context: context)

Call the static initialize function of the AdyenSession by providing the configuration and the delegates, which will asynchronously create and return the session instance.

AdyenSession.initialize(with: configuration, delegate: self, presentationDelegate: self) { [weak self] result in
    switch result {
    case let .success(session):
        // store the session object
        self?.session = session
    case let .failure(error):
        // handle the error
    }
}

Create a configuration object for DropInComponent. Check specific payment method pages to confirm if you need to include additional required parameters.

// Check specific payment method pages to confirm if you need to configure additional required parameters.
let dropInConfiguration = DropInComponent.Configuration()

Some payment methods need additional configuration. For example ApplePayComponent. These payment method specific configuration parameters can be set in an instance of DropInComponent.Configuration:

let summaryItems = [
                      PKPaymentSummaryItem(label: "Item A", amount: 75, type: .final),
                      PKPaymentSummaryItem(label: "Item B", amount: 25, type: .final),
                      PKPaymentSummaryItem(label: "My Company", amount: 100, type: .final)
                   ]
let applePayment = try ApplePayPayment(countryCode: "US",
                                       currencyCode: "USD",
                                       summaryItems: summaryItems)

dropInConfiguration.applePay = .init(payment: applePayment,
                                     merchantIdentifier: "merchant.com.adyen.MY_MERCHANT_ID")

Also for voucher payment methods like Doku variants, in order for the DokuComponent to enable the shopper to save the voucher, access to the shopper photos is requested, so a suitable text needs to be added to the NSPhotoLibraryAddUsageDescription key in the application Info.plist.

Presenting the Drop-in

Initialize the DropInComponent class and set the AdyenSession instance as the delegate and partialPaymentDelegate (if needed) of the DropInComponent instance.

let dropInComponent = DropInComponent(paymentMethods: session.sessionContext.paymentMethods,
                                      context: context,
                                      configuration: dropInConfiguration)
 
// Keep the Drop-in instance to avoid it being destroyed after the function is executed.
self.dropInComponent = dropInComponent
 
// Set session as the delegate for Drop-in
dropInComponent.delegate = session
dropInComponent.partialPaymentDelegate = session
 
present(dropInComponent.viewController, animated: true)

Implementing AdyenSessionDelegate

AdyenSession makes the necessary calls to handle the whole flow and notifies your application through its delegate, AdyenSessionDelegate. To handle the results of the Drop-in, the following methods of AdyenSessionDelegate should be implemented:


func didComplete(with result: AdyenSessionResult, component: Component, session: AdyenSession)

This method will be invoked when the component finishes without any further steps needed by the application. The application just needs to dismiss the current component, ideally after calling finalizeIfNeeded on the component.


func didFail(with error: Error, from component: Component, session: AdyenSession)

This method is invoked when an error occurred during the use of the Drop-in or the components. You can then call the finalizeIfNeeded on the component, dismiss the component's view controller in the completion callback and display an error message.


func didOpenExternalApplication(component: DropInComponent)

This optional method is invoked after a redirect to an external application has occurred.


Handling an action

Actions are handled by the Drop-in via its delegate AdyenSession.

Receiving redirect

In case the customer is redirected to an external URL or App, make sure to let the RedirectComponent know when the user returns to your app. Do this by implementing the following in your UIApplicationDelegate:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
    RedirectComponent.applicationDidOpen(from: url)

    return true
}

Components

In order to have more flexibility over the checkout flow, you can use our Components to present each payment method individually. Implementation details of our Components can be found in our Components API Reference.

Available Components

Customization

Both the Drop-in and the Components offer a number of customization options to allow you to match the appearance of your app. For example, to change the section header titles and form field titles in the Drop-in to red, and turn the submit button's background to black with white foreground:

var style = DropInComponent.Style()
style.listComponent.sectionHeader.title.color = .red
style.formComponent.textField.title.color = .red
style.formComponent.mainButtonItem.button.backgroundColor = .black
style.formComponent.mainButtonItem.button.title.color = .white

let dropInComponent = DropInComponent(paymentMethods: paymentMethods,
                                      configuration: configuration,
                                      style: style)
dropInComponent.delegate = self.session

Or, to create a black Card Component with white text:

var style = FormComponentStyle()
style.backgroundColor = .black
style.header.title.color = .white
style.textField.title.color = .white
style.textField.text.color = .white
style.switch.title.color = .white

let component = CardComponent(paymentMethod: paymentMethod,
                              apiContext: context.apiContext,
                              style: style)
component.delegate = self.session

A full list of customization options can be found in the API Reference.

See also

Support

If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our support team.

Contributing

We strongly encourage you to join us in contributing to this repository so everyone can benefit from:

  • New features and functionality
  • Resolved bug fixes and issues
  • Any general improvements

Read our contribution guidelines to find out how.

License

This repository is open source and available under the MIT license. For more information, see the LICENSE file.

More Repositories

1

adyen-web

Adyen Web Drop-in and Components
TypeScript
183
star
2

adyen-magento2

Adyen Payment plugin for Magento2
PHP
155
star
3

adyen-php-api-library

Adyen API Library for PHP
PHP
153
star
4

adyen-android

Adyen Android Drop-in and Components
Kotlin
126
star
5

adyen-java-api-library

Adyen API Library for Java
Java
115
star
6

adyen-dotnet-api-library

Adyen API Library for .NET
C#
108
star
7

adyen-node-api-library

Adyen API Library for Node.js
TypeScript
104
star
8

adyen-salesforce-commerce-cloud

Salesforce Commerce Cloud (formerly Demandware)
JavaScript
91
star
9

adyen-openapi

OpenAPI specification for the Adyen APIs
67
star
10

adyen-python-api-library

Adyen API Library for Python
Python
59
star
11

adyen-components-js-sample-code

Sample code of Adyen Components
JavaScript
54
star
12

adyen-go-api-library

Adyen API Library for Go
Go
51
star
13

adyen-react-native

Adyen React Native
Kotlin
45
star
14

adyen-commercetools

commercetools-adyen-integration provides an integration between the commercetools and Adyen payment service provider based on the concept of Adyen Web Components.
JavaScript
45
star
15

adyen-ruby-api-library

Adyen API Library for Ruby
Ruby
44
star
16

lume

Lume is a component library for visual representations of data, built for Vue with D3.
TypeScript
43
star
17

adyen-postgres-partitioning

Functions to manage partitions in PostgreSQL with minimal impact for applications
PLpgSQL
35
star
18

adyen-barcoder-ios

Use Verifone Barcode scanner over MFi
Swift
30
star
19

adyen-cse-ios

[Deprecated] Sample code for client-side encryption on iOS
Objective-C
28
star
20

adyen-3ds2-android

26
star
21

adyen-hybris

Adyen Payment plugin for Hybris
Java
25
star
22

adyen-flutter

Dart
23
star
23

adyen-3ds2-js-utils

Helper functions to get 3DS 2.0 integrated on the front-end
JavaScript
22
star
24

adyen-cse-android

[Deprecated] Sample code for client-side encryption on Android
Java
21
star
25

adyen-shopware6

Adyen Payment plugin for Shopware 6
PHP
21
star
26

adyen-3ds2-ios

Objective-C
18
star
27

adyen-cse-web

[DEPRECATED] Client-side encryption on JavaScript
JavaScript
15
star
28

adyen-postman

Postman files for the Adyen APIs
Shell
15
star
29

adyen-prestashop

Adyen Payment plugin for Prestashop
PHP
14
star
30

feast-spark-offline-store

This repo contains a plugin for feast to run an offline store on Spark
Python
14
star
31

adyen-pos-mobile-ios

Adyen POS Mobile SDK for iOS enabling the integration of TapToPay and the NYC1 card reader.
HTML
12
star
32

adyen-shopware5

PHP
11
star
33

adyen-magento2-express-checkout

Adyen Magento 2 Express Checkout Module
PHP
10
star
34

adyen-terminal-api-ios

Adyen Terminal API for iOS
Swift
10
star
35

adyen-secured-fields-sample-code

JavaScript
9
star
36

adyen-salesforce-b2b-commerce

Adyen app for Salesforce B2B Commerce
Apex
9
star
37

adyen-web-sdk-sample-code

Sample code for Adyen Web SDK
PHP
7
star
38

adyen-magento2-hyva

PHP
7
star
39

adyen-salesforce-headless-commerce-pwa

B2C Commerce Headless Integration Composable Storefront
JavaScript
6
star
40

adyen-pos-mobile-android

Kotlin
5
star
41

adyen-integration-tools-tests

JavaScript
5
star
42

adyen-wechatpay-ios

Adyen WeChat Pay SDK Wrapper
Objective-C
5
star
43

adyen-networking-ios

Swift
5
star
44

php-webhook-module

PHP Webhook Helper Module for Adyen Payment Integrations
PHP
5
star
45

adyen-openapi-generator

Generate OpenApi models from Adyen Services APIs
JavaScript
5
star
46

adyen-authentication-ios

AdyenAuthentication SDK Provides reusable and easy to use two factor authentication for security sensitive use cases like banking, issuing and PSD2 strong customer authentication.
C++
4
star
47

adyen-document-viewer

Adyen Document Viewer
TypeScript
3
star
48

.github

Organization-wide community health files in the @adyen organization
3
star
49

adyen-testcards-android

Easily autofill Adyen test payment methods on Android.
Kotlin
2
star
50

adyen-salesforce-b2b-lightning

Salesforce B2B Commerce Lightning
Apex
2
star
51

adyen-apple-pay-provisioning-ios

Resources to help integrate Apple Pay Provisioning for Adyen issued card partners
C++
1
star
52

adyen-apex-api-library

Adyen API Library for Apex
Apex
1
star
53

release-automation-action

TypeScript
1
star