About This Article
We replaced the act of "using points" with a mechanism that "consumes points to issue a coupon, then receives a discount with that coupon." This article explains the technical architecture in detail.
Conversion Process Overview
System Integration
Input UI, result display, copy function
Process control, authentication verification, transactions
Shopify coupon creation API, POS point operation API
Processing Steps in Detail
Receive conversion request from customer, verify authentication
Get real-time balance via POS API, verify conversion eligibility
Create customer-specific coupon via Shopify Admin API
Deduct specified points from balance via POS API
Record issued coupon info in customer's metafield
Return coupon code and details to frontend
Step Details
Steps 1-2: Request Reception and Balance Check
Customer ID: 12345, Requested points: 500pt, Auth token: xxx
Token validity check → OK / Customer ID ownership check → OK
API call: GET /customers/12345/points → Balance 1250pt
Balance(1250) >= Requested(500) → OK / Minimum unit: 100pt → OK / Daily limit: 10000pt → OK
All checks passed
Step 3: Shopify Coupon Generation
Shopify Admin API call: Endpoint priceRules + discountCodes
Generated code example: 70934-AB12CD-500
Response: priceRuleId, discountCodeId, code
Step 4: POS Point Deduction
Important: Record reference information to track conversions
Step 5: Metafield Storage
Storage location: Customer's Shopify metafield (namespace: loyalty, key: coupons)
Uses: My page list display, usage tracking, cancellation reference
Transaction Design
Why Order Matters
Ideal order: 1. Create coupon → 2. Deduct points → 3. Save record
Rollback on Error
Note: Metafield save is "nice to have." If actuals (coupon and points) are correct, operations can cover it
API Call Implementation Points
Retry Strategy
Timeout Settings
Performance Considerations
Processing Time Breakdown
UX response: Show "Processing..." to customer with loading animation to improve perceived speed
Benefits of This Design
Reliability
- Optimized processing order minimizes error impact
- Rollback strategy prevents inconsistencies
- All processes logged for traceability
Maintainability
- Each step is independent and testable
- Easy to identify error causes
- Easily accommodates future features (point rate changes, etc.)