Home > Net >  react-paypal-js runs onApprove function but no money is sent
react-paypal-js runs onApprove function but no money is sent

Time:11-05

I tried to do some 1€ payments with a paypal. And it it shows me that it's successful. It does everything what is in my onApprove function and no error is showing but when i check my 2 paypal account there is no money sent! Neither the balance of one account reduce nor the other gain balance.

Any ideas?

const initialOptions = {
  'client-id': 'MY_CLIENT_ID',
  components: 'buttons',
  'data-namespace': 'PayPalSDK',
  currency: 'EUR',
  intent: 'capture',
  'enable-funding': ['sofort', 'giropay'],
  'disable-funding': ['card', 'sepa'],
};



      <PayPalButtons
        key={Math.random()}
        createOrder={(data, actions) => {
          return actions.order.create({
            purchase_units: [
              {
                description: 'Restaurant',
                amount: {
                  value: carttotal,
                  currency_code: 'EUR',
                }
              },
            ],
            application_context: {
              shipping_preference: 'NO_SHIPPING',
            },
          });
        }}
        onApprove={(data, actions) => {
          actions.order.capture().then(() => {
             axios
            .post(
              '/api/paypal',
              {
                cartItems: cartItems,
               
              }
            )
          }
          
        }}
        onCancel={() => {
          toast.error('Cancel', {
            position: toast.POSITION.BOTTOM_RIGHT,
          });
        }}
        one rror={() => {
          //setPaid(false);
          toast.error('Error', {
            position: toast.POSITION.BOTTOM_RIGHT,
          });
        }}
      />

CodePudding user response:

You are using actions.order.create() to create the order for approval on the client side, but there is no call to actions.order.capture() after approval, so no transaction is created.

(If you need to store the result or do anything automated with the transaction result, you should not use either of those server-side functions, but rather the v2/checkout/orders API to create and capture on a backend, paired with a frontend that calls those backend routes.)

  • Related