AU Bespoke Presence

Custom Django & Python delivery for Australian SMEs and APAC — same stack as this showcase site.

Follow

Case study Updated 7 May 2026

Case Study: 8521 — E-Commerce Platform with Affiliate Discount Code Engine

Case Study: 8521 — E-Commerce Platform with Affiliate Discount Code Engine

Project Code: 8521
Category: E-Commerce Platform / Affiliate Marketing System
Status: Active (Port 8030)
Industry: Online Retail / Digital Commerce


1. Project Name

8521 Commerce — A full-featured e-commerce platform with an integrated multi-tier affiliate discount code engine, ECPay payment processing, and LINE social login, built for a Taiwanese online retailer selling courses and physical products.


2. Core Technology Stack

Layer Technology
Backend Framework Django 5.0+, Python 3
Database PostgreSQL
Admin UI django-baton, django-autocomplete-light
Authentication django-allauth + LINE Social Login
Payments ECPay (Taiwan payment gateway — credit card, ATM, convenience store)
Image Processing easy-thumbnails
Rich Content CKEditor
UI Components nested-inline, django-colorfield
Frontend Django Templates (RWD)
Hosting GCP / Docker (Port 8030)

Custom Apps Built:
basic (site configuration, company data) · product (product catalogue, variants, inventory) · classes (digital course management) · order (cart → checkout → order lifecycle) · member (customer accounts, purchase history) · promote (discount code engine, affiliate program)


3. The Challenge (The Problem)

Taiwanese e-commerce businesses selling a mix of physical products and digital courses face specific challenges that generic Shopify-style platforms handle poorly:

  1. Affiliate discount code complexity: When selling through KOL (Key Opinion Leader) affiliates and corporate partners, businesses need to issue unique discount codes per affiliate, track which sales originated from which code, enforce per-code usage limits, and calculate affiliate commissions — a logic set that standard "10% off" coupon systems cannot support.
  2. Dual product type management: Physical products (with inventory, shipping) and digital courses (with access management, no shipping) have fundamentally different fulfilment workflows. Managing them in one system without a purpose-built data model creates constant edge-case handling.
  3. Payment diversity: Taiwan's consumer payment preferences include credit cards, ATM bank transfers, and convenience store payment (FamiPay, ibon) — all of which must route through ECPay's API with appropriate callback handling for asynchronous payment confirmation.
  4. Duplicate discount code creation: Without deduplication logic, affiliate codes with similar patterns would be issued multiple times, causing commission attribution errors and promotional budget leakage.

4. The Solution (The Implementation)

Feature 1: Multi-Tier Affiliate Discount Engine

The promote app implements a sophisticated discount code engine documented in DISCOUNT_ALGORITHM_FIX.md and AFFILIATE_DISCOUNT_CODE_FIX.md. Each code carries: issuing affiliate identity, discount type (percentage/fixed), minimum order value, per-code usage limit, per-user usage limit, validity period, and product/category scope. The engine resolves discount stacking rules deterministically when multiple applicable codes could apply to a single cart. A deduplication algorithm (cleanup_duplicate_discount_codes.py) actively prevents commission attribution conflicts.

Feature 2: Unified Physical + Digital Product Management

The product app handles physical inventory with stock tracking, while the classes app manages digital course records with access control. Both product types feed into a single order workflow via a shared cart abstraction — the system correctly routes fulfillment for each type without the customer experiencing a different checkout flow. A single order can contain both a physical product and a course access licence.

Feature 3: ECPay Multi-Method Payment Integration

The platform integrates ECPay's full payment method suite, including asynchronous payment notifications (for ATM and convenience store payments where confirmation arrives hours after checkout). The order state machine correctly handles the pending → awaiting_payment → paid transition for each payment method, including the ATM expiry scenario where payment is not completed within the bank's window.

Feature 4: LINE Social Login & Member Ecosystem

The member app integrates LINE social login via django-allauth, matching Taiwan's social login preference where LINE accounts are near-universal. Member purchase history, saved addresses, and accumulated discount entitlements are all accessible in a responsive member centre.


5. Business Impact (The Result)

  • Affiliate channel scalability: The discount code engine enables the business to onboard dozens of affiliate partners with individualised tracking codes, usage limits, and commission structures — without any manual code management or spreadsheet reconciliation per affiliate.
  • Payment flexibility: Supporting credit card, ATM transfer, and convenience store payment captures a materially broader share of Taiwan's consumer market compared to card-only checkout.
  • Deduplication and budget integrity: The discount code deduplication logic prevents affiliate commission overpayment — a real financial exposure in volume affiliate programs.
  • Dual-product catalogue: The single-platform management of physical and digital products eliminates the operational overhead of maintaining separate systems for each category and the customer experience friction of separate checkout flows.
  • [Needs Manual Input]: Number of active affiliate codes, affiliate-attributed GMV, conversion rate improvements, average order value.

6. AI / Innovation Factor

  • Algorithm Documentation Discipline: The discount engine's resolution algorithm is documented in DISCOUNT_ALGORITHM_FIX.md with explicit edge case coverage — a software engineering practice that enables confident future modification and reduces the regression risk that commonly accompanies promotional pricing code.
  • AI-Assisted Debugging: The AI_CHANGES.md log records the iterative debugging process for the affiliate discount code fixes, demonstrating a development workflow where AI-assisted code review accelerated root cause identification for complex discount stacking bugs.
  • LINE-Native Commerce: LINE Social Login plus LINE Pay (where supported) creates a native LINE commerce loop — the platform exists inside the same application where Taiwanese consumers already spend the majority of their mobile communication time.
  • ECPay Async Webhook Handling: Correct handling of asynchronous payment callbacks (ATM transfer confirmed hours after checkout) requires careful state machine design — the implementation correctly prevents false "payment success" states and handles timeout/expiry gracefully.
  • [Needs Manual Input]: Any planned AI features for personalised product recommendations or affiliate performance analytics.

Document generated: 2026-05-03 | Maintained by Tom Lai / You Er Ta Mu She Ji