Repository navigation
feat: credit codes and invites (store credit pays for rented numbers) - #110
Merged
Merged
Conversation
- @profullstack/redeem-credits 0.2: unit usd_cents = store credit. "Have a code?" on Settings, POST /api/v1/redeem, GET /api/v1/credits. - Store credit pays for a rental or renewal as payment method CREDIT: the same number_orders row and pending -> paid -> provision transition the CoinPay webhook runs, no parallel flag. Refunded if provisioning gives up. - @profullstack/affiliates 0.2: 3 invites per account (/invites, /i/<code>). A new account that confirms its email with a signup profile spends the invite and both people get $2.50. ?ref= reads the existing referral_code cookie; old referral codes come back external and are not counted twice. - MCP: redeem_code, credit_balance, list_invites, create_invite; CLI 1.7.0: redeem, credits, invites, rent/renew --credit. scripts/mint-credit-code.mjs. - Migrations 017_redeem_credits.sql + 018_affiliates.sql (applied by hand). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ThreatCrush Security Scan12 finding(s) HIGH/CRITICAL: 2 | MEDIUM: 4 | LOW: 6
Snippets are redacted; ThreatCrush never prints matched credential material. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
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.
Credit code redemptions and invite/affiliate links (fleet rollout, batch 1).
What a code grants:
@profullstack/redeem-creditsunitusd_cents= store credit toward rented numbers ($5/mo). Redeem on Settings ("Have a code?"),POST /api/v1/redeem, CLIsmshub-cli redeem, MCPredeem_code.How credit pays for a rental: payment method
CREDIT(chain field onPOST /api/v1/numbers/ordersand/numbers/{id}/renew; "Pay with store credit" / "Renew with credit" on /numbers;rent --credit).createOrderchecks the balance (402 if short, no order opened), inserts the normalnumber_ordersrow with chainCREDIT, spends the credit (credit_append_if_versionCAS, so parallel orders cannot overdraw), then runs the samepending -> paidclaim +provision()the CoinPay webhook runs (extracted asclaimAndProvision). A renewal extendsphone_numbers.expires_atexactly like a paid renewal. If provisioning gives up for good (statusfailed), the credit is granted back (refund:order:<id>). The whole order must be covered by credit (no split payments).Invites:
@profullstack/affiliates, 3 per account at/invites(APIGET/POST /api/v1/invites, CLIinvites [new], MCPlist_invites/create_invite)./i/<code>sets a 7-day cookie and lands on /register, which says what the invite gives and also stores the code in signup metadata. On/auth/callbacka new account (under 7 days old) with a confirmed email and a signup profile (smshub's signup checks) spends the invite, and both people get $2.50 of credit, so two accepted invites pay for a month. Unconfirmed, profile-less, old accounts and self-invites spend nothing.?ref=: first touch on new accounts via
refFromRequest= the existingreferral_codecookie set bytrackReferralCode; codes from the oldreferral_codestable come backexternaland are not recorded, so a sign-up is never counted twice.DB:
017_redeem_credits.sql,018_affiliates.sqlcopied from the packages (RLS on, no policies, service_role only); applied by hand on dev2 before merge, after apg_dump -n publicbackup.Minting:
scripts/mint-credit-code.mjs --usd 10 --label "for Kim"with the app env.Tests:
src/lib/__tests__/rewards.test.ts(codes, quota, invite accepted once with both sides credited, checks, cookie vs metadata, ref first touch + external),src/lib/managed-numbers/__tests__/credit-orders.test.ts(402 when short, credit order provisions with no CoinPay call, renewal, refund on final failure). 317 pass; typecheck clean;next buildpasses.🤖 Generated with Claude Code