Fix AFFILIATE-REF-V1: ?ref= attribution + NICK30 auto-apply on signup#232
Open
bmoss2015 wants to merge 2 commits into
Open
Fix AFFILIATE-REF-V1: ?ref= attribution + NICK30 auto-apply on signup#232bmoss2015 wants to merge 2 commits into
bmoss2015 wants to merge 2 commits into
Conversation
- 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.
…react-hooks/set-state-in-effect lint rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
?ref=on mount, normalizes (uppercase, 32-char cap,[A-Z0-9_-]), persists insessionStorageso landing -> signup nav keeps the refaffiliate_refon Stripe Checkout Session metadata AND the subscription metadata (so renewals attribute too)NICK30-> coupon idNICK30), Checkout switches todiscounts: [{ coupon }]so the discount auto-applies (no manual code entry)scripts/create-affiliate-coupons.mjscreates the coupon + promotion code in Stripe (idempotent, run once per environment)No affiliate dashboard. Attribution lives in Stripe metadata only.
To activate
STRIPE_SECRET_KEYin env or.env.localnode scripts/create-affiliate-coupons.mjs(run against test mode first, then prod)https://app.nextsurplus.com/signup?ref=NICK30Test plan
/signup?ref=NICK30, confirm the Discount Applied chip renders/signupwithout ref, confirm chip still renders (sessionStorage)/signup?ref=FAKEXX, confirm form still allows manual promo code entry (no chip)affiliate_ref