Principle:A616567126 GPT WEB JAVA Card Key Redemption
| Knowledge Sources | |
|---|---|
| Domains | Payments, Billing |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Mechanism that allows users to redeem randomly generated card keys (vouchers) for platform credits, providing an alternative payment method to direct gateway payments.
Description
Card key redemption is a prepaid voucher system where an administrator generates batches of unique card keys, each carrying a credit value. Users redeem these keys to increase their credit balance. The system prevents double-redemption by marking keys as used and tracking which user redeemed each key.
This repository implements card key generation via PasswordUtil.getRandomPassword() and redemption through both the web API (OrderServiceImpl.cardPin()) and WeChat bot (WxOutServiceImpl.exchange()). The WeChat Pay flow also generates card keys automatically on successful payment, sending them to the user via WeChat kefu message.
Usage
Use this principle when:
- Offering prepaid credit vouchers as a payment alternative
- Generating card keys in bulk for distribution
- Supporting multiple redemption channels (web, WeChat bot)
Theoretical Basis
Redemption Flow:
# Abstract algorithm (NOT real implementation)
def redeem_card_pin(user, pin_code):
# Check if already redeemed in this batch
if already_redeemed(user, pin_code):
raise DuplicateRedemptionError()
# Look up card pin
card = db.find_by_pin(pin_code)
if card is None or card.state == USED:
return InvalidPinError()
# Update user credits
user.remaining_credits += card.number
card.state = USED
card.user_id = user.id
save(user, card)
Key Properties:
- Random generation:
PasswordUtil.getRandomPassword()generates unique keys - Batch prevention:
checkUseBatchCardPin()prevents double-redemption within same batch - State tracking: Each card pin has
state(0=unused, 1=used) anduserId - Auto-generation on payment: WeChat Pay callback generates a card pin with value based on payment tier (100/220/1500 credits)
Practical Guide
The repository implements this in CardPinServiceImpl and OrderServiceImpl:
CardPinServiceImpl.add(CardPinAddReq)— generates batch of random card pins with specified credit valueCardPinServiceImpl.add(Integer number)— generates a single card pin (used by WeChat Pay callback)OrderServiceImpl.cardPin(CreatePinOrderReq)— redeems a card pin via web API, checks batch duplicationWxOutServiceImpl.exchange()— redeems a card pin via WeChat bot command "兑换-XXXX"OrderServiceImpl.wxCallBack()— on WeChat Pay success, auto-generates card pin and sends via kefu message