Client-Side Implementation

InstallationAnchorIcon

BraintreeAnchorIcon

In your `Podfile`, include `BraintreeVisaCheckout`:
  1. Ruby
pod 'BraintreeVisaCheckout'

SRCAnchorIcon

The Braintree Visa Checkout SDK depends on and includes VisaCheckoutSDK v7.2.0. It requires Xcode 12.0. .

InitializationAnchorIcon

  1. Configure the VisaCheckoutSDK when your app launches:.

    1. Swift
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        VisaCheckoutSDK.configure()
        return true
    }
  2. Instantiate a BTAPIClient using the appropriate authorization
  3. Instantiate a BTVisaCheckoutClient:.

    1. Swift
    let client = BTAPIClient(authorization: "<#CLIENT_AUTHORIZATION#>")!
    self.visaCheckoutClient = BTVisaCheckoutClient(apiClient: client)
  4. Create a Profile using the BTVisaCheckoutClient:.

    1. Swift
    self.visaCheckoutClient.createProfile() { (profile, error) in
        guard let profile = profile as? Profile else {
            print("Failed to create Visa profile: (error!)")
            return;
        }
    
        // Customize the Visa Checkout experience
        profile.displayName = "My Merchant Name"
    }

Generating a client tokenAnchorIcon

If you choose to use a client token, you must generate it on the server and make it accessible to your client..

To use a merchant account ID other than your default, specify the MerchantAccountId when generating the client token. This merchant account ID must match the merchant account ID used to create the transaction.

Specifying payment detailsAnchorIcon

  1. Create a PurchaseInfo object, passing in an amount and currency
  2. Specify additional payment details on this object, e.g. description, subtotal, shipping
Here is an example:
  1. Swift
let total = CurrencyAmount(string: "1.00")
let purchaseInfo = PurchaseInfo(total: total, currency: .usd)

// Customize the purchase info
purchaseInfo.customDescription = "My Description"

TokenizingAnchorIcon

  1. Create a VisaCheckoutButton and set it up
  2. Call visaCheckoutClient.tokenize(CheckoutResult) with a CheckoutResult
  3. We tokenize the result and return a VisaCheckoutNonce in the completion block
Here is an example:
  1. Swift
let checkoutButton = VisaCheckoutButton.init(frame: CGRect.init(x: 0, y: 0, width: 213, height: 47))
self.view.addSubview(checkoutButton)

checkoutButton.onCheckout(profile: profile, purchaseInfo: purchaseInfo, presenting: self, onReady: { (launchHandler) in
    self.launchHandler = launchHandler
}, onButtonTapped: {
    self.launchHandler()
}, completion: { (result) in
    self.client.tokenize(result, completion: { (tokenizedVisaCheckoutCard, error) in
      if error != nil {
          print("Error tokenizing Visa Checkout card: %@", error.localizedDescription)
      } else if tokenizedVisaCheckoutCard != nil {
          // Send this nonce to your server, and create a transaction there.
          let nonce = tokenizedVisaCheckoutCard.nonce

          // Access Visa Checkout properties from this `VisaCheckoutCardNonce`, e.g.
          let shippingAddress = tokenizedVisaCheckoutCard.shippingAddress
      } else {
          // User canceled.
      }
    })
})