Skip to main content
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"
  }'
Response (Valid)
{
  "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

CodeDescription
COUPON_NOT_FOUNDNon-existent coupon
COUPON_INACTIVEDeactivated coupon
COUPON_NOT_YET_VALIDBefore valid period
COUPON_EXPIREDExpired
USER_CODE_LIMITUser code usage limit exceeded
USER_PACKAGE_LIMITUser package usage limit exceeded
TOTAL_USAGE_LIMITTotal usage limit exceeded

Complete Flow Example (Node SDK)

import { PlayCampServer } from '@playcamp/node-sdk';

const server = new PlayCampServer('your_server_key:your_secret');

async function redeemCoupon(userId: string, couponCode: string) {
  // 1. Validate
  const validation = await server.coupons.validate({ couponCode, userId });

  if (!validation.valid) {
    return {
      success: false,
      error: validation.errorCode,
      message: validation.errorMessage,
    };
  }

  // 2. Redeem
  const result = await server.coupons.redeem({ couponCode, userId });

  // 3. Grant in-game rewards
  for (const reward of result.reward) {
    await giveItemToUser(userId, reward.itemId, reward.itemQuantity);
  }

  return { success: true, reward: result.reward };
}