Skip to content

Migrating from V1 to V2

Marcon edited this page Aug 10, 2018 · 2 revisions

Quick Integration

Starting a payment

CheckoutViewController has been replaced with CheckoutController.

Instead of

let viewController = CheckoutViewController(delegate: self)
present(viewController, animated: true)

CheckoutController should be instantiated with the presenting view controller, like this:

var checkoutController: CheckoutController?

func startCheckout() {
    checkoutController = CheckoutController(presentingViewController: self, delegate: self)
    checkoutController?.start()
}

CheckoutControllerDelegate needs to be implemented to receive callbacks instead of CheckoutViewControllerDelegate.

Replace:

func checkoutViewController(_ controller: CheckoutViewController, requiresPaymentDataForToken token: String, completion: @escaping DataCompletion)

with:

func requestPaymentSession(withToken token: String, for checkoutController: CheckoutController, responseHandler: @escaping Completion<String>)

Just like before, this method should be used to fetch payment data and pass it to the completion handler.

Upon receiving valid payment data, the SDK will present a preselected payment method for convenience. If no preselected methods are available, a list of available payment methods will be displayed. This behaviour can be disabled, in which case the SDK will default to presenting a list of all payment methods:

checkoutController.showsPreselectedPaymentMethod = false

Finishing a payment

The payment flow can be cancelled at any time:

checkoutController.cancel()

Replace:

func checkoutViewController(_ controller: CheckoutViewController, didFinishWith result: PaymentRequestResult)

with:

func didFinish(with result: Result<PaymentResult>, for checkoutController: CheckoutController)

Redirect payment methods

There is no longer a delegate method that handles redirect payments. Instead, when the application(_:open:options:) call is received by the Application Delegate, the following method should be invoked:

Adyen.applicationDidOpen(url)

This method will return true if the url was handled by Adyen, and false if not.

Card scanning

To integrate your own card scanning framework, CheckoutViewControllerCardScanDelegate needs to be removed and replaced with CardScanDelegate. The delegate should be assigned like this:

checkoutController.cardScanDelegate = self

Appearance

This version of the API offers a lot more appearance customisation through the Appearance object. Appearance has replaced AppearanceConfiguration. An appearance object can be passed to the SDK at initialisation:

let appearance  = Appearance()
// Customize appearance
let checkoutController = CheckoutController(presentingViewController: self, delegate: self, appearance: appearance)

Custom Integration

Starting a payment

PaymentRequest has been replace with PaymentController. PaymentControllerDelegate needs to be implemented to receive callbacks instead of PaymentRequestDelegate.

Selecting a payment method

To select a payment method, implement:

func selectPaymentMethod(from paymentMethods: PaymentMethods, for paymentController: PaymentController, selectionHandler: @escaping Completion<PaymentMethod>)

The selection handler should be called after the paymentMethod.details have been filled in. This is in contrast to the paymentRequest:requiresPaymentMethodFrom:available:completion: method in PaymentRequestDelegate, after which paymentRequest:requiresPaymentDetails:completion: was called.

Redirect

While redirect:paymentController: should still be implemented to handle redirect payment methods, there is no longer a completion block to handle the return url. Instead, when the application(_:open:options:) call is received by the Application Delegate, the following method should be invoked:

Adyen.applicationDidOpen(url)