Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added rto #251

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions documents/order.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,77 @@ Razorpay::Order.edit(orderId,para_attr)
-------------------------------------------------------------------------------------------------------


### View RTO/Risk Reasons

```go
orderId = "order_XXXXXXXXXXXXX1"

Razorpay::Order.view_rto(orderId)
```
**Parameters**

| Name | Type | Description |
|----------|--------|------------------------------------- |
| orderId* | string | The unique identifier of an order to access the fulfillment information. |

**Response:**
```json
{
"risk_tier": "high",
"rto_reasons": [
{
"reason": "short_shipping_address",
"description": "Short shipping address",
"bucket": "address"
},
{
"reason": "address_pincode_state_mismatch",
"description": "Incorrect pincode state entered",
"bucket": "address"
}
]
}
```
-------------------------------------------------------------------------------------------------------

### Update the Fulfillment Details

```rb
order_id = "order_XXXXXXXXXXXXX1"

para_attr = {
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}

Razorpay::Order.edit_fulfillment(order_id, para_attr)
```
**Parameters**

| Name | Type | Description |
|----------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| orderId* | string | The unique identifier of an order to access the fulfillment information. |
| 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`. |
| shipping | object | Contains the shipping data. [here](https://razorpay.com/docs/payments/magic-checkout/rto-intelligence/#step-3-update-the-fulfillment-details) are supported |

**Response:**
```json
{
"entity": "order.fulfillment",
"order_id": "EKwxwAgItXXXX",
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}
```
-------------------------------------------------------------------------------------------------------
**PN: * indicates mandatory fields**
<br>
<br>
Expand Down
8 changes: 8 additions & 0 deletions lib/razorpay/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ def self.fetch_transfer_order(id)
# Docs: https://razorpay.com/docs/api/payments/route/#fetch-transfer-for-an-order
request.get "#{id}/?expand[]=transfers&status"
end

def self.view_rto(id)
request.post "#{id}/rto_review"
end

def self.edit_fulfillment(id, options = {})
request.post "#{id}/fulfillment", options
end
end
end
10 changes: 10 additions & 0 deletions test/fixtures/fake_fulfillment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"entity": "order.fulfillment",
"order_id": "EKwxwAgItXXXX",
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}
15 changes: 15 additions & 0 deletions test/fixtures/fake_rto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"risk_tier": "high",
"rto_reasons": [
{
"reason": "short_shipping_address",
"description": "Short shipping address",
"bucket": "address"
},
{
"reason": "address_pincode_state_mismatch",
"description": "Incorrect pincode state entered",
"bucket": "address"
}
]
}
10 changes: 10 additions & 0 deletions test/fixtures/order_error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"error": {
"code": "BAD_REQUEST_ERROR",
"description": "The id provided does not exist",
"source": "business",
"step": "payment_initiation",
"reason": "input_validation_failed",
"metadata": {}
}
}
44 changes: 43 additions & 1 deletion test/razorpay/test_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,48 @@ def test_fetch_order_transfers
assert_equal @order_id, order.id, 'order IDs do not match'
refute_empty order.transfers["items"]
assert_equal @transfer_id, order.transfers["items"][0]["id"]
end
end

def test_view_rto
stub_post(%r{orders/#{@order_id}/rto_review$}, 'fake_rto', {})
order = Razorpay::Order.view_rto(@order_id)
assert !order.rto_reasons.empty?, 'orders should be more than one'
end

def test_view_rto_exception
stub_post(%r{orders/#{@order_id}/rto_review$}, 'order_error', {})
assert_raises(Razorpay::Error) do
order = Razorpay::Order.view_rto(@order_id)
if order.error
raise Razorpay::Error.new, order.error['code']
end
end
end

def test_fulfillment
param_attr = {
"payment_method": "upi",
"shipping": {
"waybill": "123456789",
"status": "rto",
"provider": "Bluedart"
}
}

stub_post(%r{orders/#{@order_id}/fulfillment$}, 'fake_fulfillment', param_attr.to_json)
order = Razorpay::Order.edit_fulfillment(@order_id, param_attr.to_json)
assert_equal "upi", order.payment_method, 'order payment method do not match'
end

def test_fulfillment_exception
para_attr = {}
stub_post(%r{orders/#{@order_id}/fulfillment$}, 'order_error', para_attr.to_json)
assert_raises(Razorpay::Error) do
order = Razorpay::Order.edit_fulfillment(@order_id, para_attr.to_json)
if order.error
raise Razorpay::Error.new, order.error['code']
end
end
end
end
end
Loading