Skip to content

Instantly share code, notes, and snippets.

@arvindrajnaidu
Created October 18, 2021 18:55
Show Gist options
  • Select an option

  • Save arvindrajnaidu/dd2400a524336043d4c2268aeeacdc7b to your computer and use it in GitHub Desktop.

Select an option

Save arvindrajnaidu/dd2400a524336043d4c2268aeeacdc7b to your computer and use it in GitHub Desktop.
import React from "react";
import { PayPalButtons } from "@paypal/react-paypal-js";
const PayPalButton = ({ order, saveToServer }) => {
return (
<PayPalButtons
fundingSource={"paypal"}
style={{ layout: "horizontal" }}
createOrder={(data, actions) => {
return actions.order.create({
purchase_units: [
{
amount: {
value: `${(centsAmount / 100).toFixed(2)}`,
},
},
],
});
}}
onApprove={(details) => {
saveToServer({
id: details.orderID,
paymentProvider: "paypal",
}).then(() => {
console.log('Paid')
});
}}
/>
);
};
export default PayPalButton;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment