Skip to content

Commit

Permalink
added reversals (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitdas13 authored May 27, 2024
1 parent 277f49b commit 1003883
Show file tree
Hide file tree
Showing 5 changed files with 93 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.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**
<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 self.reversals(id)
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
}
]
}
10 changes: 10 additions & 0 deletions test/fixtures/transfer_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": {}
}
}
17 changes: 17 additions & 0 deletions test/razorpay/test_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1003883

Please sign in to comment.