Coder Social home page Coder Social logo

charistheo / react-google-pay-button Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 2.0 2 MB

⛔️ [DEPRECATED] A React Google Pay button component for the web

Home Page: https://www.charistheo.io/react-google-pay-button/

HTML 8.47% JavaScript 88.17% CSS 3.36%
react reactjs google-pay react-button google-payment web-payments payment-integration payment

react-google-pay-button's Introduction

⚠️ This package has been deprecated in favor of https://github.com/google-pay/google-pay-button/tree/main/src/button-react


Google Pay React unofficial logo

react-google-pay-button

A React Google Pay button component for the web.

NPM JavaScript Style Guide

Googe Pay Button API

Make sure you have read and understood the official docs before implementing

Object Reference Docs

Google Developers Tutorial

Install

npm install --save react-google-pay-button

Usage

Development example

class Example extends Component {
  render () {
    return (
      <GPayButton
        totalPriceStatus={'FINAL'}
        totalPrice={'14.45'}
        currencyCode={'GBP'}
        countryCode={'GB'}
        development={true}
      />
    )
  }
}

Production example

To get a merchantId, follow this checklist

import React, { Component } from 'react'

import GPayButton from 'react-google-pay-button'

// allowed user payment methods 💰
const paymentMethods = [
  {
    type: 'CARD',
    parameters: {
      allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
      allowedCardNetworks: ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA']
    },
    tokenizationSpecification: {
      type: 'PAYMENT_GATEWAY',
      parameters: {
        'gateway': 'stripe',
        'stripe:version': '2019-03-14',
        'stripe:publishableKey': '<YOUR_PUBLIC_STRIPE_KEY>'
      }
    }
  },
  {
    type: 'PAYPAL',
    parameters: {
      'purchase_context': {
        'purchase_units': [{
          'payee': {
            'merchant_id': '<YOUR PAYPAL_ACCOUNT_ID>'
          }
        }]
      }
    },
    tokenizationSpecification: {
      type: 'DIRECT'
    }
  }
]

class Example extends Component {
  loadPaymentDataHandler = paymentData => {
    const paymentToken = paymentData.paymentMethodData.tokenizationData.token
  }

  render () {
    return (
      <GPayButton
        totalPriceStatus={'FINAL'}
        totalPrice={'14.45'}
        currencyCode={'GBP'}
        countryCode={'GB'}
        allowedPaymentMethods={paymentMethods}
        development={true}
        merchantInfo={{
          merchantName: '<YOUR MERCHANT NAME>',
          // A Google merchant identifier issued after your website is approved by Google ✅
          merchantId: '<YOUR MERCHANT ID>'
        }}
        onLoadPaymentData={this.loadPaymentDataHandler}
      />
    )
  }
}

Props

Prop Type default value
style object For wrapper div element
className string For wrapper div element
development boolean false
color string 'black'
type string 'long'
apiVersion number 2
apiVersionMinor number 0
currencyCode string required
totalPriceStatus string required
tokenizationSpecification object required
countryCode string required for merchants based in EEA countries
totalPrice string | number required unless totalPriceStatus is set to NOT_CURRENTLY_KNOWN
merchantInfo object merchantId is required in production
allowedPaymentMethods PaymentMethod optional (default)
displayItems DisplayItem[] optional
totalPriceLabel string optional
checkoutOption string optional
onLoadPaymentData function optional
onPaymentAuthorized function optional
onPaymentDataChanged function optional
onUserCanceled function optional

allowedPaymentMethods

Default value

[
  {
    type: 'CARD',
    parameters: {
      allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
      allowedCardNetworks: ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA']
    },
    tokenizationSpecification: {
      type: 'PAYMENT_GATEWAY',
      parameters: {
        gateway: 'example',
        gatewayMerchantId: 'exampleGatewayMerchantId'
      }
    }
  }
]

react-google-pay-button's People

Contributors

charistheo avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dnna yong-ling

react-google-pay-button's Issues

Google Pay API V1

Hello. How I can use GPay Api v1. My provider uses API version 1. Your component fails to pay and reports the error 'cardRequirements' is missing!'. The documentation says that in addition to allowedPaymentMethods, you must specify cardRequirements. How can I pass this parameter?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.