- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi to all,
I'm trying to add a paypal button in my React app and I found this: https://developer.paypal.com/docs/checkout/standard/customize/single-page-app/
In public/index.html I added a line like this:
<script src="https://www.paypal.com/sdk/js?client-id=YOUR_CLIENT_ID"></script>
then I try to create my custom component like this:
import React from "react";
import ReactDOM from "react-dom"
const PayPalButton = paypal.Buttons.driver("react", { React, ReactDOM });
class YourComponent extends React.Component {
createOrder(data, actions) {
return actions.order.create({
purchase_units: [
{
amount: {
value: "0.01",
},
},
],
});
}
onApprove(data, actions) {
return actions.order.capture();
}
render() {
return (
<PayPalButton
createOrder={(data, actions) => this.createOrder(data, actions)}
onApprove={(data, actions) => this.onApprove(data, actions)}
/>
);
}
}
the app fails to compile: 'paypal' is not defined. Any suggestions? Thanks
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
just added this line:let paypal = window.paypal;
before this:const PayPalButton = paypal.Buttons.driver('react', { React, ReactDOM });
and resolved
const paypal = window.paypal;
const PayPalButton = paypal.Buttons.driver('react', { React, ReactDOM });
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
just added this line:let paypal = window.paypal;
before this:const PayPalButton = paypal.Buttons.driver('react', { React, ReactDOM });
and resolved
const paypal = window.paypal;
const PayPalButton = paypal.Buttons.driver('react', { React, ReactDOM });

Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- invoice api doesn't accept bearer token in REST APIs
- payments in javascript with custom button in SDKs
- advanced credit and debit card payment options not available in accept payments in NVP/SOAP APIs
- JavaScript SDK unreliable redirect using "Sofortüberweisung" Klarna payment provider in SDKs
- What are basic create-paypal-order and capture-paypal-order files? in REST APIs