Code Monkey home page Code Monkey logo

adyen-ios's Introduction

Adyen Components for iOS

Adyen Components for iOS allows you to accept in-app payments by providing you with the building blocks you need to create a checkout experience.

Installation

Adyen Components for iOS are available through either CocoaPods or Carthage.

CocoaPods

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

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.

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 /paymentMethods, and provides everything you need to make an API call to /payments and /payments/details.

Usage

Presenting the Drop-in

The Drop-in requires the response of the /paymentMethods endpoint to be initialized. To pass the response to Drop-in, decode the response to the PaymentMethods structure:

let paymentMethods = try JSONDecoder().decode(PaymentMethods.self, from: response)

Some payment methods need additional configuration. For example, to enable the card form, the Drop-in needs a public key to use for encryption. These payment method specific configuration parameters can be set in an instance of DropInComponent.PaymentmethodsConfiguration:

let configuration = DropInComponent.PaymentMethodsConfiguration()
configuration.card.publicKey = "..." // Your public key, retrieved from the Customer Area.

After serializing the payment methods and creating the configuration, the Drop-in is ready to be initialized. Assign a delegate and use the viewController property to present the Drop-in on the screen:

let dropInComponent = DropInComponent(paymentMethods: paymentMethods,
paymentMethodsConfiguration: configuration)
dropInComponent.delegate = self
present(dropInComponent.viewController, animated: true)

Implementing DropInComponentDelegate

To handle the results of the Drop-in, the following methods of DropInComponentDelegate should be implemented:


func didSubmit(_ data: PaymentComponentData, from component: DropInComponent)

This method is invoked when the customer has selected a payment method and entered its payment details. The payment details can be read from data.paymentMethod and can be submitted as-is to /payments.


func didProvide(_ data: ActionComponentData, from component: DropInComponent)

This method is invoked when additional details are provided by the Drop-in after the first call to /payments. This happens, for example, during the 3D Secure 2 authentication flow or any redirect flow. The additional details can be retrieved from data.details and can be submitted to /payments/details.


func didFail(with error: Error, from component: DropInComponent)

This method is invoked when an error occurred during the use of the Drop-in. Dismiss the Drop-in's view controller and display an error message.


Handling an action

When /payments or /payments/details responds with a non-final result and an action, you can use the Drop-in to handle the action:

let action = try JSONDecoder().decode(Action.self, from: actionData)
dropInComponent.handle(action)

In case the customer is redirected to an external URL, make sure to let the Drop-in 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 {
    Adyen.applicationDidOpen(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

See also

License

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

adyen-ios's People

Contributors

adyen-git-manager avatar anas10 avatar diegomarcon avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.