Skip to content

Commit

Permalink
added reversals
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 committed Apr 30, 2024
1 parent bbb7188 commit 58862a3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
40 changes: 40 additions & 0 deletions documents/transfers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
<br>
<br>
Expand Down
4 changes: 4 additions & 0 deletions lib/razorpay/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions test/fixtures/reversals_collection.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
7 changes: 7 additions & 0 deletions test/razorpay/test_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 58862a3

Please sign in to comment.