All Projects → paypal → React Paypal Js

paypal / React Paypal Js

Licence: apache-2.0
React components for the PayPal JS SDK

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Paypal Js

Braintree ios
Braintree SDK for iOS
Stars: ✭ 469 (+322.52%)
Mutual labels:  paypal
Paypalexpresscheckoutnvp
[READ-ONLY] Subtree split of the Payum PaypalExpressCheckoutNvp Component -- clone into Payum/Paypal/ExpressCheckout/Nvp/ (master at payum/payum)
Stars: ✭ 35 (-68.47%)
Mutual labels:  paypal
Black.box
Plug-and-Play VPN router and unblocker
Stars: ✭ 89 (-19.82%)
Mutual labels:  paypal
Django Payments
Universal payment handling for Django.
Stars: ✭ 575 (+418.02%)
Mutual labels:  paypal
Paypal Checkout Components
Javascript Integration for PayPal Button and PayPal Checkout
Stars: ✭ 938 (+745.05%)
Mutual labels:  paypal
Payment
支付宝支付、银联支付、微信支付、paypal、苹果内购支付
Stars: ✭ 48 (-56.76%)
Mutual labels:  paypal
Digota
ecommerce microservice
Stars: ✭ 382 (+244.14%)
Mutual labels:  paypal
Django Shop Tutorial
Use Django To Create A Simple Shopping Site Tutorial
Stars: ✭ 109 (-1.8%)
Mutual labels:  paypal
Duranius Paypal Rest Api Php Library
If you need to integrate your website with PayPal REST API, then all you need is to download this library and you are ready to go. There are only two files you need to download and import to your project.
Stars: ✭ 13 (-88.29%)
Mutual labels:  paypal
Doorstep
The powerful e-commerce solution for Python
Stars: ✭ 88 (-20.72%)
Mutual labels:  paypal
Django Paypal
A pluggable Django application for integrating PayPal Payments Standard or Payments Pro
Stars: ✭ 602 (+442.34%)
Mutual labels:  paypal
Nopcommerce
The most popular open-source eCommerce shopping cart solution based on ASP.NET Core
Stars: ✭ 6,827 (+6050.45%)
Mutual labels:  paypal
Dj Paypal
Paypal integration for Django - Inspired by Dj-Stripe
Stars: ✭ 55 (-50.45%)
Mutual labels:  paypal
Qrpay
五合一收款码在线生成,40个模板 支持微信支付、支付宝支付、手机QQ支付、京东钱包、百度钱包,PayPal五合一收款,将其二维码合并为一个二维码,无需手续费,支持qq头像,昵称判断(HTML单页版多模板免安装) 腾讯云服务器 https://api.isoyu.com/qrpay/ 腾讯云COS https://qrpay.isoyu.com/
Stars: ✭ 477 (+329.73%)
Mutual labels:  paypal
Payumserver
Payment processing microservice. Written in Symfony4
Stars: ✭ 103 (-7.21%)
Mutual labels:  paypal
Blacklist
Blacklist and Adware Blocking for the Ubiquiti EdgeMax Router
Stars: ✭ 393 (+254.05%)
Mutual labels:  paypal
React Native Paypal
PayPal clone with React Native
Stars: ✭ 47 (-57.66%)
Mutual labels:  paypal
Django Oscar Paypal
PayPal integration for django-oscar. Can be used without Oscar too.
Stars: ✭ 112 (+0.9%)
Mutual labels:  paypal
Invoice As A Service
💰 Simple invoicing service (REST API): from JSON to PDF
Stars: ✭ 106 (-4.5%)
Mutual labels:  paypal
React Native Paypal
React Native library that implements PayPal Checkout flow using purely native code
Stars: ✭ 70 (-36.94%)
Mutual labels:  paypal

react-paypal-js

React components for the PayPal JS SDK

build status coverage npm version npm downloads apache license storybook

Why use react-paypal-js?

The Problem

Developers integrating with PayPal are expected to add the JS SDK <script> to a website and then render components like the PayPal Buttons after the script loads. This architecture works great for simple websites but can be challenging when building single page apps.

React developers think in terms of components and not about loading external scripts from an index.html file. It's easy to end up with a React PayPal integration that's sub-optimal and hurts the buyer's user experience. For example, abstracting away all the implementation details of the PayPal Buttons into a single React component is an anti-pattern because it tightly couples script loading with rendering. It's also problematic when you need to render multiple different PayPal components that share the same global script parameters.

The Solution

react-paypal-js provides a solution to developers to abstract away complexities around loading the JS SDK. It enforces best practices by default so buyers get the best possible user experience.

Features

  • Enforce async loading the JS SDK up front so when it's time to render the buttons to your buyer, they render immediately.
  • Abstract away the complexity around loading the JS SDK with the global <PayPalScriptProvider> component.
  • Support dispatching actions to reload the JS SDK and re-render components when global parameters like currency change.
  • Easy to use components for all the different PayPal product offerings:

Installation

To get started, install react-paypal-js with npm.

npm install @paypal/react-paypal-js

Usage

This PayPal React library consists of two main parts:

  1. Context Provider - this <PayPalScriptProvider /> component manages loading the JS SDK script. Add it to the root of your React app. It uses the Context API for managing state and communicating to child components. It also supports reloading the script when parameters change.
  2. SDK Components - components like <PayPalButtons /> are used to render the UI for PayPal products served by the JS SDK.
// App.js
import { PayPalScriptProvider, PayPalButtons } from "@paypal/react-paypal-js";

export default function App() {
    return (
        <PayPalScriptProvider options={{ "client-id": "test" }}>
            <PayPalButtons style={{ layout: "horizontal" }} />
        </PayPalScriptProvider>
    );
}

PayPalButtons

The <PayPalButtons /> component is fully documented in Storybook. Checkout the docs page for the PayPalButtons to learn more about the available props.

PayPalScriptProvider

Use the PayPalScriptProvider options prop to configure the JS SDK. It accepts an object for passing query parameters and data attributes to the JS SDK script.

const initialOptions = {
    "client-id": "test",
    currency: "USD",
    intent: "capture",
    "data-client-token": "abc123xyz==",
};
<PayPalScriptProvider options={initialOptions}>
    <PayPalButtons />
</PayPalScriptProvider>;

The JS SDK Configuration guide contains the full list of query parameters and data attributes that can be used with the JS SDK.

The <PayPalScriptProvider /> component is designed to be used with the usePayPalScriptReducer hook for managing global state. This usePayPalScriptReducer hook has the same API as React's useReducer hook.

Tracking loading state

The usePayPalScriptReducer hook provides an easy way to tap into the loading state of the JS SDK script. This state can be used to show a loading spinner while the script loads or an error message if it fails to load. The following derived attributes are provided for tracking this loading state:

  • isPending - not finished loading (default state)
  • isResolved - successfully loaded
  • isRejected - failed to load

For example, here's how you can use it to show a loading spinner.

const [{ isPending }] = usePayPalScriptReducer();

return (
    <>
        {isPending ? <div className="spinner" /> : null}
        <PayPalButtons />
    </>
);

To learn more, check out the loading spinner example in storybook.

Reloading when parameters change

The usePayPalScriptReducer hook can be used to reload the JS SDK script when parameters like currency change. It provides the action resetOptions for reloading with new parameters. For example, here's how you can use it to change currency.

// get the state for the sdk script and the dispatch method
const [{ options }, dispatch] = usePayPalScriptReducer();
const [currency, setCurrency] = useState(options.currency);

function onCurrencyChange({ target: { value } }) {
    setCurrency(value);
    dispatch({
        type: "resetOptions",
        value: {
            ...scriptProviderOptions,
            currency: value,
        },
    });
}

return (
    <>
        <select value={currency} onChange={onCurrencyChange}>
            <option value="USD">United States dollar</option>
            <option value="EUR">Euro</option>
        </select>
        <PayPalButtons />
    </>
);

To learn more, check out the dynamic currency example in storybook.

Browser Support

This library supports all popular browsers, including IE 11. It provides the same browser support as the JS SDK. Here's the full list of supported browsers.

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