External Discount Codes
Overview
External Discount Codes allow you to create discounts dynamically through APIs without pre-configuring discount codes in the admin portal. This feature is perfect for programmatic discount management, API integrations, and dynamic pricing strategies.Key Features
- ✅ Dynamic Creation: No need to pre-create discount codes in the admin portal
- ✅ API-Based: Create discounts programmatically via Merchant API or User API
- ✅ Flexible Types: Support both fixed amount and percentage discounts
- ✅ One-time or Recurring: Choose between single-use or recurring discounts
- ✅ Automatic Code Generation: System automatically generates unique discount codes
- ✅ Metadata Support: Attach custom metadata for tracking and analysis
When to Use External Discount Codes
Perfect for:- API Integrations: Third-party systems that need to apply discounts automatically
- Dynamic Pricing: Real-time price adjustments based on user attributes or market conditions
- Personalized Offers: Custom discounts for specific users without creating codes in advance
- A/B Testing: Test different discount strategies programmatically
- Promotion Automation: Automated discount creation based on business rules
- Public Marketing Campaigns: Use Standard or Batch discount codes instead
- Checkout Page: Checkout API doesn’t support external discounts (use pre-created codes)
- Bulk Tracking: When you need to track usage across many customers
External vs Internal Discount Codes
Quick Comparison
| Feature | Internal Discount Codes | External Discount Codes |
|---|---|---|
| Creation Method | Admin portal | API only |
| Pre-configuration | Required | Not needed |
| Code Format | Custom name | Auto-generated (excode_*) |
| Reusability | Can be reused | Single-use (per user) |
| Usage Limits | Supported | Not supported |
| API Support | All APIs | Merchant & User API only |
When to Choose Which
Use Internal Discount Codes when:- Creating public marketing campaigns
- Need usage limits and restrictions
- Want customers to enter codes manually
- Need to track bulk usage
- Integrating with third-party systems
- Need programmatic discount creation
- Providing personalized offers
- Dynamic pricing requirements
API Support
Supported APIs
| API | External Discount Support | Notes |
|---|---|---|
| Merchant API | ✅ Full support | Complete external discount functionality |
| User API | ✅ Full support | Complete external discount functionality |
| Checkout API | ❌ Not supported | Only supports pre-created internal discount codes |
⚠️ Important: Checkout API doesn’t support external discounts. If you need discounts on checkout pages, pre-create discount codes in the admin portal and use the discountCode parameter.
How External Discounts Work
Automatic Code Generation
When you create an external discount via API, the system automatically:- Generates a unique discount code (format:
excode_{merchantId}_{userId}_{source}_{timestamp}{random}) - Creates the discount with your specified rules
- Activates the discount immediately
- Applies it to the subscription or purchase
Discount Parameters
When creating an external discount, you specify:| Parameter | Type | Description | Example |
|---|---|---|---|
| recurring | boolean | One-time or recurring discount | false = one-time |
| discountAmount | integer | Fixed discount amount (in cents) | 1000 = $10.00 |
| discountPercentage | integer | Percentage discount (100 = 1%) | 2000 = 20% |
| cycleLimit | integer | Number of billing cycles (recurring only) | 3 = 3 months |
| endTime | integer | Expiration time (Unix timestamp, recurring only) | 1767225599 |
| metadata | object | Custom metadata for tracking | {"campaign": "summer_sale"} |
Usage Scenarios
Scenario 1: First Order Discount (One-time)
Give new customers a 20% discount on their first purchase. Example:Scenario 2: Recurring Discount (First 3 Months)
Offer 15% off for the first 3 billing cycles. Example:Scenario 3: VIP Lifetime Discount
Provide permanent 10% discount for VIP customers. Example:Scenario 4: Time-Limited Campaign
Offer 25% discount until end of year. Example:Creating External Discounts
Subscription Creation
When creating a subscription via API, include thediscount parameter:
Merchant API: POST /api/merchant/subscription/create_submit
Subscription Update
Apply discount when upgrading or downgrading a subscription: Merchant API:POST /api/merchant/subscription/update_submit
Subscription Renewal
Apply discount during subscription renewal: Merchant API:POST /api/merchant/subscription/renew
Discount Parameters Explained
Fixed Amount vs Percentage
Fixed Amount (discountAmount):
- Use when you want a specific dollar amount off
- Example: “$10 off” regardless of order total
- Best for: Consistent promotional offers
discountPercentage):
- Use when you want a percentage off
- Format:
100 = 1%,1000 = 10%,10000 = 100% - Best for: Scaling discounts with order value
⚠️ Priority: If both are specified, discountAmount takes priority.
One-time vs Recurring
One-time (recurring: false):
- Discount applies only to the first invoice
- Perfect for: Welcome offers, sign-up bonuses
- Cannot use
cycleLimitorendTime
recurring: true):
- Discount applies to multiple billing cycles
- Perfect for: Long-term promotions, VIP discounts
- Can use
cycleLimitorendTimeto control duration
Cycle Limit
What it does: Limits how many billing cycles the discount applies Examples:cycleLimit: 1- First cycle onlycycleLimit: 3- First 3 cyclescycleLimit: 0- No limit (untilendTimeor subscription ends)
recurring: true
End Time
What it does: Sets expiration date for the discount Format: Unix timestamp (seconds since Jan 1, 1970) Example:recurring: true
Metadata
What it does: Stores custom information about the discount Use cases:- Track discount source
- Store campaign information
- Record business logic tags
- Enable reporting and analytics
Best Practices
1. Always Preview Before Submitting
Use the preview API to check discount calculations before finalizing:2. Choose the Right Discount Type
Use Fixed Amount when:- Offering consistent dollar-off promotions
- Order values vary significantly
- Need precise control over discount amount
- Discount should scale with order value
- Running percentage-based campaigns
- Want simpler calculation
3. Set Appropriate Limits
Cycle Limit Guidelines:- Short-term: 1-3 cycles
- Quarterly: 3 cycles
- Semi-annual: 6 cycles
- Annual: 12 cycles
- Unlimited: 0 (use carefully)
4. Use Metadata Effectively
Track important information in metadata:- Campaign name
- Discount source
- User segment
- Business reason
5. Handle Errors Properly
Common errors to handle:- Invalid discount percentage (must be 0-100%)
- Missing required parameters
- Invalid time settings
- Conflicting discount types
Validation Rules
Required Parameters
You must specify at least one discount type:- ✅
discountAmountOR - ✅
discountPercentage
Discount Percentage
Valid range: Greater than 0 and less than or equal to 10000100= 1%1000= 10%10000= 100%
- ❌
0- Cannot be zero - ❌
15000- Cannot exceed 100%
Discount Amount
Must be: Greater than 0 (in cents) Automatically limited: System won’t allow discount to exceed order totalRecurring Discount Rules
cycleLimit:- Only valid when
recurring: true - Must be greater than or equal to 0
0= unlimited (untilendTimeor subscription ends)
- Only valid when
recurring: true - Must be a future time (Unix timestamp)
- Must be greater than or equal to current time
Common Use Cases
Use Case 1: API Integration Discount
Third-party system automatically applies discount based on user tier:Use Case 2: Dynamic Pricing
Adjust price based on market conditions or user behavior:Use Case 3: Win-Back Campaign
Offer discount to win back churned customers:Limitations and Considerations
Checkout API Restriction
Important: Checkout API does NOT support external discounts. If you need discounts on checkout pages:- Option 1: Pre-create discount codes in admin portal, then use
discountCodeparameter - Option 2: Use Merchant API or User API instead of Checkout API
Single User Only
External discounts are created per user/subscription:- Cannot be shared across multiple users
- Cannot set usage limits (quantity limits)
- Each discount is user-specific
Cannot Combine with Internal Codes
If bothdiscountCode (internal) and discount (external) are provided:
- External discount takes priority
- Internal discount code is ignored
Troubleshooting
Error: “one of discountAmount or discountPercentage should specified”
Problem: Missing discount type specification Solution: Provide eitherdiscountAmount or discountPercentage
Error: “invalid discountPercentage”
Problem: Percentage out of valid range (0-10000) Solution: Use valid percentage valueError: “cycleLimit not available as recurring not enable”
Problem: Trying to set cycle limit without enabling recurring Solution: Setrecurring: true or remove cycleLimit
Error: “endTime not available as recurring not enable”
Problem: Trying to set end time without enabling recurring Solution: Setrecurring: true or remove endTime
Related Topics
- Discount Code Introduction - Overview of all discount types
- Standard Discount Codes - Creating discount codes in admin portal
- Batch Discount Codes - Bulk discount code generation

