Part 11 - Build Secure QR Code Redemption After Stripe Payment
Learn how to turn a confirmed Stripe payment into a secure, one-time QR redemption pass for merchant product collection.
Build Secure QR Code Redemption After Stripe Payment
A QR code can give a customer a convenient way to collect a product after paying with Stripe. However, the QR code must not be treated as proof of payment by itself.
The server must verify the payment status before allowing redemption.
The QR code is a secure redemption pass. Stripe remains the source of truth for payment, while the application remains responsible for the order, token, merchant, and redemption state.
The basic workflow
Customer pays with Stripe
↓
Stripe confirms payment through a webhook
↓
Server marks the order as paid
↓
Server creates a one-time redemption token
↓
System generates or displays a QR code
↓
Customer shows the QR code to the merchant
↓
Merchant scans the QR code
↓
Server validates and marks the redemption as used
The customer returning to a Stripe success page is not enough. A browser redirect can be interrupted, repeated, or manipulated. The backend should create a redeemable pass only after it receives and verifies the appropriate Stripe webhook.
What the QR code represents
| Item | Responsibility |
|---|---|
| Stripe | Confirms whether the payment succeeded, failed, or was later refunded |
| Backend | Connects the payment to the order and creates the redemption record |
| QR code | Carries a random reference to the redemption record |
| Merchant scanner | Requests validation and confirms product collection |
| Database | Stores payment, redemption, merchant, and audit state |
The QR code is a pointer to a server-side record, not a receipt containing all the facts needed to approve collection.
Three practical implementation options
Option 1: Integrate with the merchant's existing POS
This option uses the merchant's current point-of-sale system.
| Question | Why it matters |
|---|---|
| Does the POS provide an API? | Determines whether an integration is possible |
| Can it create vouchers or redemption tokens? | Shows whether it can own the redemption record |
| Can it accept an external payment reference? | Links Stripe payment to the POS order |
| Can it send redemption status back? | Keeps both systems synchronised |
| Can it prevent a second redemption? | Protects against reuse |
Existing POS workflow
- Ask the POS provider for its API and voucher documentation.
- Create or identify the POS order.
- Connect the Stripe payment reference to that order.
- Obtain the POS redemption reference or QR code.
- Show the reference to the customer.
- Let the merchant scan it with the existing POS device.
- Receive and store the redemption status.
This is attractive when the merchant already has a reliable POS process. The main challenge is that every POS provider has different APIs, identifiers, authentication, and redemption rules.
Option 2: Build an independent redemption system
If the merchant has no QR system, the business can provide one.
| First-version capability | Purpose |
|---|---|
| One merchant | Keeps onboarding and permissions simple |
| One Stripe account | Avoids marketplace complexity |
| One paid order | Defines the first redemption boundary |
| One QR code | Supports one product collection pass |
| One-time redemption | Prevents repeated collection |
| Merchant scanning page | Works on a normal phone with an internet connection |
| Redemption history | Provides an audit trail |
The QR code could open a link such as:
https://example.com/redeem/secure-random-token
The token should be:
- Unique and generated with a cryptographically secure random generator.
- Difficult to guess and not based on a predictable order number.
- Connected to the correct order and merchant.
- Usable only once.
- Expirable when the business needs an expiry policy.
The QR code must not contain card details, Stripe secret keys, full personal information, or the product price as the only proof of payment.
Option 3: Use a voucher or coupon model
The system can describe the redemption pass as a digital voucher. The QR code simply opens the voucher.
| Voucher field | Example |
|---|---|
| Voucher number | MUG-7F3A |
| Product | Printed ceramic cup |
| Quantity | 1 |
| Merchant | MugMori |
| Expiry date | 30 September 2026 |
| Redemption status | Available, redeemed, cancelled, or expired |
Scanning the QR code only opens or displays the voucher. It does not redeem the voucher by itself. Redemption happens only after an authenticated merchant reviews the voucher and confirms collection.
Customer or merchant scans QR
↓
Voucher page opens with status: Available
↓
Merchant reviews product and quantity
↓
Merchant selects “Confirm collection”
↓
Server validates payment, merchant, expiry, and status
↓
Server atomically changes the status to Redeemed
This model works well for food and drinks, event tickets, product collection, gift vouchers, promotional items, and prepaid services. A scan or preview must never consume the voucher; only the server-confirmed merchant action changes its status.
Recommended starting approach
Start with Option 2: an independent QR redemption system.
| Phase | Scope |
|---|---|
| 1 | One merchant, one Stripe account, and one paid order |
| 2 | One-time product collection through a merchant web page |
| 3 | Refund, cancellation, expiry, and redemption history rules |
| 4 | Merchant dashboard and scanning workflow |
| 5 | POS integrations one provider at a time |
| 6 | Multi-merchant marketplace support later |
This keeps the business rules under the application's control and avoids beginning with a different POS integration for every merchant.
Payment confirmation workflow
The customer can pay through Stripe Checkout or a PaymentIntent. The server should wait for a confirmed Stripe webhook, such as checkout.session.completed or payment_intent.succeeded, as appropriate for the payment flow.
1. Customer starts checkout
2. Backend creates the trusted order total
3. Stripe processes the payment
4. Stripe sends a signed webhook to the backend
5. Backend verifies the webhook signature
6. Backend confirms the payment and order match
7. Backend marks the order as paid
8. Backend creates one redemption record
9. Backend generates the QR link
10. Customer can view or receive the QR code
The webhook handler should be idempotent. If Stripe retries the same event, the handler must not create a second redemption pass.
Merchant scanning workflow
The merchant needs an authenticated scanning page or dashboard. For the first version, require an internet connection during redemption.
Merchant scans QR
↓
Backend receives the token
↓
Token exists and is valid?
↓ yes
Payment succeeded and order is not cancelled or refunded?
↓ yes
Token belongs to this merchant and is unused?
↓ yes
Show product and quantity
↓
Merchant confirms collection
↓
Atomically mark redemption as redeemed
↓
Show “Redeemed” and record the event
The server should validate all of these conditions:
- The token exists.
- The payment succeeded.
- The token belongs to the scanning merchant.
- The token has not already been redeemed.
- The order is not cancelled or refunded.
- The token has not expired.
- The product and quantity match the order.
- The redemption update is atomic so two scans cannot both succeed.
After a successful redemption, scanning the same QR code again should show:
Already redeemed
Suggested database records
The first version can use the existing Django database and models. FastAPI or Django can expose the workflow, but the application should not create a second database or duplicate payment records.
| Record | Important fields |
|---|---|
| Merchant | Name, provider, provider account reference, status |
| Order | Merchant, product, quantity, total, status |
| Payment | Order, provider payment ID, amount, status, event ID |
| Redemption | Order, merchant, secure token, status, created time, redeemed time |
| RedemptionEvent | Redemption, action, actor, timestamp, reason |
Possible redemption statuses are available, redeemed, cancelled, and expired.
Keep provider secret keys, card numbers, CVV values, and bank login credentials out of the database. Store secrets in server-side environment configuration and store only safe provider references.
Failure cases and responses
| Failure | Safe response |
|---|---|
| Payment failed | Do not create a redeemable pass |
| Webhook is duplicated | Return success without creating another pass |
| Payment is refunded | Cancel the pass or block redemption according to policy |
| Payment is disputed | Flag the order for review and avoid automatic approval if required |
| QR code was already used | Show “Already redeemed” and keep the original audit record |
| QR code expired | Show an expiry message and direct the customer to support |
| Wrong merchant scans | Reject the scan without revealing unnecessary order details |
| Partial redemption is needed | Add quantity-level redemption rules before enabling it |
| Customer loses the QR code | Authenticate the customer and allow the server to re-display the same pass |
| Merchant loses internet access | Require online redemption in version one |
| POS integration is unavailable | Keep the independent redemption record and flag the integration error |
Offline redemption is much harder because two devices could approve the same token before either one can contact the server. Online validation is the safer first release.
Security checklist
- Verify Stripe webhook signatures.
- Use HTTPS for customer and merchant pages.
- Generate tokens with a secure random generator.
- Never use sequential order numbers as redemption secrets.
- Do not put payment credentials in QR data.
- Require merchant authentication before scanning or confirming.
- Check merchant ownership on every redemption request.
- Make the redemption update atomic and one-time.
- Record redemption events for support and dispute investigation.
- Apply rate limits to token lookup and scan endpoints.
- Return general error messages that do not leak private customer information.
Final recommendation
Build a small independent redemption system first. Start with one verified merchant, one Stripe account, one paid order, one QR code, and one-time online redemption through a merchant web page.
The payment and redemption boundaries should remain clear:
| Boundary | Source of truth |
|---|---|
| Payment succeeded | Stripe webhook verified by the backend |
| Order contents and quantity | Backend order record |
| Who may redeem | Merchant ownership and authentication |
| Whether the pass is unused | Redemption record and atomic update |
| What happened | Redemption event history |
Once these rules work reliably, add refunds and cancellation policies, then integrate POS providers one by one. Multi-merchant support can come later after onboarding, settlement, and permission requirements are understood.