Secure Remote Commerce
Client-Side Implementation
Installation
Braintree
In your Podfile
, include BraintreeVisaCheckout
:
- Ruby
pod 'BraintreeVisaCheckout'
SRC
The Braintree Visa Checkout SDK depends on and includes VisaCheckoutSDK
v7.2.0. It requires Xcode 12.0.
Initialization
- Configure the
VisaCheckoutSDK
when your app launches:
- Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
VisaCheckoutSDK.configure()
return true
}
-
Instantiate a
BTAPIClient
using the appropriate authorization- If using 3D Secure with Visa Checkout, you must use a client token from your server
- Otherwise, you can choose between a tokenization key or a client token
-
Instantiate a
BTVisaCheckoutClient
:
- Swift
let client = BTAPIClient(authorization: "<#CLIENT_AUTHORIZATION#>")!
self.visaCheckoutClient = BTVisaCheckoutClient(apiClient: client)
- Create a
Profile
using theBTVisaCheckoutClient
:
- 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 token
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 details
- Create a
PurchaseInfo
object, passing in an amount and currency - Specify additional payment details on this object, e.g. description, subtotal, shipping
Here is an example:
- Swift
let total = CurrencyAmount(string: "1.00")
let purchaseInfo = PurchaseInfo(total: total, currency: .usd)
// Customize the purchase info
purchaseInfo.customDescription = "My Description"
Tokenizing
- Create a
VisaCheckoutButton
and set it up - Call
visaCheckoutClient.tokenize(CheckoutResult)
with aCheckoutResult
- We tokenize the result and return a
VisaCheckoutNonce
in thecompletion
block
Here is an example:
- 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.
}
})
})
Next Page: Server-side →