# Delay disbursement (/limited-release/commerce-platform/accept-payments/delay-disbursement)



Use this integration to hold funds from a buyer before disbursing it to your seller. Holding funds gives you time to conduct additional vetting. If you want to capture funds immediately, use [Immediate capture](/platforms/checkout/immediate-capture/).

Delayed disbursement supports:

* Authorization: Set intent to authorize in the [create order](/api/orders/v2/orders-create) call to authorize a payment and place funds on hold after the customer makes a payment.
* Capture: Set intent to `capture` [create order](/api/orders/v2/orders-create) call to capture payment immediately after the customer makes a payment.

> **Info:** **Note:** Funds are automatically disbursed to the seller after 28 days, and PayPal deducts fees from the seller's funds.

## Know before you code [#know-before-you-code]

> **Info:** To use this integration you must:
>
> * [**Contact us**](https://www.paypal.com/us/cshelp/contact-us?_ga=2.191334383.496491259.1730035904-2088268300.1721295590) to be an approved partner.
> * [**Onboard merchants**](/limited-release/commerce-platform/onboard-merchants/) with the DELAY\_FUNDS\_DISBURSEMENT feature in the developer dashboard before you use this integration.
> * Inform your merchants of [PayPal's Seller Protection policy](https://www.paypal.com/us/webapps/mpp/security/seller-protection), so they are aware of use cases that invalidate that protection, such as shipping to an address other than the one in the transaction confirmation.

> **Info:** **Note:** This server-side integration uses the [Orders REST API](/api/orders/v2/) for this server-side integration.

## 1. Generate PayPal-Auth-Assertion header [#1-generate-paypal-auth-assertion-header]

You'll need to Pass the [PayPal-Auth-Assertion](/api/rest/requests/#paypal-auth-assertion) header with the standard `Content-Type`, `Authorization`, and `PayPal-Request-ID` headers. In client-side JavaScript, the value of the `PayPal-Auth-Assertion` header can be generated as follows:

```javascript lineNumbers
// client-side JavaScript

function encodeObjectToBase64(object) {
  const objectString = JSON.stringify(object);
  return window.btoa(objectString);
}

const clientId = "CLIENT-ID";
const sellerPayerId = "SELLER-PAYER-ID"; // preferred
// const sellerEmail = "SELLER-ACCOUNT-EMAIL"; // use instead of payer-id if required

const header = {
  alg: "none"
};
const encodedHeader = encodeObjectToBase64(header);

const payload = {
  iss: clientId,
  payer_id: sellerPayerId
  // email: sellerEmail
};
const encodedPayload = encodeObjectToBase64(payload);

const jwt = `${encodedHeader}.${encodedPayload}.`; // json web token
console.log(`Paypal-Auth-Assertion=${jwt}`);
```

> **Info:** **Note:** The token contains two period (.) characters, which are required according to the JSON web token structure.

#### Modify the code [#modify-the-code]

* Use the client ID of the platform or marketplace from the PayPal Developer dashboard for `clientId`.
* In the given example, the `sellerPayerId` is the payer ID of the receiving seller's PayPal account. You can also use `email` instead of `payer_id` and supply the email address of the seller's PayPal account.

Example functions to generate the `PayPal-Auth-Assertion` header in other programming environments:

#### Node.js [#nodejs]

```javascript lineNumbers
// Node.js

function encodeObjectToBase64(object) {
  const objectString = JSON.stringify(object);
  return Buffer
    .from(objectString)
    .toString("base64");
}

const clientId = "CLIENT-ID";
const sellerPayerId = "SELLER-PAYER-ID"; // preferred
// const sellerEmail = "SELLER-ACCOUNT-EMAIL"; // use instead if payer-id unknown

const header = {
  alg: "none"
};
const encodedHeader = encodeObjectToBase64(header);

const payload = {
  iss: clientId,
  payer_id: sellerPayerId
  // email: sellerEmail
};
const encodedPayload = encodeObjectToBase64(payload);

const jwt = `${encodedHeader}.${encodedPayload}.`; // json web token
console.log(`Paypal-Auth-Assertion=${jwt}`);
```

#### Java [#java]

```java lineNumbers
// Java

import org.apache.commons.codec.binary.Base64;

public class Base64Encode {

  public static void main(String[] args) {
    String clientId = "CLIENT-ID";
    String sellerPayerId = "SELLER-PAYER-ID"; // preferred
    // String sellerEmail = "SELLER-ACCOUNT-EMAIL"; // use instead if payer-id unknown

    String header = "{\"alg\":\"none\"}";
    String payload =
      "{\"iss\":\"" + clientId + "\",\"payer_id\":\"" + sellerPayerId + "\"}";
    // "{"iss":"" + clientId + "","email":"" + sellerEmail + ""}";

    byte[] encodedHeader = Base64.encodeBase64(header.getBytes());
    byte[] encodedPayload = Base64.encodeBase64(payload.getBytes());

    String jwt = new String(encodedHeader) +
      "." +
      new String(encodedPayload) +
      "."; // json web token
    System.out.println("Paypal-Auth-Assertion=" + jwt);
  }
}
```

## 2. Create Order [#2-create-order]

You must first [create an order](/api/orders/v2/orders-create) and capture funds. To create an order, copy the following code and modify as follows:

* Replace `BN-CODE` with your PayPal attribution ID.
* Replace `PAYPAL-AUTH-ASSERTION` with your PayPal auth assertion generated from Step 1.
* Use the `purchase_units/payee` object to specify the end receiver of the funds.
* Use the `purchase_units/payment_instruction/disbursement_mode` field to specify when funds should be disbursed to the payee upon calling [capture order](/api/orders/v2/orders-capture). In this integration, set this field to `DELAYED`.
* Use the `purchase_units/payment_instruction/platform_fees` array to specify fees for the order. To use this array, ensure that the merchants are onboarded with the **Platform Fee** feature enabled for your app. On the app settings page of your app, you can configure specific features. To configure your app to include **PARTNER\_FEE**, from the developer dashboard, navigate to your app settings page and toggle **Platform Fee** to select the feature.

#### Sample request - cURL [#sample-request---curl]

```javascript lineNumbers
curl -v -XPOSThttps://api-m.sandbox.paypal.com/v2/checkout/orders
-H'Content-Type: application/json'
-H'Authorization: Bearer ACCESS-TOKEN'
-H'PayPal-Partner-Attribution-Id: BN-CODE'
-H'PayPal-Auth-Assertion: PAYPAL-AUTH-ASSERTION'
-d '{
"intent":"CAPTURE",
"purchase_units":[{
"amount":{
"currency_code":"USD",
"value":"100.00"
},
"payee":{
"email_address":"seller@example.com"
},
"payment_instruction":{
"disbursement_mode":"DELAYED",
"platform_fees":[{
"amount":{
"currency_code":"USD",
"value":"25.00"
}
}]
}
}]
}'
```

#### Sample request - Node [#sample-request---node]

```javascript lineNumbers
var express =require('express');
var request =require('request');
express().post('/my-server/create-order',function(req, res){
	request.post('https://api-m.sandbox.paypal.com/v2/checkout/orders',{
headers:{
"Content-Type":"application/json",
"Authorization":"Bearer ACCESS-TOKEN",
"PayPal-Partner-Attribution-Id":"BN-CODE",
"PayPal-Auth-Assertion":"PAYPAL-AUTH-ASSERTION"
},
body:{
"intent":"CAPTURE",
"purchase_units":[{
"amount":{
"currency_code":"USD",
"value":"100.00"
},
"payee":{
"email_address":"seller@example.com"
},
"payment_instruction":{
"disbursement_mode":"DELAYED",
"platform_fees":[{
"amount":{
"currency_code":"USD",
"value":"25.00"
}
}]
}
}],
},
json:true
},function(err, response, body){
if(err){
console.error(err);
return res.sendStatus(500);
}
		res.json({
id: body.id
});
});
});
```

## 3. Capture Order [#3-capture-order]

After your buyer approves the order, call [capture order](/api/orders/v2/orders-capture) to capture the buyer's funds.

Copy the following code and modify as follows:

* Replace `ACCESS-TOKEN` with your access token.
* Replace `BN-CODE` with your [PayPal partner attribution ID](/api/rest/requests/#paypal-partner-attribution-id).
* Replace `PAYPAL-AUTH-ASSERTION` with your PayPal auth assertion generated from Step 1.

#### Sample request - cURL [#sample-request---curl-1]

```javascript lineNumbers
curl -v -k -X POST https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T/capture
-H 'Content-Type: application/json'
-H 'Authorization: Bearer ACCESS-TOKEN'
-H 'PayPal-Partner-Attribution-Id: BN-CODE'
-H 'PayPal-Auth-Assertion: PAYPAL-AUTH-ASSERTION'
-d '{}'
```

#### Sample request - Node [#sample-request---node-1]

```javascript lineNumbers
var express = require('express');
var request = require('request');
express().post('/my-server/handle-approve/:id', function(req, res) {
	var OrderID = req.params.id;
	request.post('https://api-m.sandbox.paypal.com/v2/checkout/orders/' + OrderID + '/capture', {
		headers: {
			"Content-Type": "application/json",
			"Authorization": "Bearer ACCESS-TOKEN",
			"PayPal-Partner-Attribution-Id": "BN-CODE",
			"PayPal-Auth-Assertion": "PAYPAL-AUTH-ASSERTION"
		}
	}, function(err, response, body) {
		if (err) {
			console.error(err);
			return res.sendStatus(500);
		}
		res.json({
			status: 'success'
		});
	});
});
```

> **Info:** **Note:** Orders cannot be captured until the status of the order is set to APPROVED. The order status is set to APPROVED when the buyer successfully completes the [checkout](/platforms/checkout/) flow.

## 4. Show order details [#4-show-order-details]

To see your order details, pass the order ID as a path parameter in a [show order details](/api/orders/v2/orders-get) call.

Copy the following code and modify as follows:

* Replace `ACCESS-TOKEN` with your access token.
* Replace `BN-CODE` with your [PayPal partner attribution ID](/api/rest/requests/#paypal-partner-attribution-id).
* Replace `PAYPAL-AUTH-ASSERTION` with your PayPal auth assertion generated from Step 1.

#### Sample request - cURL [#sample-request---curl-2]

```javascript lineNumbers
curl -v -X GET https://api-m.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T
-H "Content-Type: application/json"
-H 'Authorization: Bearer ACCESS-TOKEN'
-H 'PayPal-Partner-Attribution-Id: BN-CODE'
-H 'PayPal-Auth-Assertion: PAYPAL-AUTH-ASSERTION'
```

#### Sample request - Node [#sample-request---node-2]

```javascript lineNumbers
var http = require("https");
var options = {
	"method": "GET",
	"hostname": "api-m.sandbox.paypal.com",
	"port": null,
	"path": "/v2/checkout/orders/5O190127TN364715T",
	"headers": {
		"Content-Type": "application/json",
		"Authorization": "Bearer ACCESS-TOKEN",
		"PayPal-Partner-Attribution-Id": "BN-CODE",
		"PayPal-Auth-Assertion": "PAYPAL-AUTH-ASSERTION"
	}
};
var req = http.request(options, function(res) {
	var chunks = [];
	res.on("data", function(chunk) {
		chunks.push(chunk);
	});
	res.on("end", function() {
		var body = Buffer.concat(chunks);
		console.log(body.toString());
	});
});
req.end();
```

A successful request returns the `HTTP 200 OK` status code and a JSON response body that shows order details.

```json lineNumbers
{
  "id": "5O190127TN364715T",
  "status": "CREATED",
  "intent": "CAPTURE",
  "purchase_units": [
    {
      "reference_id": "d9f80740-38f0-11e8-b467-0ed5f89f718b",
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ],
  "create_time": "2018-04-01T21:18:49Z",
  "links": [
    {
      "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T",
      "rel": "self",
      "method": "GET"
    },
    {
      "href": "https://www.paypal.com/checkoutnow?token=5O190127TN364715T",
      "rel": "approve",
      "method": "GET"
    },
    {
      "href": "https://api-m.paypal.com/v2/checkout/orders/5O190127TN364715T/capture",
      "rel": "capture",
      "method": "POST"
    }
  ]
}
```

## 5. Disburse funds [#5-disburse-funds]

Once funds are captured, call [/v1/payments/referenced-payouts-items](/api/payouts/standard) to disburse funds to your seller. To make this call you must pass a `reference_id`. Retrieve the `reference_id` by making a [show order details](/api/orders/v2/orders-get) call and note down the `urchase_units/payments/captures/id` field.

Copy the following code and modify as follows:

* Replace `ACCESS-TOKEN` with your access token.
* Replace `BN-CODE` with your [PayPal partner attribution ID](/api/rest/requests/#paypal-partner-attribution-id).

#### Sample request - cURL [#sample-request---curl-3]

```javascript lineNumbers
curl -v https://api-m.sandbox.paypal.com/v1/payments/referenced-payouts-items
-XPOST
-H"Content-Type: application/json"
-H"Authorization: Bearer ACCESS-TOKEN"
-H"PayPal-Partner-Attribution-Id: BN-CODE"
-d '{
"reference_id":"29N36144XH0198422",
"reference_type":"TRANSACTION_ID"
}'
```

#### Sample request - Node [#sample-request---node-3]

```javascript lineNumbers
var http =require("https");
var options ={
"method":"GET",
"hostname":"api-m.sandbox.paypal.com",
"port":null,
"path":"/v2/checkout/orders/5O190127TN364715T",
"headers":{
"content-type":"application/json",
"Authorization":"Bearer ACCESS-TOKEN",
}
};
var req = http.request(options,
function(res){
var chunks =[];
    res.on("data ",function(chunk){
        chunks.push(chunk);
});
    res.on("end ",function(){
var body =Buffer.concat(chunks);
console.log(body.toString());
})
;});
req.end();
```

A successful request returns the `HTTP 200 OK` status code and a JSON response body that shows order details.

## Next steps [#next-steps]

> **Info:** [Integration Checklist](/platforms/integration-checklist)
>
> Go through the integration checklist before you go live.
