Skip to content

Resources to help integrate Apple Pay Provisioning for Adyen issued card partners

License

Notifications You must be signed in to change notification settings

Adyen/adyen-apple-pay-provisioning-ios

Repository files navigation

Adyen Apple Pay Provisioning

Adyen Apple Pay Provisioning iOS SDK simplifies integration with Apple wallet.

Installation

The SDK is available via Swift Package Manager or via manual installation.

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-apple-pay-provisioning-ios as the repository URL.

Dynamic xcFramework

Drag the dynamic AdyenApplePayProvisioning/XCFramework/Dynamic/AdyenApplePayProvisioning.xcframework and AdyenApplePayExtensionProvisioning/XCFramework/Dynamic/AdyenApplePayExtensionProvisioning.xcframework (wallet extension) to the Frameworks, Libraries, and Embedded Content section in your general target settings. Select "Copy items if needed" when asked.

Static xcFramework

  1. Drag the static AdyenApplePayProvisioning/XCFramework/Static/AdyenApplePayProvisioning.xcframework and AdyenApplePayExtensionProvisioning/XCFramework/Static/AdyenApplePayExtensionProvisioning.xcframework (wallet extension) to the Frameworks, Libraries, and Embedded Content section in your general target settings.
  2. Make sure the static AdyenApplePayProvisioning.xcframework and AdyenApplePayExtensionProvisioning.xcframework is not embedded.
  3. Select AdyenApplePayProvisioning.bundle inside AdyenApplePayProvisioning.xcframework (same for extension) and check "Copy items if needed", then select "Add".

Usage

Creating a provisioning service instance

Create an instance of ProvisioningService with the sdk input data retrieved from the call to /paymentInstruments/\(paymentInstrumentId)/networkTokenActivationData.

provisioningService = try ProvisioningService(sdkInput: sdkInput)

Checking if a card can be added

Check if the cardholder can add a payment card to their Apple Wallet (phone or watch). If the card cannot be added it means it is already in the wallet. However, when the watch is not available it is not possible to determine if that card is already added. Watch availability needs to be determined on the caller's side by using WCSession.

let state = provisioningService.canAddCardDetails(isWatchAvailable: true)

if state.canAddCard {
    // show "Add to Apple Wallet" button
}

Initiate card provisioning

When the cardholder selects Add card to Apple Wallet, initiate provisioning by calling the start() method with two parameters: delegate and presentingViewController

try provisioningService.start(
    delegate: self,
    presentingViewController: viewController
)

Provision the card

Implement ProvisioningServiceDelegate to receive the provision(sdkOutput) callback from the SDK. In the callback:

  1. From your back-end, make a POST paymentInstruments/{id}/networkTokenActivationData request and pass sdkOutput to provision the payment instrument. The response contains the sdkInput object.
  2. Return sdkInput from the provision method.
func provision(sdkOutput: Data, paymentInstrumentId: String) async -> Data? {
    struct ProvisioningBody: Encodable {
        let sdkOutput: Data
    }

    let encoder = JSONEncoder()
    encoder.dataEncodingStrategy = .base64

    do {
        let body = try encoder.encode(ProvisioningBody(sdkOutput: sdkOutput))
        let sdkInput = // POST the body to the server and receive `sdkInput` back
        return sdkInput
    } catch {
        return nil
    }
}

Finalize card provisioning

When the provisioning is complete update your UI

func didFinishProvisioning(with pass: PKPaymentPass?, error: Error?) {
    // Update your UI
}

Handle provisioning flow from the Wallet app (wallet extension)

In your wallet extension target create a subclass of PKIssuerProvisioningExtensionHandler which conforms to ExtensionProvisioningServiceDelegate protocol. Implement required methods (override parent class methods and implement protocol methods) and pass the data provided by the SDK.

import PassKit
import AdyenApplePayExtensionProvisioning

class ActionRequestHandler: PKIssuerProvisioningExtensionHandler, ExtensionProvisioningServiceDelegate {
    // Your implementation goes here
}

See also

License

This SDK is available under the MIT License. For more information, see the LICENSE file.

About

Resources to help integrate Apple Pay Provisioning for Adyen issued card partners

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published