Batch Transfer

A batch transfer is a way to make multiple payouts transfer requests at one time. Cashfree offers separate APIs for batch transfers. This section provides details on how to integrate a batch transfer from scratch. It includes making a batch transfer and fetching the batch transfer status.

644

Batch Transfer

Steps

  1. Setup
  2. Initialization and Authorization
  3. Request a batch transfer
  4. Get batch transfer status

Check out our libraries and samples section for the integration code hosted on GitHub.

Step 1: Setup

Get your corresponding clientId and clientSecret from your payout dashboard and ensure that your IP is whitelisted as well. Check our development quickstart here.

Host URL: Use the following URL for PROD and TEST, respectively:

Step 2: Initialization and Authorization

Call the authenticate API to Cashfree system/server to obtain an Authorization Bearer token. All other API calls must have this token as Authorization header in the format 'Bearer ' (without quotes) for them to be processed.

curl -X POST \
  'http://{{Host%20Url}}/payout/v1/authorize' \

  -H 'X-Client-Id: {{client id}}' \
  -H 'X-Client-Secret: {{client secret}}' \
  -H 'cache-control: no-cache'
//require CashfreeSDK
const cfSdk = require('cashfree-sdk');

//access the PayoutsSdk from CashfreeSDK
const {Payouts} = cfSdk;

// Instantiate Cashfree Payouts
const payoutsInstance = new Payouts({
  env: 'TEST',
  clientId: '<CLIENT_ID>',
  clientSecret: '<CLIENT_SECRET>',
});
from cashfree_sdk.payouts import Payouts
from cashfree_sdk.payouts.transfers import Transfers

clientId = "your_client_id"
clientSecret = "your_secret_key"
env = "TEST"

Payouts.init(clientId, clientSecret, env)
import com.cashfree.lib.clients.Payouts;
import com.cashfree.lib.constants.Constants.Environment;

public static void main() {
Payouts payouts = Payouts.getInstance(
    Environment.PRODUCTION, "<client_id>", "<client_secret>");
payouts.init();
}

Sample Response

{
  "status":"SUCCESS", 
  "message":"Token generated", 
  "subCode":"200", 
  "data": {"token":"eyJ0eXA...fWStg", "expiry":1564130052}
}

Step 3: Request Batch Transfer

A batch transfer allows you to request multiple payout transfers at a given time. Batch transfers can be created by passing the beneficiary ID or by passing the beneficiary details.

curl -X POST \
  'http://{{Host%20Url}}/payout/v1/requestBatchTransfer' \
  -H 'Authorization: Bearer {{Token}}' \
  -d '{
	"batchTransferId": "test_batch_format",
	"batchFormat": "BENEFICIARY_ID",
	"batch": [{
		"transferId": "PTM_00121241112",
		"amount": "12",
		"beneId": "b01",
		"remarks": "working"
	}]
}'
const response = await payoutsInstance.transfers.requestBatchTransfer(
{batchTransferId : "Test_Bank_Account_Format_45",
batchFormat: "BANK_ACCOUNT" , 
deleteBene : 1, 
batch : [
    {transferId : "PTM_00121241112", 
    amount: "12",
    phone : "9999999999", 
    bankAccount : "9999999999" , 
    ifsc : "PYTM0_000001",
    email : "[email protected]",
    name: "bharat"}
    ]
});
entries = [ {"transferId" : "PTM_00121241112", 
    "amount" : "12",
    "phone" : "9999999999",
    "bankAccount" : "9999999999" , 
    "ifsc" : "PYTM0_000001",
    "email" : "[email protected]", 
    "name": "bharat"},
    {"transferId" : "PTM_00052312126",
    "amount" : "12",
    "phone" : "9999999999", 
    "bankAccount" : "9999999999" , 
    "ifsc" : "PYTM0000001",
    "email" : "[email protected]", 
    "name": "bharat" },
    {"transferId" : "PTM_0001321215",
    "amount" : "12","phone" : "9999999999", 
    "bankAccount" : "9999999999" , 
    "ifsc" : "PYTM0000001",
    "email" : "[email protected]", "name": "bharat"} ]

batch_tnx_create = Transfers.create_batch_transfer(batchTransferId="Test_Bank_Account_Format_45", batchFormat="BANK_ACCOUNT", batch=entries, deleteBene=1)
import com.cashfree.lib.clients.Payouts;
import com.cashfree.lib.clients.Transfers;
import com.cashfree.lib.domains.request.BatchTransferRequest;
import com.cashfree.lib.domains.request.RequestTransferRequest;

public static void main(){

Payouts payouts = Payouts.getInstance(
    Environment.PRODUCTION, "<client_id>", "<client_secret>");
payouts.init();
Transfers transfer = new Transfers(payouts);

BatchTransferRequest batchTransferRequest = new BatchTransferRequest()
        .setBatchTransferId("javasdkbatch12")
        .setBatchFormat("BANK_ACCOUNT")
        .setDeleteBene(1)
        .setBatch(List.of(
            new BatchTransferRequest.Payload()
                .setTransferId("PTM_00121241112")
                .setAmount(new BigDecimal("1.00"))
                .setPhone("9999999999")
                .setBankAccount("9999999999")
                .setIfsc("PYTM0_000001")
                .setEmail("[email protected]")
                .setName("bharat"),
            new BatchTransferRequest.Payload()
                .setTransferId("PTM_00052312126")
                .setAmount(new BigDecimal("1.00"))
                .setPhone("9999999999")
                .setBankAccount("9999999999")
                .setIfsc("PYTM0000001")
                .setEmail("[email protected]")
                .setName("bharat"),
            new BatchTransferRequest.Payload()
                .setTransferId("PTM_0001321215")
                .setAmount(new BigDecimal("1.00"))
                .setPhone("9999999999")
                .setBankAccount("9999999999")
                .setIfsc("PYTM0000001")
                .setEmail("[email protected]")
                .setName("bharat")));

transfers.requestBatchTransfer(batchTransferRequest);

}

Sample Response

{ 
  "status": SUCCESS, 
  "subCode": "200", 
  "message": "Request accepted",
  "data": { "referenceId": 1594 }}

Step 4: Get Batch Transfer Status

Get the status of all transfers within a batch transfer.

curl -X GET \
  'http://{{Host%20Url}}/payout/v1/getBatchTransferStatus?batchTransferId=test_batch_format_01' \
  -H 'Authorization: Bearer {{Token}}' \
const response = await payoutsInstance.tranfers.getBatchTransferStatus({
batchTransferId:Test_Bank_Account_Format_45" 
});
status = Transfers.get_batch_transfer_status(batchTransferId="Test_Bank_Account_Format_45")
import com.cashfree.lib.clients.Payouts;
import com.cashfree.lib.clients.Transfers;
import com.cashfree.lib.domains.request.BatchTransferRequest;
import com.cashfree.lib.domains.request.RequestTransferRequest;

public static void main(){

Payouts payouts = Payouts.getInstance(
    Environment.PRODUCTION, "<client_id>", "<client_secret>");
payouts.init();
Transfers transfer = new Transfers(payouts);

transfers.getBatchTransferStatus("javasdkbatch12");
}

Sample Response

{
  "status": "SUCCESS", 
  "subCode": "200", 
  "message": "Details of transfer with transferId 159381033b123", 
  "data": {"transfer": { "referenceId": 17073, 
                       "bankAccount": "026291800001191", 
                       "beneId": "ABCD_123", 
                       "amount": "20.00", 
                       "status": "SUCCESS", 
                       "utr": "1387420170430008800069857", 
                       "addedOn": "2017­-01­-07 20:09:59", 
                       "processedOn": "2017­-01­-07 20:10:05", 
                       "acknowledged": 1 
                       }
      }
}

Check out our Libraries and Samples section for the integration code hosted on GitHub.

You now have a complete standard transfer integration for payouts. Cashfree will send webhooks in the case of certain events. Webhooks are server to server notifications. Learn more about webhooks here.

When testing your integration with your test API key, you can use test numbers to ensure that it works correctly.