React native - paypal payout error status 400

37 Views Asked by At

I am trying to integrate a PayPal payout to my app because I want the user to be able to send money to another user but it is giving me error 400. I tried putting my friend's PayPal email just to test it, I know it wont send money since it is in sandbox.

const makePayout = async () => { 

    try {
      const response = await fetch('https://api-m.sandbox.paypal.com/v1/payments/payouts', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Bearer <my access token>'
        },
        body: JSON.stringify({
          "sender_batch_header": {
            "sender_batch_id": "Payouts_2020_100007",
            "email_subject": "You have a payout!",
            "email_message": "You have received a payout! Thanks for using our service!"
          },
          "items": [
            {
              "recipient_type": "EMAIL",
              "amount": {
                "value": "10.00",
                "currency": "PHP"
              },
              "note": "Thanks for your patronage!",
              "sender_item_id": "201403140001",
              "receiver": "<friend's email>@gmail.com",
              "recipient_wallet": "RECIPIENT_SELECTED"
            }
          ]
        })
      });

      if (response.ok) {
        const data = await response.json();
        console.log('Payout success:', data);
      } else {
        console.log('Payout failed. Status:', response.status);
      }
    } catch (error) {
      console.error('Payout error:', error.message);
    }
  };
1

There are 1 best solutions below

1
On
  1. You should not use the PayPal API from client-side code, especially Payouts. Anyone will be able to use the access token to send money from your PayPal account to arbitrary destinations, effectively stealing all your money. Instead, only use the API from a server, and examine all incoming requests before acting on them to make sure they are valid (not duplicates, correct amount and destination) for your purposes.

  2. To investigate the 400 error, look at the entire body of the PayPal API response.