diff --git a/documents/transfers.md b/documents/transfers.md index a4d3f14..4a4d7c2 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.reversals(transferId) +``` + +**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..690657b 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 self.reversals(id) + 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/fixtures/transfer_error.json b/test/fixtures/transfer_error.json new file mode 100644 index 0000000..ab33e9d --- /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 diff --git a/test/razorpay/test_transfer.rb b/test/razorpay/test_transfer.rb index 8c08730..52a29f7 100644 --- a/test/razorpay/test_transfer.rb +++ b/test/razorpay/test_transfer.rb @@ -73,5 +73,22 @@ 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.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 + + def test_fetch_reversals_exception + stub_get(%r{/transfers/#{@transfer_id}/reversals$}, 'transfer_error') + assert_raises(Razorpay::Error) do + transfer = Razorpay::Transfer.reversals(@transfer_id) + if transfer.error + raise Razorpay::Error.new, transfer.error['code'] + end + end + end end end