From 58862a35cec3dbef18834616ba9f877a08d064d6 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Tue, 30 Apr 2024 08:48:56 +0530 Subject: [PATCH 1/4] added reversals --- documents/transfers.md | 40 +++++++++++++++++++++++++ lib/razorpay/transfer.rb | 4 +++ test/fixtures/reversals_collection.json | 22 ++++++++++++++ test/razorpay/test_transfer.rb | 7 +++++ 4 files changed, 73 insertions(+) create mode 100644 test/fixtures/reversals_collection.json diff --git a/documents/transfers.md b/documents/transfers.md index a4d3f148..1540dd1f 100644 --- a/documents/transfers.md +++ b/documents/transfers.md @@ -775,6 +775,46 @@ Razorpay::Transfer.fetch(transferId).edit(para_attr) ------------------------------------------------------------------------------------------------------- +### Fetch Reversals for a Transfer +```rb +transferId = "trf_JhemwjNekar9Za" +Razorpay::Transfer.fetch(transferId).reversals +``` + +**Parameters:** + +| Name | Type | Description | +|---------------|-------------|---------------------------------------------| +| transferId* | string | The id of the transfer to be fetched | + +**Response:** +```json +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"rvrsl_Lt09xvyzskI7KZ", + "entity":"reversal", + "transfer_id":"trf_Lt048W7cgLdo1u", + "amount":50000, + "fee":0, + "tax":0, + "currency":"INR", + "notes":[ + + ], + "initiator_id":"Ghri4beeOuMTAb", + "customer_refund_id":null, + "utr":null, + "created_at":1684822489 + } + ] +} +``` + +------------------------------------------------------------------------------------------------------- + **PN: * indicates mandatory fields**

diff --git a/lib/razorpay/transfer.rb b/lib/razorpay/transfer.rb index ea825b72..87a0246c 100644 --- a/lib/razorpay/transfer.rb +++ b/lib/razorpay/transfer.rb @@ -31,5 +31,9 @@ def reverse(options = {}) def self.fetch_settlements request.get "?expand[]=recipient_settlement" end + + def reversals + self.class.request.get "#{id}/reversals" + end end end diff --git a/test/fixtures/reversals_collection.json b/test/fixtures/reversals_collection.json new file mode 100644 index 00000000..62ea1962 --- /dev/null +++ b/test/fixtures/reversals_collection.json @@ -0,0 +1,22 @@ +{ + "entity":"collection", + "count":1, + "items":[ + { + "id":"rvrsl_Lt09xvyzskI7KZ", + "entity":"reversal", + "transfer_id":"trf_Lt048W7cgLdo1u", + "amount":50000, + "fee":0, + "tax":0, + "currency":"INR", + "notes":[ + + ], + "initiator_id":"Ghri4beeOuMTAb", + "customer_refund_id":null, + "utr":null, + "created_at":1684822489 + } + ] + } diff --git a/test/razorpay/test_transfer.rb b/test/razorpay/test_transfer.rb index 8c087303..0342ce6c 100644 --- a/test/razorpay/test_transfer.rb +++ b/test/razorpay/test_transfer.rb @@ -73,5 +73,12 @@ def test_transfer_direct_transfer assert_equal transfer.id, @transfer_id , 'Transfer transfer_id is accessible' refute transfer.on_hold end + + def test_fetch_reversals + stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'reversals_collection') + transfer = Razorpay::Transfer.fetch(@transfer_id).reversals + assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array' + refute_empty transfer.items , 'Transfer should be more than one' + end end end From d92aaff485c09cba4d0a9c9f96ead6e82718662a Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 24 May 2024 10:46:04 +0530 Subject: [PATCH 2/4] added failure test case --- test/razorpay/test_transfer.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/razorpay/test_transfer.rb b/test/razorpay/test_transfer.rb index 0342ce6c..37cf0512 100644 --- a/test/razorpay/test_transfer.rb +++ b/test/razorpay/test_transfer.rb @@ -79,6 +79,16 @@ def test_fetch_reversals transfer = Razorpay::Transfer.fetch(@transfer_id).reversals assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array' refute_empty transfer.items , 'Transfer should be more than one' - end + end + + def test_fetch_reversals_exception + stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'transfer_error') + assert_raises(Razorpay::Error) do + transfer = Razorpay::Transfer.fetch(@transfer_id).reversals + if transfer.error + raise Razorpay::Error.new, transfer.error['code'] + end + end + end end end From 01c60f5949ef78686610f556302586c183731cd0 Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Fri, 24 May 2024 12:34:15 +0530 Subject: [PATCH 3/4] updated fixtures --- test/fixtures/transfer_error.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 test/fixtures/transfer_error.json diff --git a/test/fixtures/transfer_error.json b/test/fixtures/transfer_error.json new file mode 100644 index 00000000..ab33e9d3 --- /dev/null +++ b/test/fixtures/transfer_error.json @@ -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": {} + } +} \ No newline at end of file From 3eaf6baa0ef67c9e5b8569ee62d6092e070a1b6b Mon Sep 17 00:00:00 2001 From: ankitdas13 Date: Mon, 27 May 2024 12:15:36 +0530 Subject: [PATCH 4/4] removed chaining --- documents/transfers.md | 2 +- lib/razorpay/transfer.rb | 4 ++-- test/razorpay/test_transfer.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/documents/transfers.md b/documents/transfers.md index 1540dd1f..4a4d7c2b 100644 --- a/documents/transfers.md +++ b/documents/transfers.md @@ -778,7 +778,7 @@ Razorpay::Transfer.fetch(transferId).edit(para_attr) ### Fetch Reversals for a Transfer ```rb transferId = "trf_JhemwjNekar9Za" -Razorpay::Transfer.fetch(transferId).reversals +Razorpay::Transfer.reversals(transferId) ``` **Parameters:** diff --git a/lib/razorpay/transfer.rb b/lib/razorpay/transfer.rb index 87a0246c..690657be 100644 --- a/lib/razorpay/transfer.rb +++ b/lib/razorpay/transfer.rb @@ -32,8 +32,8 @@ def self.fetch_settlements request.get "?expand[]=recipient_settlement" end - def reversals - self.class.request.get "#{id}/reversals" + def self.reversals(id) + request.get "#{id}/reversals" end end end diff --git a/test/razorpay/test_transfer.rb b/test/razorpay/test_transfer.rb index 37cf0512..52a29f75 100644 --- a/test/razorpay/test_transfer.rb +++ b/test/razorpay/test_transfer.rb @@ -76,7 +76,7 @@ def test_transfer_direct_transfer def test_fetch_reversals stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'reversals_collection') - transfer = Razorpay::Transfer.fetch(@transfer_id).reversals + transfer = Razorpay::Transfer.reversals(@transfer_id) assert_instance_of Razorpay::Collection, transfer , 'Transfer should be an array' refute_empty transfer.items , 'Transfer should be more than one' end @@ -84,7 +84,7 @@ def test_fetch_reversals def test_fetch_reversals_exception stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'transfer_error') assert_raises(Razorpay::Error) do - transfer = Razorpay::Transfer.fetch(@transfer_id).reversals + transfer = Razorpay::Transfer.reversals(@transfer_id) if transfer.error raise Razorpay::Error.new, transfer.error['code'] end