Reputation: 11
How can I change the amount of a PayPal Subscription with react-paypal-js
import { useEffect } from "react";
import {
PayPalScriptProvider,
PayPalButtons,
usePayPalScriptReducer
} from "@paypal/react-paypal-js";
const ButtonWrapper = ({ type }) => {
const [{ options }, dispatch] = usePayPalScriptReducer();
useEffect(() => {
dispatch({
type: "resetOptions",
value: {
...options,
intent: "subscription",
},
});
}, [type]);
return (<PayPalButtons
createSubscription={(data, actions) => {
return actions.subscription
.create({
plan_id: "P-3RX065706M3469222L5IFM4I",
})
.then((orderId) => {
// Your code here after create the order
return orderId;
});
}}
style={{
label: "subscribe",
}}
/>);
}
export default function App() {
return (
<PayPalScriptProvider
options={{
"client-id": "test",
components: "buttons",
intent: "subscription",
vault: true,
}}
>
<ButtonWrapper type="subscription" />
</PayPalScriptProvider>
);
}
Upvotes: 1
Views: 228
Reputation: 30477
Is P-3RX065706M3469222L5IFM4I your own plan ID, or not?
You can create your own plans via:
The account used must correspond to the client ID you load the JS SDK with.
If the amount needs to change arbitrarily rather than selecting from pre-created plans, then next to the plan_id you can specify a plan
object to override its values. This is documented in the Create Subscription API operation.
Upvotes: 1