diff --git a/documents/transfers.md b/documents/transfers.md index a4d3f14..1540dd1 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 ea825b7..87a0246 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 0000000..62ea196 --- /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 8c08730..0342ce6 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