diff --git a/documents/token.md b/documents/token.md index aa0a0c6d..40a49355 100644 --- a/documents/token.md +++ b/documents/token.md @@ -384,7 +384,31 @@ Token token = instance.token.processPaymentOnAlternatePAorPG(productRequest); } ``` ------------------------------------------------------------------------------------------------------- +### Cancel token +```java +String customerId = "cust_1Aa00000000004"; + +String tokenId = "token_Hxe0skTXLeg9pF"; + +instance.customers.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/src/main/java/com/razorpay/Constants.java b/src/main/java/com/razorpay/Constants.java index c55bc6dc..40c00a56 100755 --- a/src/main/java/com/razorpay/Constants.java +++ b/src/main/java/com/razorpay/Constants.java @@ -102,6 +102,8 @@ public class Constants { static final String TOKEN_GET = "customers/%s/tokens/%s"; static final String TOKEN_DELETE = "customers/%s/tokens/%s"; + static final String TOKEN_CANCEL = "customers/%s/tokens/%s/cancel"; + static final String TRANSFER_CREATE = "transfers"; static final String TRANSFER_GET = "transfers/%s"; static final String TRANSFER_EDIT = "transfers/%s"; diff --git a/src/main/java/com/razorpay/CustomerClient.java b/src/main/java/com/razorpay/CustomerClient.java index 6bbe079d..79b74bc9 100644 --- a/src/main/java/com/razorpay/CustomerClient.java +++ b/src/main/java/com/razorpay/CustomerClient.java @@ -66,4 +66,8 @@ public Customer requestEligibilityCheck(JSONObject request) throws RazorpayExcep public Customer fetchEligibility(String id) throws RazorpayException { return get(Constants.VERSION, String.format(Constants.ELIGIBILITY_FETCH, id), null); } + + public Customer cancelToken(String customerId, String tokenId) throws RazorpayException { + return put(Constants.VERSION, String.format(Constants.TOKEN_CANCEL, customerId, tokenId), null); + } } diff --git a/src/test/java/com/razorpay/CustomerClientTest.java b/src/test/java/com/razorpay/CustomerClientTest.java index c080268e..b48e0a0f 100644 --- a/src/test/java/com/razorpay/CustomerClientTest.java +++ b/src/test/java/com/razorpay/CustomerClientTest.java @@ -458,4 +458,18 @@ public void testFetchEligibility() throws RazorpayException { assertTrue(false); } } + + @Test + public void testCanelToken() throws IOException, RazorpayException { + String mockedResponseJson = "{\"entity\":\"customer\",\"status\":cancellation_initiated}"; + try { + mockResponseFromExternalClient(mockedResponseJson); + mockResponseHTTPCodeFromExternalClient(200); + Customer customer = customerClient.cancelToken(CUSTOMER_ID,TOKEN_ID); + assertNotNull(customer); + verifySentRequest(false, null, getHost(String.format(Constants.TOKEN_CANCEL,CUSTOMER_ID,TOKEN_ID))); + } catch (IOException e) { + assertTrue(false); + } + } } \ No newline at end of file