HLD - Razorpay Route Integration
Details needed to make this integration work:
Step 1. The following keys are required to generate a basic auth token to validate the requests:
[YOUR_KEY_ID]
[YOUR_KEY_SECRET]
Step 2. Once we have these two credentials, the app will be installed and connected.
Step 3. Now, to perform the settlement of Prepaid Orders
, we can use two below-mentioned approaches:
Approach 1: We listen to the shipment delivered event and check if the particular is fulfilled by the Distributor or Eshopbox, based on which razor_pay_account_id
will be fetched and can be used to perform the transfer.
Step-wise flow for this approach:
Check the configuration set by the client for settling the payment, which could be order delivered date+
N days
configured by the client in the settings.If No return is initiated on this order, we need to check for the shipments.warehouse_id or
externalWarehouseID
given in the particular event.Using
externalWarehouseID
, andaccount_id
combination, pick therazor_pay_account_id
fromeshopbox_wms_production.account_warehouse_mapping
Using this
razor_pay_account_id
, we need to prepare the request given as below to do the settlement of the payment.
POST API:
https://api.razorpay.com/v1/payments/{pay_id}/transfers
Request Body:
{
"transfers": [
{
"account": "razor_pay_account_id",//Please replace with appropriate ID.
"amount": 100,
"currency": "INR",
"on_hold": true,
"on_hold_until": 1671222870
}
]
}
Mapping of Keys:
Keys | Values |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Conditions to decide for Amount:
Step 1. Fetch all the order_items(status !=cancelled) using the following conditions:
externalChannelID
customerOrderNumber
externalShipmentID
Step 2. Once the items are retrieved, then we need to make the sum of order_items.invoiceTotal
, and it will become our transfers[].amount
Step 4. Once the settlement is scheduled for the N Days configured by the Client
on Razorpay, we need to save the status as order_settled
in shipment_status_logs
Approach 2: Cron-based approach
Step-wise flow for this approach:
Fetch all the active connections of Razor Pay
Out of active connections, check for the channel configured for the settlements of payments via Razorpay Route Integration.
Now, pick one connection and fetch all the
Prepaid Orders
andshipment_status_logs.status
!='order_settled
' of that particular channel delivered +N days
which the client configures in the settings.If No return is initiated on this order, we need to check for the shipments.warehouse_id or
externalWarehouseID
Using
externalWarehouseID
, andaccount_id
combination, pick therazor_pay_account_id
fromeshopbox_wms_production.account_warehouse_mapping
Using this
razor_pay_account_id
, we need to prepare the request explained as above.Once we have successfully made the settlement on Razorypay, then we need to save the status as
order_settled
inshipment_status_logs