All Projects → Cretezy → braintree-web-drop-in-react

Cretezy / braintree-web-drop-in-react

Licence: MIT license
React component for Braintree Web Drop-In (v3)

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to braintree-web-drop-in-react

solidus braintree
Braintree v.zero support for solidus
Stars: ✭ 19 (-72.46%)
Mutual labels:  braintree
Lynnhosting
Open Source, Web Hosting Automation built with Laravel
Stars: ✭ 36 (-47.83%)
Mutual labels:  braintree
Braintree dotnet
Braintree .NET library
Stars: ✭ 109 (+57.97%)
Mutual labels:  braintree
Braintree android
Braintree SDK for Android
Stars: ✭ 343 (+397.1%)
Mutual labels:  braintree
Django Payments
Universal payment handling for Django.
Stars: ✭ 575 (+733.33%)
Mutual labels:  braintree
React Native Paypal
React Native library that implements PayPal Checkout flow using purely native code
Stars: ✭ 70 (+1.45%)
Mutual labels:  braintree
graphql-api
Schemas, changelogs and feature requests for Braintree's GraphQL API
Stars: ✭ 39 (-43.48%)
Mutual labels:  braintree
Test Payment Cards
Cheatsheet of test payment cards for various payment gateways
Stars: ✭ 217 (+214.49%)
Mutual labels:  braintree
Pay
Payments for Ruby on Rails apps
Stars: ✭ 759 (+1000%)
Mutual labels:  braintree
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (+53.62%)
Mutual labels:  braintree
Braintree Web
A suite of tools for integrating Braintree in the browser
Stars: ✭ 357 (+417.39%)
Mutual labels:  braintree
Braintree php
Braintree PHP library
Stars: ✭ 491 (+611.59%)
Mutual labels:  braintree
Braintree Android Drop In
Braintree Drop-In SDK for Android
Stars: ✭ 78 (+13.04%)
Mutual labels:  braintree
Braintree node
Braintree Node.js library
Stars: ✭ 271 (+292.75%)
Mutual labels:  braintree
Braintree java
Braintree Java library
Stars: ✭ 129 (+86.96%)
Mutual labels:  braintree
OpenBook-E-Commerce
An e-commerce progressive web application, built with mern stack. It has features like product buy, order management by admin, payment gateway, cart, checkout and lot more.
Stars: ✭ 53 (-23.19%)
Mutual labels:  braintree
Nestjs Braintree
A module for braintree reoccurring payments and transactions 💳
Stars: ✭ 62 (-10.14%)
Mutual labels:  braintree
Braintree python
Braintree Python library
Stars: ✭ 217 (+214.49%)
Mutual labels:  braintree
Spree gateway
Huge collection of payment gateways for @spree. Stripe, Braintree, Apple Pay, Authorize.net and many others!
Stars: ✭ 180 (+160.87%)
Mutual labels:  braintree
Braintree Elixir
💳 Native elixir client for Braintree
Stars: ✭ 86 (+24.64%)
Mutual labels:  braintree

Braintree Web Drop-in React Build Status npm version

This is a React component that wraps braintree-web-drop-in (v3). braintree-web-drop-in-react example

Disclaimer: this is not an official Braintree module.

For issues and information concerning braintree-web-drop-in or braintree-web in general, please see braintree/braintree-web-drop-in and braintree/braintree-web.

Install

yarn add braintree-web-drop-in-react
# or
npm install braintree-web-drop-in-react

Drop-In

Complete example

import React from "react";
import DropIn from "braintree-web-drop-in-react";

class Store extends React.Component {
  instance;

  state = {
    clientToken: null,
  };

  async componentDidMount() {
    // Get a client token for authorization from your server
    const response = await fetch("server.test/client_token");
    const clientToken = await response.json(); // If returned as JSON string

    this.setState({
      clientToken,
    });
  }

  async buy() {
    // Send the nonce to your server
    const { nonce } = await this.instance.requestPaymentMethod();
    await fetch(`server.test/purchase/${nonce}`);
  }

  render() {
    if (!this.state.clientToken) {
      return (
        <div>
          <h1>Loading...</h1>
        </div>
      );
    } else {
      return (
        <div>
          <DropIn
            options={{ authorization: this.state.clientToken }}
            onInstance={(instance) => (this.instance = instance)}
          />
          <button onClick={this.buy.bind(this)}>Buy</button>
        </div>
      );
    }
  }
}

Basic example

See example.

Props

options (object, required)

Options to setup Braintree. See Drop-In options.

onInstance (function: instance, optional)

Called with the Braintree Drop-In instance when done initializing. You can call all regular Drop-In methods

The on events are already listened to using onNoPaymentMethodRequestable, onPaymentMethodRequestable, onPaymentOptionSelected. See below.

instance.requestPaymentMethod([callback]): [Promise]

Requests a payment method object which includes the payment method nonce used by by the Braintree Server SDKs. The structure of this payment method object varies by type: a cardPaymentMethodPayload is returned when the payment method is a card, a paypalPaymentMethodPayload is returned when the payment method is a PayPal account.

If a payment method is not available, an error will appear in the UI. When a callback is used, an error will be passed to it. If no callback is used, the returned Promise will be rejected with an error.

Returns a Promise if no callback is provided.

instance.clearSelectedPaymentMethod(): void

Removes the currently selected payment method and returns the customer to the payment options view. Does not remove vaulted payment methods.

instance.isPaymentMethodRequestable(): boolean

Returns a boolean indicating if a payment method is available through requestPaymentMethod. Particularly useful for detecting if using a client token with a customer ID to show vaulted payment methods.

instance.updateConfiguration(property, key, value): void

Modify your configuration initially set in options. Can be used for any paypal or paypalCredit property.

If updateConfiguration is called after a user completes the PayPal authorization flow, any PayPal accounts not stored in the Vault record will be removed.

onError (function: error, optional)

Called when creating the instance throws an error.

Note: This doesn't propage up to React's error bounderies. If this is the desired behavior, rethrow the error inside your onError handler

onNoPaymentMethodRequestable, onPaymentMethodRequestable, onPaymentOptionSelected (function: void/payload, optional)

Ran for events.

preselectVaultedPaymentMethod (boolean, default: true)

Whether to initialize with a vaulted payment method pre-selected. Only applicable when using a client token with a customer with saved payment methods.

Note: This prop is deprecated and will be removed in v2. Simply place this prop inside your options instead.

Package size

Since this depends on braintree-web-drop-in, this can be a quite large package (324.5 kB minified). This package alone is only ~3 kB.

To avoid loading all this code when not used, it is strongly recommended to dynamically import it using import(). Using @loadable/component or react-loadable can make this quite simple.

This is an maintainted and updated rewrite of jeffcarp/braintree-react.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].