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-applepay

v13.1.3

Published

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

Downloads

16

Readme

ApplePay for Braintree for Cordova

This is Cordova plugin extends the Cordova Purchase Plugin's Braintree Adapter to add Apple Pay support.

This plugin requires at least cordova-plugin-purchase-braintree of at least the same version number.

Installing

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

cordova plugin add cordova-plugin-purchase-braintree-applepay --variable APPLE_PAY_MERCHANT_ID=merchant.my.app.com

If unspecified, APPLE_PAY_MERCHANT_ID default value is merchant.$PACKAGE_NAME.

Usage

Initialization

Initialize the purchase plugin with the Braintree adapter enabled. It will detect that this extension is available and offer the Apple Pay payment option when possible.

You can customize it by passing additional options at initialization:

store.initialize([{
  platform: CdvPurchase.Platform.BRAINTREE,
  options: {
    applePay: {
      // Apple Pay would like to use the company name as a description for the payment total
      companyName: 'The Company, LLC'

      // Optionally, you can customize the full payment request.
      preparePaymentRequest: (request) => {
        // Return an ApplePay.PaymentRequest. For details see:
        // - https://github.com/j3k0/cordova-plugin-purchase/blob/master/api/interfaces/CdvPurchase.ApplePay.PaymentRequest.md
        // - https://developer.apple.com/documentation/passkit/pkpaymentrequest/ for details.
        return {
          merchantCapabilities: [CdvPurchase.ApplePay.MerchantCapability.EMV],
          shippingMethods = [{
            label: "Free Shipping",
            amount: "0.00",
            identifier: "free",
            detail: "Arrive by July 2"
          }, {
            label: "Standard Shipping",
            amount: "3.00",
            identifier: "standard",
            detail: "Arrive by June 29"
          }, {
            label: "Express Shipping",
            amount: "9.00",
            identifier: "express",
            detail: "Ships withing 24h"
          }],
          // see https://developer.apple.com/documentation/passkit/pkpaymentrequest/1619231-paymentsummaryitems
          paymentSummaryItems: [{
            amount: '1.50',
            label: 'Some item'
          }, {
            amount: '3.00',
            label: 'Some other item'
          }, {
            amount: '9.00',
            label: 'Express Shipping',
            type: 'pending'
          }, {
            amount: '-3.50',
            label: 'Discount'
          }, {
            // The last entry is the grand total
            amount: '10.00',
            label: 'Company, LLC',
            type: 'pending'
          }]
        }
      }
    }
  }
}];

For the full reference, see Braintree.AdapterOptions API for reference. You can do things like prefill the shipping or billing address, limit the available payment methods, limit the countries you accept payment from, etc.

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,
  productIds: ['my-product-1', 'my-product-2'], // Use anything, for reference
  amountMicros: 1990000,
  currency: 'USD',
  description: 'This this the description of the payment request',
}, {})
.failed(error => {
  // payment request failed
  showAlert(error.message);
})
.approved(transaction => {
  // payment request approved
})
.finished(transaction => {
  // payment finished
})
.cancelled(() => {
  // user cancelled by closing the dialog window
});

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.

Dynamically disable Apple Pay

You can choose to dynamically disable Apple Pay by passing applePayDisabled as show below to the store.requestPayment() function:

store.requestPayment({
  /* ... */
}, {
  braintree: {
    dropInRequest: {
      applePayDisabled: true,
    }
  }
});

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.