Send funds to another account

By default, the money is paid to the application owner in their own account, and this account receiving funds is known as the payee or receiver.

To specify a different receiver when you create a payment or order, add the payee object to the transaction payload and include the email_address or merchant_id of the account to receive the payment.

  1. Set up your server to make calls to PayPal
  2. Set up your server to receive a call from the client
  3. Call PayPal to set up a transaction with a payee
  4. Handle any errors from the call
  5. Return a successful response to the client with the order ID
// Note: This is example code. Each server platform and programming language has a different way of handling requests, making HTTP API calls, and serving responses to the browser.

// 1. Set up your server to make calls to PayPal

// 1a. Add your client ID and secret
PAYPAL_CLIENT = 'PAYPAL_SANDBOX_CLIENT';
PAYPAL_SECRET = 'PAYPAL_SANDBOX_SECRET';

// 1b. Point your server to the PayPal API
PAYPAL_OAUTH_API = 'https://api.sandbox.paypal.com/v1/oauth2/token/';
PAYPAL_ORDER_API = 'https://api.sandbox.paypal.com/v2/checkout/orders/';

// 1c. Get an access token from the PayPal API
basicAuth = base64encode(`${ PAYPAL_CLIENT }:${ PAYPAL_SECRET }`);
auth = http.post(PAYPAL_OAUTH_API {
  headers: {
    Accept:        `application/json`,
    Authorization: `Basic ${ basicAuth }`
  },
  data: `grant_type=client_credentials`
});

// 2. Set up your server to receive a call from the client
function handleRequest(request, response) {

  // 3. Call PayPal to set up a transaction with a payee
  order = http.post(PAYPAL_ORDER_API, {
    headers: {
      Accept:        `application/json`,
      Authorization: `Bearer ${ auth.access_token }`
    },
    data: {
      intent: 'CAPTURE',
      purchase_units: [{
        amount: {
          currency_code: 'USD',
          value: '220.00'
        },
        payee: {
          email_address: 'payee@gmail.com'
        }
      }]
    }
  });

  // 4. Handle any errors from the call
  if (order.error) {
    return response.send(500);
  }

  // 5. Return a successful response to the client with the order ID
  response.send(200, {
    orderID: order.id
  });
}
// 1. Set up your server to make calls to PayPal

// 1a. Import the SDK package
const paypal = require('checkoutNodeJssdk');

// 1b. Add your client ID and secret
const PAYPAL_CLIENT = 'PAYPAL_SANDBOX_CLIENT';
const PAYPAL_SECRET = 'PAYPAL_SANDBOX_SECRET';

// 1c. Set up the SDK client
const env = new paypal.core.SandboxEnvironment(PAYPAL_CLIENT, PAYPAL_SECRET);
const client = new paypal.core.PayPalHttpClient(env);

// 2. Set up your server to receive a call from the client
module.exports = async function handleRequest(req, res) {

  // 3. Call PayPal to set up a transaction with payee
  const request = new sdk.orders.OrdersCreateRequest();
  request.prefer("return=representation");
  request.requestBody({
    intent: 'CAPTURE',
    purchase_units: [{
      amount: {
        currency_code: 'USD',
        value: '220.00'
      },
      payee: {
        email_address: 'payee@gmail.com'
      }
    }]
  });

  let order;
  try {
    order = await payPalClient.client().execute(request);
  } catch (err) {

    // 4. Handle any errors from the call
    console.error(err);
    return res.send(500);
  }

  // 5. Return a successful response to the client with the order ID
  res.status(200).json{
    orderID: order.result.id
  });
}
private static function buildRequestBody()
{
  return array(
    'intent' => 'AUTHORIZE',
    'purchase_units' =>
      array(
        0 =>
          array(
            'amount' =>
              array(
                'currency_code' => 'USD',
                'value' => '220.00'
              )
          ),
          array(
            'payee' =>
              array(
                'email_address' => 'payee@email.com'
              )
          )
      )
  );
}
@staticmethod
def build_request_body():
  """Method to create body with a custom PAYEE (receiver)"""
  return \
    {
      "intent": "AUTHORIZE",           
      "purchase_units": [
        {
          "amount": {
            "currency_code": "USD",
            "value": "220.00"
          },
          "payee": {
            "email_address": "payee@email.com"
          }
        }
      ]
    }
def build_request_body (debug=false)
  body = {
    intent: 'AUTHORIZE',         
    purchase_units: [
      {
        amount: {
          currency_code: 'USD',
          value: '220.00'
        },
        payee: {
          email_address: 'payee@email.com'
        }
      }
    ]
  }
private OrderRequest buildRequestBody() {
    OrderRequest orderRequest = new OrderRequest();
    orderRequest.intent("AUTHORIZE");

    ApplicationContext applicationContext = new ApplicationContext();

    List<PurchaseUnitRequest> purchaseUnitRequests = new ArrayList<>();
    PurchaseUnitRequest purchaseUnitRequest = new PurchaseUnitRequest()
            .amount(new AmountWithBreakdown().currencyCode("USD").value("220.00"));
    Payee payee = new Payee();
    payee.emailAddress("payee@email.com");
    purchaseUnitRequest.payee(payee);        
    purchaseUnitRequests.add(purchaseUnitRequest);
    orderRequest.purchaseUnits(purchaseUnitRequests);
    return orderRequest;
}
private static OrderRequest BuildRequestBody()
{
  OrderRequest orderRequest = new OrderRequest()
  {
    Intent = "AUTHORIZE",
    ApplicationContext = new ApplicationContext
    {

    },                
    PurchaseUnits = new List<PurchaseUnitRequest>
    {
      new PurchaseUnitRequest {
        Amount = new AmountWithBreakdown
        {
          CurrencyCode = "USD",
          Value = "220.00"
        },
        Payee = new Payee
        {
          EmailAddress = "example@paypal.com"
        }          
      }
    }
  };

  return orderRequest;
}

Then follow the steps in the basic integration to test your integration and go live.