Skip to content

Fix AFFILIATE-REF-V1: ?ref= attribution + NICK30 auto-apply on signup#232

Open
bmoss2015 wants to merge 2 commits into
mainfrom
fix/affiliate-ref-nick30
Open

Fix AFFILIATE-REF-V1: ?ref= attribution + NICK30 auto-apply on signup#232
bmoss2015 wants to merge 2 commits into
mainfrom
fix/affiliate-ref-nick30

Conversation

@bmoss2015

Copy link
Copy Markdown
Owner

Summary

  • Signup page reads ?ref= on mount, normalizes (uppercase, 32-char cap, [A-Z0-9_-]), persists in sessionStorage so landing -> signup nav keeps the ref
  • Signup action sets affiliate_ref on Stripe Checkout Session metadata AND the subscription metadata (so renewals attribute too)
  • When the ref maps to a known coupon (NICK30 -> coupon id NICK30), Checkout switches to discounts: [{ coupon }] so the discount auto-applies (no manual code entry)
  • New script scripts/create-affiliate-coupons.mjs creates the coupon + promotion code in Stripe (idempotent, run once per environment)
  • Neutral Discount Applied chip on the signup form when a ref is present

No affiliate dashboard. Attribution lives in Stripe metadata only.

To activate

  1. Set STRIPE_SECRET_KEY in env or .env.local
  2. node scripts/create-affiliate-coupons.mjs (run against test mode first, then prod)
  3. Send affiliates to https://app.nextsurplus.com/signup?ref=NICK30

Test plan

  • Visit preview /signup?ref=NICK30, confirm the Discount Applied chip renders
  • Navigate away, return to /signup without ref, confirm chip still renders (sessionStorage)
  • Submit signup, confirm Stripe Checkout shows -30% discount pre-applied
  • Visit /signup?ref=FAKEXX, confirm form still allows manual promo code entry (no chip)
  • After checkout completes, inspect the Stripe Customer/Subscription metadata for affiliate_ref
  • Login: info@mossyland.com / Anderson1028!$

- signup page (page.tsx): reads ?ref= on mount, normalizes (uppercase,
  32 char cap, /[A-Z0-9_-]/), persists in sessionStorage so landing
  -> /signup nav doesn't drop the ref. Passes ref to the signUp action
  and renders a neutral Discount Applied chip when present.
- signup _actions.ts: accepts ref, sets `affiliate_ref` on both the
  Checkout Session metadata AND the subscription metadata so Stripe
  reports attribute the org for the life of the subscription. When the
  ref maps to a known coupon (NICK30 -> coupon id NICK30), swaps
  allow_promotion_codes out for discounts:[{coupon}] so the discount
  auto-applies. Unknown refs are still recorded in metadata but
  fall back to the manual promo code entry.
- scripts/create-affiliate-coupons.mjs: one-time idempotent Stripe call
  that creates the NICK30 coupon (30% off, repeating 12 months) + a
  matching promotion code. Reads STRIPE_SECRET_KEY from env or
  .env.local. Run with `node scripts/create-affiliate-coupons.mjs`
  against test mode first, then prod.

No affiliate dashboard yet; attribution lives entirely in Stripe metadata.
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.

1 participant