Search code examples
paypalpaypal-sandboxpaypal-rest-sdk

react-paypal-button-v2 secret key


I'm using "react-paypal-button-v2" I'm in sand box mode and I have those problems: 1- I can't find where to use my PAYPAL_CLIENT_SECRET 2- "amount" is discounted from the payer but never been added to the payee Balance 3- It never executes onApprove()

<PayPalButton
            amount={totalAmount}
            options={{
                clientId: settings.env.paypalClientId
            }}
            currency="USD"
            shippingPreference="NO_SHIPPING"
            onSuccess={(details, data) => {
                console.log({successData: data, successDetails: details})
                console.log("Transaction completed by " + details.payer.name.given_name);
            }}
            onApprove={(data) => {
                console.log("Approve data: " + data) /// <<<<<<<<<<<<<< never log
                return
            }}
            onError={(err) => console.error({ err })}
        />

Solution

  • react-paypal-button-v2 is not an official package. use react-paypal-js

    the createOrder and onApprove callback functions should call a backend to create and capture an order (respectively) using the v2/checkout/orders API. Those backend routes will make use of the client and secret to first obtain an oauth2 access token. See the standard checkout integration guide for example node.js code to accomplish this -- that node code is just an example of course, the routes can be implemented with any backend of your choosing. The routes themselves are not (and should not be) react code.


    Note also that actions.order.create and actions.order.capture functions, while still documented in react-paypal-js as of this writing, have been deprecated for new integrations. Do not use them.