Documentation

BankPay

  1. Home
  2. BankPay
  3. Overview
  4. BankPay SDK for iOS Documentation

BankPay SDK for iOS Documentation

This SDK allows you to implement ACH payments in your iOS app.

Installing the SDK

SDK Files

BankPay iOS SDK v2.0

Requirements

  • iOS 12.1+
  • Swift 4+

Set up

  1. Download the universal binary zip and extract it.
  2. Drag the BankPay_sdk_ios.xcframework folder into your project, select “Copy items if needed”, “Create groups”, and “Add to Targets” for your App’s project, then click “Finish”

Using the SDK

Creating the BankPaySdk Instance

To start, define three Info.plist variables for the environment, publishable key, and open banking redirect. The default keys for these are BankPay-environment, BankPay-publishableKey, and BankPay-openBankingRedirect. A new BankPaySdk instance can be instantiated after the variables have been created.

// Basic instantiation uses the default environment, publishable key, and open
// banking redirect variables from your Info.plist.
let bankPay = BankPaySdk()

// To override the location of the environment in your Info.plist, provide it
// during instantiation.
let bankPay = BankPaySdk(environmentInfoName: "yourEnvironmentName")

// To override the location of the publishable key in your Info.plist, provide it
// during instantiation.
let bankPay = BankPaySdk(publishableKeyInfoName: "yourPublishableKeyName")

// To override the location of the Open Banking redirect URL in your Info.plist,
// provide it during instantiation.
let bankPay = BankPaySdk(openBankingRedirectInfoName: "yourRedirectName")

// Or provide all three
let bankPay = BankPaySdk(
    environmentInfoName: "yourEnvironmentName",
    publishableKeyInfoName: "yourPublishableKeyName",
    openBankingRedirectInfoName: "yourRedirectName"
)

Using the Enrollment Flow

Instantiate a new enrollment webview for an enrollment by providing the enrollment_intent_id you received from the create enrollment intent request made by your server.

let webView = bankPay.createEnrollmentWebView(intentId: enrollmentIntentId);

After instantiating the webview attach the event listeners you need to listen for.

webView.events.addObserver(
    self,
    selector: #selector(onReadyForAuthorization(notification:)),
    name: Notification.Name(BankPayEventName.readyForAuthorization.rawValue),
    object: nil
)

The observer should accept a notification that will contain an object that can be cast to the relevant event data type.

@objc func onReadyForAuthorization(notification: Notification) {
    let data = notification.object as! BankPayReadyForAuthorizationEventData

    // Authorize enrollment intent using data.intentId
}

Using the Transaction Flow

Instantiate a new transaction webview for a transaction by providing the transaction_intent_id you received from the create transaction intent request made by your server.

let webView = bankPay.createTransactionWebView(intentId: transactionIntentId);

After instantiating the webview attach the event listeners you need to listen for.

webView.events.addObserver(
    self,
    selector: #selector(onReadyForAuthorization(notification:)),
    name: Notification.Name(BankPayEventName.readyForAuthorization.rawValue),
    object: nil
)

The observer should accept a notification that will contain an object that can be cast to the relevant event data type.

@objc func onReadyForAuthorization(notification: Notification) {
    let data = notification.object as! BankPayReadyForAuthorizationEventData

    // Authorize transaction intent using data.intentId
}

Supporting Open Banking

To support open banking you must setup a URL scheme or Universal Link then provide it using the BankPay-openBankingRedirect key in your Info.plist. For more information see Open Banking.

Events

The webview will emit events at various points during the enrollment and transaction flows. These are defined with the BankPayEventName enum.

BankPayEventName.cancel

Value: "cancel"

This is called whenever the users leaves the webview without finishing their enrollment or transaction.

Data

N/A

BankPayEventName.close

Value: "close"

This is called whenever the users performs an action which should end the WebView. This will be called with "cancel", "failure", and "success".

Data

N/A

BankPayEventName.failure

Value: "failure"

This is called when the user leaves the webview after their enrollment or transaction has failed.

Data

struct BankPayFailureEventData {
    var message: String // A description of the outcome.
    var status: String // The status of the intent (Example: "declined")
}

BankPayEventName.readyForAuthorization

Value: "readyForAuthorization"

This is called when the user is finished with the enrollment or transaction and the intent is ready for authorization.

Data

struct BankPayReadyForAuthorizationEventData {
    var intentId: String // The enrollment or transaction intent ID.
}

BankPayEventName.success

Value: "success"

This is called when the user leaves the webview after their enrollment or transaction has succeeded.

Data

struct BankPaySuccessEventData {
    var message: String // A description of the outcome.
    var status: String // The status of the intent (Example: "accepted")
}

Example

class ViewController: UIViewController {
    var bankPay: BankPaySdk = try! BankPaySdk()

    override func viewDidLoad() {
        super.viewDidLoad()

        let webView = bankPay.createEnrollmentWebView(intentId: "FAKE-INTENT-TOKEN")

        webView.events.addObserver(
            self,
            selector: #selector(onCancel(notification:)),
            name: Notification.Name(BankPayEventName.cancel.rawValue),
            object: nil
        )

        webView.events.addObserver(
            self,
            selector: #selector(onClose(notification:)),
            name: Notification.Name(BankPayEventName.close.rawValue),
            object: nil
        )

        webView.events.addObserver(
            self,
            selector: #selector(onFailure(notification:)),
            name: Notification.Name(BankPayEventName.failure.rawValue),
            object: nil
        )

        webView.events.addObserver(
            self,
            selector: #selector(onReadyForAuthorization(notification:)),
            name: Notification.Name(BankPayEventName.readyForAuthorization.rawValue),
            object: nil
        )

        webView.events.addObserver(
            self,
            selector: #selector(onSuccess(notification:)),
            name: Notification.Name(BankPayEventName.success.rawValue),
            object: nil
        )

        addChild(webView)
        view.addSubview(webView.view)
        webView.view.frame = view.bounds
        webView.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        webView.didMove(toParent: self)
        webView.view.isHidden = false
    }

    @objc func onCancel(notification: Notification) {
        // Handle cancel events
    }

    @objc func onClose(notification: Notification) {
        dismiss(animated: true, completion: nil);
    }

    @objc func onFailure(notification: Notification) {
        let data = notification.object as! BankPayFailureEventData

        // Handle failure events
    }

    @objc func onReadyForAuthorization(notification: Notification) {
        let data = notification.object as! BankPayReadyForAuthorizationEventData

        // Authorize enrollment intent using data.intentId
    }

    @objc func onSuccess(notification: Notification) {
        let data = notification.object as! BankPaySuccessEventData

        // Handle success events
    }
}

Back to Top

Was this article helpful to you? Yes No

How can we help?