Debit/Credit Wallet
Learn how to use the Debit/Credit Wallet API to adjust user wallet points, manage loyalty rewards, and effectively offer users real-time incentives.
Overview
The Debit/Credit Wallet API allows you to update the points in the user wallet by either debiting (subtracting) or crediting (adding) them. The wallet ledger balance is updated immediately after the transaction is processed.
This API provides flexibility for a range of scenarios where point adjustments are required for the user wallet as follows:
- Redeeming Wallet Points in Transactions: Enable users to redeem wallet points during transactions, providing them with a seamless way to utilize their loyalty rewards.
- Crediting Points to User Wallets: Add points to the user wallet as and when needed.
This API is essential for businesses managing customer loyalty programs. It allows you to instantly update loyalty balances based on user actions or rewards. For example, if a user earns 100 loyalty points after a purchase, the API instantly credits the points to their wallet. Later, if the user returns the item, the API can debit the corresponding points, ensuring the loyalty balance remains accurate. By leveraging this API, businesses can enhance user experience and build trust through accurate and immediate loyalty point transactions.
Example Use Case
Consider an example user case where a user makes a purchase worth $200 and has a balance of 200 points in their wallet. You can use the Debit/Credit Wallet API to seamlessly redeem wallet points during this transaction as follows:
-
Determine Redemption Details: With a conversion rate of 1 point = $1, this redemption translates into a $50 discount.
-
Calculate Final Payable Amount: Apply the $50 discount to the purchase amount of $200. The userโs final payable amount is $150.
-
Invoke the Debit API: Invoke the Debit API to deduct the redeemed points from the user's wallet after completing the transaction successfully. Pass the transaction details, such as
walletId
,identity
, andpoints
to be debited (in this case, 50) in the API request. -
Update Wallet Ledger: Update the wallet balance to 150 points, ensuring the user wallet accurately reflects the redeemed points.
Example Credit Use Case
This above example illustrates a scenario specific to the Debit API. Consider an example where the current user balance is 200 points and earns 50 points after a transaction. In this case, the Credit API is invoked to add points to the user wallet, updating the wallet balance to 250 points.
Base URL
Here is an example base URL from the account in the India region
https://in1.api.clevertap.com/1/promo/creditDebit
Region
To identify the API endpoint for the region of your account, refer to Region.
Headers
For more information about API headers used while processing API requests, refer to Headers.
HTTP Method
POST
Query Parameters
Parameter | Description | Required/Optional | Type | Sample Value |
---|---|---|---|---|
identity | Identifies the user associated with the wallet. | Required | String | KMN@123 |
walletId | Unique identifier assigned to each user wallet within the application. | Required | String | wallet_123 |
Body Parameters
Parameter | Description | Required/Optional | Datatype | Sample Value |
---|---|---|---|---|
description | Description of the transaction. | Optional | String | Redemption for order |
points | Loyalty points value to be debited/credited. Only positive point values are accepted. Requests with negative points for debit or credit transactions are rejected. | Required | Numeric | 100 |
transactionType | Type of transaction. Valid values are:
| Required | String | DEBIT |
bucketType | Specifies the bucket where points are credited, either ACTIVE or PENDING . This applies only to credit transactions. If no value is provided, points are credited to the ACTIVE bucket by default. | Optional | String | PENDING or ACTIVE |
activationDuration | Specifies the time duration before points move from the Pending bucket to the Active bucket. This applies only to credit transactions. If the value is set to zero, the credit is applied immediately. The format is: Xw Xd Xh Xm, where: Xw Xd Xh Xm where:
| Optional | Number | 2d 3h |
expiryDuration | Specifies the expiry duration. This applies only to credit transactions. If not provided, the system defaults to the wallet-level expiry. The format is: Xw Xd Xh Xm where:
| Optional | Number | 1w 2d |
orderId | References the bill number to associate the transaction to a specific order ID for potential future refunds. This enables tracking transactions for return sales. | Optional | String | ORD12345 |
Debit Transactions Validation
If debit transactions exceed available active points, they are not processed to prevent overdrafts in the wallet.
Sample Request
Here is an example HTTP request to the Debit/Credit Wallet API, including the headers needed to authenticate the request:
POST /https://in1.api.clevertap.com/1/promo/creditDebit?walletId=1000&identity=User2 HTTP/1.1
Authorization: Basic {API Key: Secret Key}
Content-Type: application/json
The following are the request payloads for debit/credit transactions:
{
"description": "Reward points for purchase",
"points": 100,
"transactionType": "DEBIT",
"bucketType": "",
"expiryDuration": "",
"activationDuration": "",
"orderId": "order123"
}
{
"description": "Reward points for purchase",
"points": 100,
"transactionType": "CREDIT",
"bucketType": "PENDING",
"expiryDuration": "1d 10m",
"activationDuration": "3d",
"orderId": "order123"
}
Sample Response
The sample response returns the updated wallet balance and transaction details in the following format:
{
"status": "success",
"record": {
"walletId": 1000,
"activePoints":200,
"orderId": "order123",
"description": "points redeemed for a purchase",
"tnxId": "wl_YLKUlWbHU4MKySZhoGqLV",
"points": 100
}
}
On a successful API call, the system debits or credits the specified points from the user's wallet based on the transactionType
in the request body and returns a response indicating the updated wallet balance and transaction details.
Errors
To know the errors applicable to the Debit/Credit Wallet API, refer to API Error Cases.
Updated 21 days ago