Immediate capture

You can immediately capture money from your buyers and move it to your sellers.

On this page

Know before you code

  • Complete Onboarding before you begin this integration.
  • The instructions in Get started will help you get your access token.
  • This server-side integration uses the Orders REST API.
  • You must set intent to capture in the create order call for this feature to work.

Step 1: Create an order

Copy the following code and modify it.

Sample request

API endpoint used: Create an order

curl -v -X POST https://api.sandbox.paypal.com/v2/checkout/orders \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer Access-Token' \
 -H 'PayPal-Partner-Attribution-Id: BN-Code' \
 -d '{
 "intent": "CAPTURE",
 "purchase_units": [{
   "amount": {
     "currency_code": "USD",
     "value": "100.00"
   },
   "payee": {
     "email_address": "seller@example.com"
   },
   "payment_instruction": {
     "disbursement_mode": "INSTANT",
     "platform_fees": [{
       "amount": {
         "currency_code": "USD",
         "value": "25.00"
       }
     }]
   }
 }]
}'
var express = require('express');
var request = require('request');

express()
    .post('/my-server/create-order', function(req, res) {
        request.post('https://api.sandbox.paypal.com/v2/checkout/orders', {
            headers: {
                Content-Type: "application/json",
                Authorization: "Bearer Access-Token",
                PayPal-Partner-Attribution-Id: BN-Code
            },
            body: {
                "intent": "CAPTURE",
                "purchase_units": [{
                    "amount": {
                        "currency_code": "USD",
                        "value": "100.00"
                    },
                    "payee": {
                        "email_address": "seller@example.com"
                    },
                    "payment_instruction": {
                        "disbursement_mode": "INSTANT",
                        "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
            });
        });
    });

Modify the code

After you copy the code in the sample request, modify the following:

  • 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.
  • Use the purchase_units/payment_instruction/platform_fees array to specify fees for the order.

Step 2: Capture an order

Copy the following code and modify it.

Sample request

API endpoint used: Capture order

curl -v -k -X POST https://api.paypal.com/v2/checkout/orders/5O190127TN364715T/capture \
 -H 'PayPal-Partner-Attribution-Id: BN-Code' \
 -H 'Authorization: Bearer Access-Token' \
 -H 'Content-Type: application/json' \
 -d '{}'
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.sandbox.paypal.com/v2/checkout/orders/' + OrderID + '/capture', {
             headers: {
                 Content-Type: "application/json",
                 Authorization: "Bearer Access-Token",
                 PayPal-Partner-Attribution-Id: BN-Code
             }
         }, function(err, response, body) {
             if (err) {
                 console.error(err);
                 return res.sendStatus(500);
             }

             res.json({
                 status: 'success'
             });
         });
     });

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 flow.

Modify the code

After you copy the code in the sample request, modify the following:

  • Change Access-Token to your access token.
  • Change BN-Code to your partner ID.

Step 3: Show order details

API endpoint used: Show order details

Copy the following code and modify it, using the order ID as a path parameter.

Sample request

curl -v -X GET https://api.sandbox.paypal.com/v2/checkout/orders/5O190127TN364715T \
-H "Content-Type: application/json" \
-H "Authorization: Bearer Access-Token"
var http = require("https");

var options = {
  "method": "GET",
  "hostname": "api.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.

{
  "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.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.paypal.com/v2/checkout/orders/5O190127TN364715T/capture",
      "rel": "capture",
      "method": "POST"
    }
  ]
}

Modify the code

After you copy the code, modify the following:

  • Change Access-Token to your access token.
  • Pass the order ID as a path parameter.

Next steps

Test and go live