paypalpaypal-sandboxpaypal-rest-sdk

Paypal Payout API


Hello stackover community, I want to integrate paypal payout functionality in my existing nodeJS Application. while doing RnD i found out that i can't send money from paypal's account to bank account directly. so i changed my appraoch, such as in payout api, i have passed "receipent_type" to PAYPAL_ID. i am in pakistan asia region. Paypal does not work here. now i want to test my api. from where i can get Paypal_account_ID as while completing the profile it requires me the bank account, SNS and other details which i am not having is there any way to that i can test my code

const paypalPayouts = async (req, res) => {
  const { paypalID, amount, currency, note } = req.body;

  if (!paypalID || !amount || !currency) {
    return res
      .status(400)
      .json({ message: "paypalID, amount, and currency are required" });
  }

  const payout = {
    sender_batch_header: {
      sender_batch_id: Math.random().toString(36).substring(9),
      email_subject: "You have a payout!",
      email_message:
        "You have received a payout! Thanks for using our paypal payout service!!",
    },
    items: [
      {
        recipient_type: "PAYPAL_ID",
        amount: {
          value: amount,
          currency: currency,
        },
        receiver: paypalID,
        note: note || "Thank you.",
        sender_item_id: Math.random().toString(36).substring(9),
      },
    ],
  };

  paypal.payout.create(payout, (error, payout) => {
    if (error) {
      console.error(error);
      return res
        .status(500)
        .json({ message: "Error creating payout", error: error.response });
    } else {
      console.log("paypal Payout response=>", payout);
      return res
        .status(200)
        .json({ message: "Payout created successfully", payout: payout });
    }
  });
};

how can i get my accountID or is there any way to run this api.


Solution

  •     items: [
          {
            recipient_type: "PAYPAL_ID", 
            amount: {
              value: amount,
              currency: currency,
            },
            receiver: accountID, 
            note: note || "Thank you.",
            sender_item_id: Math.random().toString(36).substring(9),
            recipient_bank_account: {
              bank_country: bankAccount.bank_country,
              account_number: bankAccount.account_number,
              account_currency: bankAccount.account_currency,
              account_name: bankAccount.account_name,
              routing_number: bankAccount.routing_number,
              bank_name: bankAccount.bank_name,
              bank_address: bankAccount.bank_address,
              bank_code: bankAccount.bank_code,
            },
          },
        ],
      };
    

    you need to pass the accountID, when you make an account in paypal in sandbox mode you need an extra account as well to perform the tesing such as one account as admin one account as buyer. Go to sandbox account and open admin account. you will find the ID there. same goes for the buyer account. copy the buyer account ID and pass in the JSON such as below hit the api. the balance will be deducted from one account and will be added into another account

    {
        "accountID": "J2TUG99MU2A9",
        "amount": "8",
        "currency": "USD",
        "note": "Test payout",
        "bankAccount": {
            "bank_country": "US",
            "account_number": "01005639601",
            "account_currency": "USD",
            "account_name": "John Doe",
            "routing_number": "987654321",
            "bank_name": "Bank of Example",
            "bank_address": "1234 Bank St, Example City, EX 12345",
            "bank_code": "001"
        }
    }