All Projects → erksch → react-smart-payment-buttons

erksch / react-smart-payment-buttons

Licence: other
React integration for PayPal Smart Payment Buttons

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-smart-payment-buttons

Paypal Checkout Components
Javascript Integration for PayPal Button and PayPal Checkout
Stars: ✭ 938 (+5111.11%)
Mutual labels:  paypal, payments
Django Payments
Universal payment handling for Django.
Stars: ✭ 575 (+3094.44%)
Mutual labels:  paypal, payments
Digota
ecommerce microservice
Stars: ✭ 382 (+2022.22%)
Mutual labels:  paypal, payments
Dj Paypal
Paypal integration for Django - Inspired by Dj-Stripe
Stars: ✭ 55 (+205.56%)
Mutual labels:  paypal, payments
react-recurly
React components for Recurly.js
Stars: ✭ 38 (+111.11%)
Mutual labels:  payments
mangopay2-java-sdk
Java SDK for MANGOPAY
Stars: ✭ 23 (+27.78%)
Mutual labels:  payments
crowdfunding-backend
[DEPRECATED] A crowdfunding backend written with NodeJS, Apollo and PostgreSQL. Features an extensive data model, mult. payment integrations, passwordless auth, statistics and admin endpoints.
Stars: ✭ 23 (+27.78%)
Mutual labels:  paypal
mangopay2-python-sdk
SDK Python for MANGOPAY
Stars: ✭ 31 (+72.22%)
Mutual labels:  payments
XLsn0wPay
XLsn0w WeChat And Alipay SDK Pay Manager 微信支付SDK/支付宝SDK/银联支付/Paypal支付 接入指南(一键支付管理工具类)
Stars: ✭ 31 (+72.22%)
Mutual labels:  paypal
saasform
Add signup & payments to your SaaS in minutes.
Stars: ✭ 247 (+1272.22%)
Mutual labels:  payments
Cartkit
Cartkit - The [quick] starter kit!
Stars: ✭ 39 (+116.67%)
Mutual labels:  paypal
mpesa-rest-api
mpesa rest api converts the mpesa api to a RESTful API that is easy for developers to use instead of the current SOAP web service provided by mpesa.
Stars: ✭ 24 (+33.33%)
Mutual labels:  payments
mobimoney
Cross-platform mobile payments project for React Native
Stars: ✭ 14 (-22.22%)
Mutual labels:  payments
procesa-pagos-con-laravel
Código fuente resultado del curso "Procesa pagos con Laravel y las mejores plataformas de pagos"
Stars: ✭ 38 (+111.11%)
Mutual labels:  paypal
awesome-pix
Awesome PIX
Stars: ✭ 127 (+605.56%)
Mutual labels:  payments
Product-Site-101
Simple product site - demo for a talk
Stars: ✭ 33 (+83.33%)
Mutual labels:  payments
paymentgateway
Dokumentace ČSOB platební brány a jejího eAPI pro platby platebními kartami, Apple Pay, mallpay a platebními tlačítky ČSOB.
Stars: ✭ 104 (+477.78%)
Mutual labels:  payments
Nest-Js-Boiler-Plate
Nest Js Boilerplate with JWT authentication, CRUD functions and payment gateways.
Stars: ✭ 14 (-22.22%)
Mutual labels:  paypal
adyen-dotnet-api-library
Adyen API Library for .NET
Stars: ✭ 69 (+283.33%)
Mutual labels:  payments
card-validator
Card validation helpers for payment forms.
Stars: ✭ 22 (+22.22%)
Mutual labels:  payments

react-smart-payment-buttons

CircleCI Coverage Status npm package npm downloads

A react integration for PayPal's Smart Payment Buttons.

Installation

Install with npm

npm install --save react-smart-payment-buttons

Install with yarn

yarn add react-smart-payment-buttons

Usage

For the buttons to load, the PayPal JavaScript SDK needs to be globally available.

You can achieve this in two ways:

Load the PayPal SDK with a script tag

<script src="https://www.paypal.com/sdk/js?client-id=CLIENT_ID"></script>

Then you are able to use the SmartPaymentButtons component where ever you want:

import SmartPaymentButtons from 'react-smart-payment-buttons';

function MyCheckout() {
  return (
    <div>
      <h1>Checkout</h1>
      <SmartPaymentButtons
        createOrder={...}
        onApprove={...}
      />
    </div>
  );
}

Alternatively, you can also load the script asynchronously:

<script id="paypal-sdk" src="https://www.paypal.com/sdk/js?client-id=CLIENT_ID" async></script>

Now you can tell SmartPaymentButtons to wait until the SDK is loaded by providing the sdkScriptId you chose earlier:

<SmartPaymentButtons
  sdkScriptId="paypal-sdk"
  loading={<Spinner />} // optional
  createOrder={...}
  onApprove={...}
/>

You can add an optional loading prop to display something until the buttons are displayed.

Making the <script> asynchronous is a highly recommend because it reduces the load time of your application.

Alternative: Use the built in PayPalSDKWrapper component

import SmartPaymentButtons, { PayPalSDKWrapper } from 'react-smart-payment-buttons';

function MyCheckout() {
  return (
    <div>
      <h1>Checkout</h1>
      <PayPalSDKWrapper clientId="CLIENT_ID">
        <SmartPaymentButtons
          createOrder={...}
          onApprove={...}
        />
      </PayPalSDKWrapper>
    </div>
  );
}

As you can see, with this option you don't need to the import the script.

This option also reduces the load time of your application like the async script. A second benefit is that the PayPal SDK is only loaded when it's needed: Users who are entering your website may not want to immediatly download a PayPal SDK. By using the wrapper you are able to defer loading the SDK for example to when the users enters the checkout page.

Instead of using the clientId prop you can also create an environment variable REACT_APP_PAYPAL_CLIENT_ID (for create-react-app usage) that contains the id. The PayPalSDKWrapper will pick it up automatically.

Display a loading indicator

It can take a second to load the script with the PayPalSDKWrapper. But you can attach some custom loading that you wan't to display while waiting for the script to load by using the loading property of the PayPalSDKWrapper component.

return (
  <PayPalSDKWrapper
    clientId="CLIENT_ID"
    loading={<Spinner />}
  >
    <SmartPaymentButtons
      createOrder={...}
      onApprove={...}
    />
  </PayPalSDKWrapper>
);

Props

SmartPaymentButtons component

Name Type Description (PayPal Docs Link)
createOrder (data, actions) => any See createOrder
onApprove (data, actions) => any See onApprove
onCancel (data) => any See onCancel
onError (error) => any See onError
style Object See customization
containerStyle React StyleSheet Object Style applied to the button's container
containerClassName string CSS class applied to the button's container
refresh mixed If this value changes the buttons are rerendered
sdkScriptId string ID of the script tag loading the PayPal SDK asynchronously
loading React Node Only works with sdkScriptId. Is displayed until the SDK is loaded.

PayPalSDKWrapper component

The component accepts all parameters the SDK accepts. See the official Customize SDK documentation for reference.

Attention

  • The PayPalSDKWrapper expects the props to be in camelCase instead of kebab-case like the SDK parameters.

  • The SDK parameters that take a comma separated list like disable-funding=card,sepa have to be assigned with an array in the props like disableFunding={['card', 'sepa']}.

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].