npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-purchase-braintree

v13.2.4

Published

A Cordova plugin for the Braintree mobile payment processing SDK with 3D secure and Data Collecting.

Downloads

13

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 using the Braintree DropIn interface.

This plugin requires at least cordova-plugin-purchase version 13.

Installing

The plugin identifier is cordova-plugin-purchase-braintree. Here's how to adding it to your app with the cordova CLI:

cordova plugin add cordova-plugin-purchase-braintree

For Android, you have to make sure the minSdkVersion is at least 21 in your app's config.xml file. To do so, add (or update) the preference tag for the android platform as below:

<platform name="android">
    <preference name="android-minSdkVersion" value="21" />
</platform>

For iOS, the minimum deployment target for the Braintree SDK is iOS 12.0, to set this up, add (or update) the preference tag for the ios platform like so:

<platform name="ios">
    <preference name="deployment-target" value="12.0" />
</platform>

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 clientTokenProvider or a tokenizationKey string.
  • 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.IError object ({isError: true, code: ErrorNumber, message: string}).

The CdvPurchase.Iaptic object contains the implementation of a client token provider. So you if you are using https://www.iaptic.com, you can do:

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: {
        // using iaptic's built-in braintree client token provider
        clientTokenProvider: iaptic.braintreeClientTokenProvider
    }
}]);

tokenizationKey is just a string.

Making a purchase

Use the store.requestPayment() method to initiate a payment with Braintree.

  • amountMicros and currency are required.
  • If result.isError is set, the returned value is an error.
    • Check result.code, PAYMENT_CANCELLED means the user closed the modal window.
    • Other error codes means something went wrong.
store.requestPayment({
  platform: CdvPurchase.Platform.BRAINTREE,
  email: GetEmailAddress(),
  items: [{
    id: 'item_id',
    title: 'An Item',
    pricing: { // 11 USD
        priceMicros: 11 * 1000000,
        currency: 'USD',
    }
  }],
  description: 'An item delivered before Christmas',
})
.cancelled(() => {
  // request cancelled by user
})
.failed(error => {
  // request failed
})
.initiated(transaction => {
  // transaction initiated
})
.approved(transaction => {
  // transaction initiated
})
.finished(transaction => {
  // transaction finished
});

Once the client gets the initial approval, the "approved" event is triggered. It's the job of the receipt validation service to create and submit a transaction to Braintree.

Once again, iaptic has built-in support for Braintree, so this part is already covered if your app is integrated with Iaptic. If now, implement the server side call using values provided by the receipt validation call.

3DSecure

To enable 3DSecure, you have to add threeDSecure into the platform options.

Example:

{
  platform: Platform.BRAINTREE,
  options: {
    // ...
    threeDSecure: {
      exemptionRequested: true
    }
  }
}

It can also be an empty object if you don't have any specific options to set. The list of accepted options is documented here: ThreeDSecure.Request.

Those options will be merged into all Braintree payment requests. They can be overloaded by adding threeDSecureRequest in the payment request' additional data, for example:

CdvPurchase.store.requestPayment({
    platform: CdvPurchase.Platform.BRAINTREE,
    items: [/* */],
    email: GetEmailAddress(),
}, {
  braintree: {
    threeDSecureRequest: {
      exemptionRequested: false
    }
  }
});

threeDSecureRequest is of the same type: a ThreeDSecure.Request object.

Google Pay

To enable Google Pay, you have to add googlePay into the platform options.

Example:

{
  platform: Platform.BRAINTREE,
  options: {
    // ...
    googlePay: {
      countryCode: 'US',
      googleMerchantName: 'My Merchant Name',
      environment: 'TEST'
    },
  }
}

The list of accepted options is documented here: GooglePay.Request.

Those options will be merged into all Braintree payment requests. As with 3DSecure, those options can be overloaded by adding googlePayRequest into the payment request's additional data, for example.

CdvPurchase.store.requestPayment({
    platform: CdvPurchase.Platform.BRAINTREE,
    items: [/* */],
}, {
  braintree: {
    googlePayRequest: {
      shippingAddressRequired: true,
    },
  }
});

Apple Pay

The cordova-plugin-purchase-braintree-applepay plugin is an extension that enables support for Apple. By installing this plugin, you can add support for Apple Pay to your Cordova app, through Braintree.

Documentation related to Apple Pay can be found in that repository.

Notes

Crash on iOS with Braintree SDK 5.16.0

Running on device, the app crashes with:

Termination Description: DYLD, Library not loaded: @rpath/PPRiskMagnes.framework/PPRiskMagnes
Referenced from: /private/var/containers/Bundle/Application/E39026F3-50D7-4A92-AEA0-CFE6564973E4/Minimum Template.app/Frameworks/PayPalDataCollector.framework/PayPalDataCollector
Reason: image not found

Notice that this is a release related with the PPRiskMagnes library: see Release Notes for 5.16.0

This might be interesting: https://github.com/braintree/braintree_ios/issues/735

It works with 5.15.0.

Licence

The MIT License

Copyright (c) 2022, Jean-Christophe Hoelt and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.