paypal-checkout-components
please submit Issues about the PayPal JS SDK here: https://github.com/paypal/paypal-js/issues
Quick Overview
The PayPal Checkout Components repository is a collection of reusable UI components for integrating PayPal's checkout experience into web applications. It provides a set of customizable and extensible components that allow developers to easily add PayPal's payment options to their websites or applications.
Pros
- Comprehensive Functionality: The repository offers a wide range of payment-related components, including the PayPal button, Smart Payment Buttons, and Hosted Fields, catering to various payment integration needs.
- Customizability: The components are highly customizable, allowing developers to adjust the appearance and behavior to match the branding and design of their application.
- Cross-browser Compatibility: The components are designed to work seamlessly across a wide range of modern web browsers, ensuring a consistent user experience.
- Active Development and Support: The project is actively maintained by the PayPal team, with regular updates and improvements to address evolving payment requirements and security concerns.
Cons
- Steep Learning Curve: Integrating the PayPal Checkout Components may require a significant amount of time and effort, especially for developers who are new to the PayPal ecosystem.
- Dependency on PayPal: The components are tightly coupled with the PayPal platform, which means that developers are reliant on the availability and stability of the PayPal services.
- Limited Flexibility: While the components are customizable, there may be limitations in terms of the level of customization that can be achieved, particularly for more complex or unique payment flows.
- Performance Considerations: The inclusion of the PayPal Checkout Components may impact the overall performance of the web application, especially on slower network connections or older devices.
Code Examples
Here are a few code examples demonstrating the usage of the PayPal Checkout Components:
Rendering the PayPal Button
import { PayPalButtons } from '@paypal/react-paypal-js';
function PayPalCheckout() {
return (
<PayPalButtons
createOrder={(data, actions) => {
return actions.order.create({
purchase_units: [
{
amount: {
value: '0.01',
},
},
],
});
}}
onApprove={(data, actions) => {
return actions.order.capture().then((details) => {
alert(`Transaction completed by ${details.payer.name.given_name}!`);
});
}}
/>
);
}
Integrating Hosted Fields
import { useHostedFields } from '@paypal/react-paypal-js';
function HostedFieldsExample() {
const { initializeHostedFields, hostedFieldsInstance } = useHostedFields({
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [
{
amount: {
value: '0.01',
},
},
],
});
},
onApprove: (data, actions) => {
return actions.order.capture().then((details) => {
alert(`Transaction completed by ${details.payer.name.given_name}!`);
});
},
});
return (
<div>
<button onClick={initializeHostedFields}>Initialize Hosted Fields</button>
<div id="hosted-fields-container">
<label htmlFor="card-number">Card Number</label>
<div id="card-number"></div>
<label htmlFor="expiration-date">Expiration Date</label>
<div id="expiration-date"></div>
<label htmlFor="cvv">CVV</label>
<div id="cvv"></div>
</div>
</div>
);
}
Getting Started
To get started with the PayPal Checkout Components, follow these steps:
- Install the required dependencies:
npm install @paypal/react-paypal-js
- Import the necessary components and initialize the PayPal SDK:
import { PayPalScriptProvider, PayPalButtons } from '@paypal/react-paypal-js';
function
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
PayPal Checkout
A set of components allowing easy integration of PayPal Buttons and PayPal Checkout into your site, powered by zoid.
Dev Docs
See developer.paypal.com/docs/checkout
Issues
Please submit any issues about the JS SDK here: https://github.com/paypal/paypal-js/issues
Development
Please feel free to follow the Contribution Guidelines to contribute to this repository. PRs are welcome, but for major changes please raise an issue first.
Quick Setup
Set up your env:
npm install
Run tests:
npm test
Run in dev mode:
npm run dev
Testing Tasks
npm test
Runs all testing tasks lint
, flow
, karma
, jest-ssr
, jest-screenshot
, & check-size
.
Flags | Description |
---|---|
--clear-cache | Clear Babel Loader and PhantomJS cache |
--debug | Debug mode. PhantomJS, Karma, and CheckoutJS |
--quick | Fastest testing. Minimal output, no coverage |
--browser | Choose Browser |
lint
npm run lint
npm run lint -- --fix
# attempt to automatically fix any problems
Runs eslint using definitions extended from Grumbler-Scripts.
flow
npm run flow
Checks for typing issues using Flow. Prior to running this task, flow-typed
should be run to generate type interfaces for the various 3rd-party libraries we use.
karma
npm run karma
npm run karma -- --keep-open
# keeps the test browser window open to allow debugging
npm run karma -- --capture-console
# dumps the browser's console output into the terminal
Runs Karma tests using the Mocha framework. Responsible for running the test/e2e & test/integration directories.
jest-ssr
npm run jest-ssr
Checks for the correct rendering of components on the server-side using Jest.
jest-screenshot
npm run jest-screenshot
Uses Puppeteer & Jest to take screenshots and checks against existing views to look for discrepancies. Tests are defined in test/screenshot/config.js.
check-size
npm run check-size
Checks to make sure that the compiled & gzipped bundle doesn't exceed the recommended size limit.
Releasing
This package is published weekly, Every Wednesday. Please view our Changelog to stay updated with bug fixes and new features.
Logo Strategy with paypal-sdk-logos
Our usage of svg logos is optimized for performance. Here's how it works for the two-phased render for the Buttons component:
-
First Render - Buttons are first rendered on the client-side inside an
<iframe>
tag using the code bundled inside the JS SDK script. This<iframe>
tag has no src attribute at this point in the rendering life cycle. We leverage the__WEB__
global variable to determine if we are rendering client-side or server-side. The__WEB__
global variable will equal true when rendering client-side. To minimize the bundle size of the JS SDK script, we load these svg logos from the www.paypalobjects.com CDN as external images (ex:<PayPalLogoExternalImage />
). -
Second Render - The second phase of rendering happens on the server-side. This
<iframe>
tag is fully rendered by setting the src attribute and making an http request to the server to populate the contents which are securely hosted by PayPal's servers on www.paypal.com. The same code in this repo is used to render the buttons on the server-side. To ensure there are no issues with the logos, we have decided to inline the svg code for this server-side render (ex:<PayPalLogoInlineSVG />
). The__WEB__
global variable is set to false to control what code executes during the server render.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot