razorpay / razorpay-java

Razorpay Java SDK
https://mvnrepository.com/artifact/com.razorpay/razorpay-java
MIT License
58 stars 67 forks source link

5% Failure Rate of Payment Transfer to Bank Accounts via Route (`RazorpayException BAD_REQUEST_ERROR:The id provided does not exist`) #321

Open SushSpaceBasic opened 3 months ago

SushSpaceBasic commented 3 months ago

I work at a start-up and we use Razorpay payment gateway to collect payments from our client's customers'. We have added the client bank accounts in our Razorpay account and use routing to transfer the amount to the client using the "Route" feature of Razorpay. We are experiencing a 5% failure of payment transfers in a day when there are a more than 1000 transactions being made in a day.

I'm using this code snippet to transfer the amount (razorpay-java-1.4.3)

Map<String, Object> paymentPayload = (Map<String, Object>) payload.get("payload");
Map<String, Object> payment = (Map<String, Object>) paymentPayload.get("payment");
Map<String, Object> paymentEntity = (Map<String, Object>) payment.get("entity");

String paymentId = String.valueOf(paymentEntity.get("id"));

RazorpayClient razorpay = new RazorpayClient(razorpayMID, razorpaySecretKey);

JSONObject createOrderRequest = new JSONObject();
JSONObject request = new JSONObject();
JSONArray transfers = new JSONArray();

createOrderRequest.put(AMOUNT, amountToBeTransferred);
createOrderRequest.put(CURRENCY, "INR");
createOrderRequest.put("account", accountId);
transfers.put(createOrderRequest);
request.put("transfers", transfers);

List<Transfer> razorpayTransfers = razorpay.payments.transfer(paymentId, request);

The transfer method in the last line fails with this error: RazorpayException BAD_REQUEST_ERROR:The id provided does not exist

JSON body of the transfer API (payload):

{
    "account_id": "acc_qwerty",
    "contains": [
        "payment"
    ],
    "created_at": 1721298486,
    "entity": "event",
    "event": "payment.captured",
    "payload": {
        "payment": {
            "entity": {
                "acquirer_data": {
                    "rrn": "0987654321"
                },
                "amount": 1101233,
                "amount_refunded": 0,
                "bank": null,
                "base_amount": 1101233,
                "captured": true,
                "card_id": null,
                "contact": "+911234567890",
                "created_at": 1721298485,
                "currency": "INR",
                "description": "qwerty",
                "email": "[johndoe@gmail.com](mailto:johndoe@gmail.com)",
                "entity": "payment",
                "error_code": null,
                "error_description": null,
                "error_reason": null,
                "error_source": null,
                "error_step": null,
                "fee": 0,
                "id": "pay_xyz",
                "international": false,
                "invoice_id": null,
                "method": "upi",
                "notes": {
                    "amountPaid": "1100000",
                    "convenienceCharges": "1233",
                    "proformaOrderId": "123",
                    "proformaOrderNo": "456",
                    "regNo": "112233",
                    "selectedPaymentMethod": "upi",
                    "studentId": "445566",
                    "tenantId": "999",
                    "type": "payment"
                },
                "order_id": "order_abc",
                "refund_status": null,
                "reward": null,
                "status": "captured",
                "tax": 0,
                "upi": {
                    "payer_account_type": "bank_account",
                    "vpa": "johndoe@abc"
                },
                "vpa": "johndoe@abc",
                "wallet": null
            }
        }
    }
}

Note: Replaced all sensitive information.

The error message is not helpful because the payment ID is valid. What is the error message trying to say? The payment ID is not yet recorded in Razorpay's system?

We tried contacting the Razorpay support but we did not receive any help in this issue. Did anyone else face this issue before? If so, how did you overcome this issue?