Validating and redeeming creator coupon codes
Redeem coupon codes distributed by creators.
Flow
1. Enter coupon code → 2. Validate → 3. Redeem coupon → 4. Grant rewards
Validate Coupon
Check if the coupon is valid before use.Request
curl -X POST "https://sandbox-sdk-api.playcamp.io/v1/server/coupons/validate" \
-H "Authorization: Bearer ak_server_xxx:secret" \
-H "Content-Type: application/json" \
-d '{
"couponCode": "CREATOR-ABC12-001",
"userId": "user_12345"
}'{
"data": {
"valid": true,
"couponCode": "CREATOR-ABC12-001",
"reward": [
{ "itemId": "gem", "itemQuantity": 100 }
],
"packageName": { "ko": "Welcome Package", "en": "Welcome Package" },
"creatorKey": "ABC12",
"campaignId": "campaign_001"
}
}Response (Invalid)
{
"data": {
"valid": false,
"couponCode": "INVALID-CODE",
"errorCode": "COUPON_NOT_FOUND",
"errorMessage": "Coupon not found"
}
}Redeem Coupon
Actually use the coupon after validation.Request
curl -X POST "https://sandbox-sdk-api.playcamp.io/v1/server/coupons/redeem" \
-H "Authorization: Bearer ak_server_xxx:secret" \
-H "Content-Type: application/json" \
-d '{
"couponCode": "CREATOR-ABC12-001",
"userId": "user_12345"
}'Response (200 OK)
{
"data": {
"success": true,
"usageId": 5678,
"couponCode": "CREATOR-ABC12-001",
"reward": [
{ "itemId": "gem", "itemQuantity": 100 }
],
"packageName": { "ko": "Welcome Package" },
"creatorKey": "ABC12",
"campaignId": "campaign_001",
"redeemedAt": "2024-01-15T10:30:00.000Z"
}
}Error Codes
| Code | Description |
|---|---|
COUPON_NOT_FOUND |
Non-existent coupon |
COUPON_INACTIVE |
Deactivated coupon |
COUPON_NOT_YET_VALID |
Before valid period |
COUPON_EXPIRED |
Expired |
USER_CODE_LIMIT |
User code usage limit exceeded |
USER_PACKAGE_LIMIT |
User package usage limit exceeded |
TOTAL_USAGE_LIMIT |
Total usage limit exceeded |
Complete Flow Example (Node.js)
async function redeemCoupon(userId: string, couponCode: string) {
// 1. Validate
const response = await sdk.validateCoupon({ couponCode, userId });
const validation = response.data;
if (!validation.valid) {
return {
success: false,
error: validation.errorCode,
message: validation.errorMessage
};
}
// 2. Redeem
const redeemResponse = await sdk.redeemCoupon({ couponCode, userId });
const result = redeemResponse.data;
// 3. Grant in-game rewards
for (const reward of result.reward) {
await giveItemToUser(userId, reward.itemId, reward.itemQuantity);
}
return { success: true, reward: result.reward };
}