How to pass "amount" using @paypal/react-paypal-js

tcarter88
Contributor
Contributor

I am using @paypal/react-paypal-js and I just need example code on how to actually pass "amount" data from my client for a $30 subscription. My local dev is working fine with Paypal sandbox but it always defaults to $100.  Existing code examples only shows how to set currency, product ID and quantity, but not price.  Without any examples and vague API docs, I'm left to guessing.  I tried putting "amount": "30.00" in the PayPalScriptProvider initial options object, but that breaks the page. I tried passing it in the createOrder fetch body but Paypal seems to ignore that.  What am I missing here?  Can anyone provide a link to example code where I can actually define the price Paypal is charging the user? 
I'd also like to edit the email content in the notification email sent to the merchant, but can't find any docs on that either. Thanks in advance.

Login to Me Too
1 REPLY 1

tcarter88
Contributor
Contributor

I emailed merchant support and got my answers.  Reposting here the relevant code if anyone else finds this post.
Additionally, after hours of searching and looking around, I found the only mention of "amount" here:
https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=purchase_units/amount&t=request

Interesting that example code for "amount", being the main purpose of the entire Paypal business, is strangely buried.

Otherwise, their merchant support is very quick to respond with an answer for which I am grateful:

const createOrder = (data, actions) => {
    return actions.order.create({
      purchase_units: [
        {
          amount: {
            value: "30.00",
          },
        },
      ],
    });
  };

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.