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
24 changes: 24 additions & 0 deletions documents/token.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
<br>
<br>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/razorpay/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/razorpay/CustomerClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
14 changes: 14 additions & 0 deletions src/test/java/com/razorpay/CustomerClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}