Secure Remote Commerce
Client-Side Implementation
Installation
Braintree
To set up the Braintree Android SDK, see the installation guide.
SRC integration requires the Braintree Visa Checkout module, as well as several dependencies required by the Visa Checkout SDK.
The dependencies block in your build.gradle
file should look like the following:
- Groovy
dependencies {
// Braintree dependencies
implementation 'com.braintreepayments.api:braintree:3.20.1'
implementation 'com.braintreepayments.api:visa-checkout:3.20.1'
// VisaCheckout aar dependency
implementation(group: 'com.visa.checkout', name: 'visacheckout-android-sdk', version: '6.6.1', ext: 'aar')
// Dependencies required by Visa Checkout
implementation 'com.squareup.okio:okio:1.13.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'de.greenrobot:eventbus:2.4.1'
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support:design:26.0.0'
implementation 'com.android.support:multidex:1.0.0'
}
SRC
SRC for Braintree requires the Visa Checkout SDK running in your app.
To install the Visa Checkout SDK, see Visa's documentation on adding Visa Checkout to a mobile application.
The Braintree SDK is currently designed to work with the Visa Checkout Android SDK v6.6.1.
Initialization
- Initialize the Braintree Android SDK 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
- Register listeners to receive callbacks for the payment method nonce once the Visa Checkout flow finishes. At minimum, you will need:
BraintreeResponseListener<ProfileBuilder>
PaymentMethodNonceCreatedListener
- Get a
ProfileBuilder
:
- Java
VisaCheckout.createProfileBuilder(mBraintreeFragment, this);
- Once you receive a callback on your
BraintreeResponseListener<ProfileBuilder>
indicating theProfileBuilder
is ready, customize theProfileBuilder
:
- Java
@Override
public void onResponse(ProfileBuilder profileBuilder) {
// Customize ProfileBuilder for your merchant.
profileBuilder.setDisplayName("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
PurchaseInfoBuilder
object, passing in an amount and currency - Specify additional payment details on this object, e.g. description, subtotal, shipping
Here is an example:
- Java
PurchaseInfoBuilder purchaseInfoBuilder = new PurchaseInfoBuilder(
new BigDecimal("1.00"),
PurchaseInfo.Currency.USD
);
purchaseInfoBuilder.setDescription("My Description");
Tokenizing
- Create a
CheckoutButton
and add it to your layout. Make sure it is accessible in the Android code:
- Java
mVisaPaymentButton = (CheckoutButton) findViewById(R.is.visa_checkout_button);
- Tokenize the
VisaPaymentSummary
in thePAYMENT_SUCCESS
case
- Java
mVisaPaymentButton.init(VisaCheckoutActivity.this, profileBuilder.build(),
purchaseInfo.build(), new VisaCheckoutSdk.VisaCheckoutResultListener() {
@Override
public void onButtonClick(LaunchReadyHandler launchReadyHandler) {
launchReadyHandler.launch();
}
@Override
public void onResult(VisaPaymentSummary visaPaymentSummary) {
switch(visaPaymentSummary.getStatusName()) {
case VisaPaymentSummary.PAYMENT_CANCEL:
// The customer canceled the Visa Checkout flow
break;
case VisaPaymentSummary.PAYMENT_SUCCESS:
VisaCheckout.tokenize(mBraintreeFragment, visaPaymentSummary);
break;
case VisaPaymentSummary.PAYMENT_ERROR:
case VisaPaymentSummary.PAYMENT_FAILURE:
default:
// There was an issue processing Visa Checkout
break;
}
}
});
After tokenization has finished, Braintree SDK will call your PaymentMethodNonceCreatedListener
, with the resulting VisaCheckoutNonce
.
- Java
@Override
public void onPaymentMethodCreated(PaymentMethodNonce paymentMethodNonce) {
if (paymentMethodNonce instanceof VisaCheckoutNonce) {
// Access VisaCheckout properties from this object, e.g.
VisaCheckoutNonce visaCheckoutNonce = (VisaCheckoutNonce) paymentMethodNonce;
VisaCheckoutAddress shippingAddress = visaCheckoutNonce.getShippingAddress();
// Send this nonce to your server, and create a transaction there.
String nonce = visaCheckoutNonce.getNonce();
}
}
Next Page: Server-side →