@nekenaraonimanana/cordova-plugin-purchase-braintree
v14.0.2
Published
Cordova Braintree adapter for cordova-plugin-purchase (iOS 7.x, Android SDK 5.x).
Maintainers
Readme
Braintree for Cordova
This is a Cordova plugin for the Braintree mobile payment processing SDK. It extends the Cordova Purchase Plugin to add Braintree support via native payment flows (card, PayPal, Venmo, Google Pay, 3DS).
This plugin requires cordova-plugin-purchase version 13 or newer (tested with 13.15.4).
Version 14.x requirements
| Platform | Minimum |
|----------|---------|
| cordova-android | 12+ |
| cordova-ios | 7+ |
| Android API | 23 (android-minSdkVersion) |
| iOS | 16.0 (deployment-target) |
| Xcode (iOS build) | 16.2+ |
Braintree SDK versions bundled or resolved by this plugin:
- iOS: braintree_ios 7.6.0 (downloaded on
cordova plugin addviascripts/iosBeforeInstall.js) - Android: braintree_android 5.27.0 modules (Maven)
See CHANGELOG.md for migration notes from 13.x.
Installing
From npm
cordova plugin add @nekenaraonimanana/[email protected]
cordova plugin add [email protected]See PUBLISHING.md to publish updates.
The Cordova plugin id remains cordova-plugin-purchase-braintree (see plugin.xml).
From git
cordova plugin add https://github.com/Nekena12345/cordova-plugin-purchase-braintree-renovo.git#master
cordova plugin add [email protected]Android — set minimum SDK in config.xml:
<platform name="android">
<preference name="android-minSdkVersion" value="23" />
</platform>iOS — set deployment target in config.xml:
<platform name="ios">
<preference name="deployment-target" value="16.0" />
</platform>On first install, the iOS hook downloads Braintree XCFrameworks into plugins/cordova-plugin-purchase-braintree/lib/ios (requires network access).
Usage
Initialization
When initializing the purchase plugin, add Platform.BRAINTREE at initialization.
CdvPurchase.store.initialize([{
platform: CdvPurchase.Platform.BRAINTREE,
options: { ... }
}]);The options object should contain:
- a
clientTokenProvideror atokenizationKeystring. - optional configuration options for Apple Pay, Google Pay and 3DSecure.
Client Token or Tokenization Key
Check the Braintree documentation to understand the difference.
clientTokenProvider is a function that takes a callback as a parameter, this callback will accept either:
- a
string: the Client Token - a
CdvPurchase.IErrorobject ({isError: true, code: ErrorNumber, message: string}).
The CdvPurchase.Iaptic object contains the implementation of a client token provider. If you are using https://www.iaptic.com:
const iaptic = new CdvPurchase.Iaptic({
url: 'https://validator.iaptic.com', appName: 'MY_APP_NAME', apiKey: 'MY_PUBLIC_KEY',
});
store.initialize([Platform.APPLE_APPSTORE, Platform.GOOGLE_PLAY, {
platform: Platform.BRAINTREE,
options: {
clientTokenProvider: iaptic.braintreeClientTokenProvider
}
}]);tokenizationKey is just a string.
Making a purchase
Use the store.requestPayment() method to initiate a payment with Braintree.
amountMicrosandcurrencyare required.- If
result.isErroris set, the returned value is an error.- Check
result.code,PAYMENT_CANCELLEDmeans the user closed the modal window.
- Check
store.requestPayment({
platform: CdvPurchase.Platform.BRAINTREE,
email: GetEmailAddress(),
items: [{
id: 'item_id',
title: 'An Item',
pricing: {
priceMicros: 11 * 1000000,
currency: 'USD',
}
}],
description: 'An item delivered before Christmas',
})
.cancelled(() => {})
.failed(error => {})
.approved(transaction => {})
.finished(transaction => {});The native layer presents a custom payment sheet (not the deprecated Braintree Drop-In SDK). The JavaScript contract (launchDropIn result shape) is unchanged for cordova-plugin-purchase compatibility.
3DSecure
Add threeDSecure into the platform options. See ThreeDSecure.Request.
Google Pay
Add googlePay into the platform options (Android). See GooglePay.Request.
Apple Pay
The cordova-plugin-purchase-braintree-applepay extension adds Apple Pay through Braintree.
Testing
Manual QA checklist: TEST_MATRIX.md.
Integration notes with cordova-plugin-purchase: INTEGRATION.md.
Licence
The MIT License — see LICENSE.
