Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reversals #250

Merged
merged 6 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove the method chaining

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed chaining , also updated in doc and unit test

def self.reversals(id)

```

**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')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add test case for 5xx response.

Copy link
Contributor Author

@ankitdas13 ankitdas13 May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test cases

def test_fetch_reversals_exception

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
Loading