diff --git a/documents/tokens.md b/documents/tokens.md index d283327..8ff3b8b 100644 --- a/documents/tokens.md +++ b/documents/tokens.md @@ -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**
diff --git a/lib/razorpay/customer.rb b/lib/razorpay/customer.rb index 231f0b8..fd576a5 100644 --- a/lib/razorpay/customer.rb +++ b/lib/razorpay/customer.rb @@ -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 diff --git a/test/fixtures/fake_token_cancel.json b/test/fixtures/fake_token_cancel.json new file mode 100644 index 0000000..abe79be --- /dev/null +++ b/test/fixtures/fake_token_cancel.json @@ -0,0 +1,4 @@ +{ + "entity": "token", + "status": "cancellation_initiated" +} \ No newline at end of file diff --git a/test/razorpay/test_customer.rb b/test/razorpay/test_customer.rb index ae3274e..842a783 100644 --- a/test/razorpay/test_customer.rb +++ b/test/razorpay/test_customer.rb @@ -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