Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 26 additions & 0 deletions documents/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,32 @@ Razorpay::Token.process_payment_on_alternate_pa_or_pg({"id":"spt_4lsdksD31GaZ09"
}
}
```
-------------------------------------------------------------------------------------------------------

### Cancel token

```rb
customerId = "cust_1Aa00000000004"

tokenId = "token_Hxe0skTXLeg9pF"

Razorpay::Customer.cancelToken(customerId, tokenId)
```

**Parameters:**

| Name | Type | Description |
| ------------ | ------ | --------------------------------------------------------------------------- |
| customerId* | string | The unique identifier of the customer with whom the token is linked. |
| tokenId* | string | The unique identifier of the token that is to be cancelled. |

**Response:**
```json
{
"status": "cancellation_initiated"
}
```

-------------------------------------------------------------------------------------------------------
**PN: * indicates mandatory fields**
<br>
Expand Down
5 changes: 5 additions & 0 deletions lib/razorpay/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ def self.request_eligibility_check(options = {})
def self.fetch_eligibility(eligibilityId)
request.get "eligibility/#{eligibilityId}"
end

# Cancel a token
def self.cancelToken(customerId, tokenId)
request.put "#{customerId}/tokens/#{tokenId}/cancel"
end
end
end
4 changes: 4 additions & 0 deletions test/fixtures/fake_token_cancel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"entity": "token",
"status": "cancellation_initiated"
}
7 changes: 7 additions & 0 deletions test/razorpay/test_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,12 @@ def test_customer_fetch_eligiblity_exception
end
end
end

def test_customer_cancel_token
stub_request(:put, %r{customers/#{@customer_id}/tokens/#{@token_id}/cancel$})
.to_return(stub_response(%r{customers/#{@customer_id}/tokens/#{@token_id}/cancel$}, 'fake_token_cancel'))
result = Razorpay::Customer.cancelToken(@customer_id, @token_id)
assert_equal 'cancellation_initiated', result.status
end
end
end
Loading