Skip to content

Conversation

@ucjonathan
Copy link
Contributor

Summary

Adds large batch coupon code generation samples across all 7 supported languages (Ruby, JavaScript, TypeScript, Python, PHP, Java, C#). These samples demonstrate how to generate up to 100,000 coupon codes by calling the API repeatedly in batches of 1,000 codes.

Features

  • Command line arguments: merchant_code (required), total_codes (default: 10,000), output_file (optional)
  • Coupon lookup: Uses getCouponByMerchantCode() API to resolve merchant code to coupon OID
  • Batch processing: Generates codes in batches of 1,000 (API limit per request)
  • Safeguards: Maximum 100,000 codes per application run
  • Rate limiting: 750ms delay between batches to avoid API throttling
  • CSV export: Saves all generated codes with timestamps and batch numbers
  • Progress tracking: Real-time console output showing batch progress
  • Error handling: Retry logic with exponential backoff on API failures
  • Summary statistics: Total codes, time elapsed, average per batch

Usage Examples

Ruby

ruby coupon/generate_coupon_codes_batch.rb 10OFF 2500 output.csv

Python

PYTHONPATH=. python coupon/generate_coupon_codes_batch.py 10OFF 2500 output.csv

JavaScript

NODE_TLS_REJECT_UNAUTHORIZED=0 node coupon/generateCouponCodesBatch.js 10OFF 2500 output.csv

TypeScript

NODE_TLS_REJECT_UNAUTHORIZED=0 ts-node coupon/GenerateCouponCodesBatch.ts 10OFF 2500 output.csv

PHP

php coupon/generateCouponCodesBatch.php 10OFF 2500 output.csv

Java

java -cp target/sdk_samples-1.0-SNAPSHOT.jar coupon.GenerateCouponCodesBatch 10OFF 2500 output.csv

C#

bin/Debug/SdkSample.exe GenerateCouponCodesBatch 10OFF 2500 output.csv

Files Added

  • ruby/coupon/generate_coupon_codes_batch.rb
  • python/coupon/generate_coupon_codes_batch.py
  • javascript/coupon/generateCouponCodesBatch.js
  • typescript/coupon/GenerateCouponCodesBatch.ts
  • php/coupon/generateCouponCodesBatch.php
  • java/src/coupon/GenerateCouponCodesBatch.java
  • csharp/coupon/GenerateCouponCodesBatch.cs

Testing Recommendations

For each language, test with:

  1. Small batch (100 codes = 1 batch) to verify basic functionality
  2. Medium batch (2,500 codes = 3 batches) to verify batching and delays
  3. Default (10,000 codes = 10 batches) to verify full workflow
  4. Error cases (invalid merchant code, invalid total_codes values)
  5. Verify CSV output format and contents

CSV Output Format

code,generated_at,batch_number
ABCD1234,2026-01-09T12:30:45Z,1
EFGH5678,2026-01-09T12:30:45Z,1
IJKL9012,2026-01-09T12:30:46Z,2

🤖 Generated with Claude Code

ucjonathan and others added 7 commits January 9, 2026 13:07
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ucjonathan ucjonathan assigned ucjonathan and perrytew and unassigned ucjonathan Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants