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
21 changes: 21 additions & 0 deletions documents/token.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,27 @@ instance.tokens.processPaymentOnAlternatePAorPG({"id":"spt_4lsdksD31GaZ09"});
}
```
-------------------------------------------------------------------------------------------------------

### Cancel Token

```js
instance.customers.cancelToken('cust_1Aa00000000001','token_1Aa00000000001')
```

**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
8 changes: 7 additions & 1 deletion lib/resources/customers.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ module.exports = function (api) {
return api.get({
url: `/customers/eligibility/${eligibilityId}`,
}, callback)
}
},

cancelToken(customerId, tokenId, callback) {
return api.put({
url: `/customers/${customerId}/tokens/${tokenId}/cancel`,
}, callback);
},
}
}
8 changes: 8 additions & 0 deletions lib/types/customers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ declare function customers(api: any): {
* @param eligibilityId - The unique identifier of the eligibility request to be retrieved.
*/
fetchEligibility(eligibilityId: string): Promise<Partial<Customers.RazorpayCustomerEligibility>>
/**
* Cancel a token
*
* @param customerId - The unique identifier of the customer with whom the token is linked.
* @param tokenId - The unique identifier of the token that is to be cancelled.
*/
cancelToken(customerId: string, tokenId: string): Promise<{ status: string }>
cancelToken(customerId: string, tokenId: string, callback: (err: INormalizeError | null, data: { status: string }) => void): void;
}

export default customers
20 changes: 20 additions & 0 deletions test/resources/customers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,24 @@ describe('CUSTOMERS', () => {
done()
})
})

it('Cancel token', (done) => {
const TEST_CUSTOMER_ID = 'cust_PNSQEApWqQgwux'
const TEST_TOKEN_ID = 'token_RBBG4pD0oBpZ64'

mocker.mock({
url: `/customers/${TEST_CUSTOMER_ID}/tokens/${TEST_TOKEN_ID}/cancel`,
method: 'PUT'
})

rzpInstance.customers.cancelToken(TEST_CUSTOMER_ID, TEST_TOKEN_ID).then((response) => {
assert.equal(
response.__JUST_FOR_TESTS__.url,
`/v1/customers/${TEST_CUSTOMER_ID}/tokens/${TEST_TOKEN_ID}/cancel`,
'Cancel token url formed correctly'
)
done()
})
})

})
Loading