Skip to content

Commit 1e57f85

Browse files
authored
added rto (#251)
1 parent 1003883 commit 1e57f85

File tree

6 files changed

+157
-1
lines changed

6 files changed

+157
-1
lines changed

documents/order.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,77 @@ Razorpay::Order.edit(orderId,para_attr)
275275
-------------------------------------------------------------------------------------------------------
276276

277277

278+
### View RTO/Risk Reasons
279+
280+
```go
281+
orderId = "order_XXXXXXXXXXXXX1"
282+
283+
Razorpay::Order.view_rto(orderId)
284+
```
285+
**Parameters**
286+
287+
| Name | Type | Description |
288+
|----------|--------|------------------------------------- |
289+
| orderId* | string | The unique identifier of an order to access the fulfillment information. |
290+
291+
**Response:**
292+
```json
293+
{
294+
"risk_tier": "high",
295+
"rto_reasons": [
296+
{
297+
"reason": "short_shipping_address",
298+
"description": "Short shipping address",
299+
"bucket": "address"
300+
},
301+
{
302+
"reason": "address_pincode_state_mismatch",
303+
"description": "Incorrect pincode state entered",
304+
"bucket": "address"
305+
}
306+
]
307+
}
308+
```
309+
-------------------------------------------------------------------------------------------------------
310+
311+
### Update the Fulfillment Details
312+
313+
```rb
314+
order_id = "order_XXXXXXXXXXXXX1"
315+
316+
para_attr = {
317+
"payment_method": "upi",
318+
"shipping": {
319+
"waybill": "123456789",
320+
"status": "rto",
321+
"provider": "Bluedart"
322+
}
323+
}
324+
325+
Razorpay::Order.edit_fulfillment(order_id, para_attr)
326+
```
327+
**Parameters**
328+
329+
| Name | Type | Description |
330+
|----------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
331+
| orderId* | string | The unique identifier of an order to access the fulfillment information. |
332+
| payment_method | string | Payment Method opted by the customer to complete the payment. Possible values is `upi`, `card`, `wallet`, `netbanking`, `cod`, `emi`, `cardless_emi`, `paylater`, `recurring`, `other`. |
333+
| shipping | object | Contains the shipping data. [here](https://razorpay.com/docs/payments/magic-checkout/rto-intelligence/#step-3-update-the-fulfillment-details) are supported |
334+
335+
**Response:**
336+
```json
337+
{
338+
"entity": "order.fulfillment",
339+
"order_id": "EKwxwAgItXXXX",
340+
"payment_method": "upi",
341+
"shipping": {
342+
"waybill": "123456789",
343+
"status": "rto",
344+
"provider": "Bluedart"
345+
}
346+
}
347+
```
348+
-------------------------------------------------------------------------------------------------------
278349
**PN: * indicates mandatory fields**
279350
<br>
280351
<br>

lib/razorpay/order.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ def self.fetch_transfer_order(id)
3535
# Docs: https://razorpay.com/docs/api/payments/route/#fetch-transfer-for-an-order
3636
request.get "#{id}/?expand[]=transfers&status"
3737
end
38+
39+
def self.view_rto(id)
40+
request.post "#{id}/rto_review"
41+
end
42+
43+
def self.edit_fulfillment(id, options = {})
44+
request.post "#{id}/fulfillment", options
45+
end
3846
end
3947
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"entity": "order.fulfillment",
3+
"order_id": "EKwxwAgItXXXX",
4+
"payment_method": "upi",
5+
"shipping": {
6+
"waybill": "123456789",
7+
"status": "rto",
8+
"provider": "Bluedart"
9+
}
10+
}

test/fixtures/fake_rto.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"risk_tier": "high",
3+
"rto_reasons": [
4+
{
5+
"reason": "short_shipping_address",
6+
"description": "Short shipping address",
7+
"bucket": "address"
8+
},
9+
{
10+
"reason": "address_pincode_state_mismatch",
11+
"description": "Incorrect pincode state entered",
12+
"bucket": "address"
13+
}
14+
]
15+
}

test/fixtures/order_error.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"error": {
3+
"code": "BAD_REQUEST_ERROR",
4+
"description": "The id provided does not exist",
5+
"source": "business",
6+
"step": "payment_initiation",
7+
"reason": "input_validation_failed",
8+
"metadata": {}
9+
}
10+
}

test/razorpay/test_order.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,48 @@ def test_fetch_order_transfers
6666
assert_equal @order_id, order.id, 'order IDs do not match'
6767
refute_empty order.transfers["items"]
6868
assert_equal @transfer_id, order.transfers["items"][0]["id"]
69-
end
69+
end
70+
71+
def test_view_rto
72+
stub_post(%r{orders/#{@order_id}/rto_review$}, 'fake_rto', {})
73+
order = Razorpay::Order.view_rto(@order_id)
74+
assert !order.rto_reasons.empty?, 'orders should be more than one'
75+
end
76+
77+
def test_view_rto_exception
78+
stub_post(%r{orders/#{@order_id}/rto_review$}, 'order_error', {})
79+
assert_raises(Razorpay::Error) do
80+
order = Razorpay::Order.view_rto(@order_id)
81+
if order.error
82+
raise Razorpay::Error.new, order.error['code']
83+
end
84+
end
85+
end
86+
87+
def test_fulfillment
88+
param_attr = {
89+
"payment_method": "upi",
90+
"shipping": {
91+
"waybill": "123456789",
92+
"status": "rto",
93+
"provider": "Bluedart"
94+
}
95+
}
96+
97+
stub_post(%r{orders/#{@order_id}/fulfillment$}, 'fake_fulfillment', param_attr.to_json)
98+
order = Razorpay::Order.edit_fulfillment(@order_id, param_attr.to_json)
99+
assert_equal "upi", order.payment_method, 'order payment method do not match'
100+
end
101+
102+
def test_fulfillment_exception
103+
para_attr = {}
104+
stub_post(%r{orders/#{@order_id}/fulfillment$}, 'order_error', para_attr.to_json)
105+
assert_raises(Razorpay::Error) do
106+
order = Razorpay::Order.edit_fulfillment(@order_id, para_attr.to_json)
107+
if order.error
108+
raise Razorpay::Error.new, order.error['code']
109+
end
110+
end
111+
end
70112
end
71113
end

0 commit comments

Comments
 (0)