This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x 72c0f8c12c feat(talent): wire recruiter placement/unlock revenue via Creem
The talent graph's recruiter monetization was designed (Opportunity → Pilot →
Proof funnel) but never wired to charge. This adds the placement/candidate-unlock
revenue engine on top of the existing talent graph, charged through Creem (a
merchant-of-record with Turkey-based-seller payout support — the portfolio
standard used by bidstage/CalDesk), not Polar/Stripe.

Revenue gate: a recruiter (opportunity owner) unlocks a matched candidate's
contact + full evidence. Gating mirrors the referral gate (owner-only, no
self-unlock, candidate must have real matching evidence). The fee is charged via
a Creem checkout whose custom_price is the exact computed fee, and settled by the
signed checkout.completed webhook, which records the entitlement + receipt.

- Fee math (pure, configurable): flat unlock access fee (TALENT_UNLOCK_FEE_CENTS,
  default $49) or a percentage placement success fee (rate + min/max clamps) when
  a placement amount is supplied.
- New TalentPlacement model + migration: entitlement/receipt with a compound
  unique key (opportunity, candidate, recruiter) for charge idempotency and a
  unique providerOrderId; provider defaults to creem.
- Creem adapter (createCreemCheckout) mirroring the reviewed bidstage lib/creem.ts,
  and a signed Creem webhook route (HMAC-SHA256, timing-safe) that settles
  placements. Amount is revalidated against the quoted fee before unlocking.
- Routes: POST/GET /talent-graph/opportunities/:id/unlocks and gated
  GET .../candidates/:candidateId/contact (402 until paid).
- Errors.paymentRequired (402) helper.
- Tests: fee math, gating, charge idempotency, and the signed webhook settlement
  path (75 tests). Secrets are env-only (CREEM_API_KEY, CREEM_WEBHOOK_SECRET,
  CREEM_PRODUCT_ID) — none committed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-26 21:31:07 +03:00

34 lines
1.5 KiB
SQL

-- Recruiter placement / candidate-unlock revenue entitlement + receipt.
-- Charged through the Creem adapter (merchant-of-record with Turkey payout
-- support), settled by the signed Creem checkout.completed webhook.
CREATE TABLE "TalentPlacement" (
"id" TEXT NOT NULL,
"opportunityId" TEXT NOT NULL,
"candidateId" TEXT NOT NULL,
"recruiterId" TEXT NOT NULL,
"feeCents" INTEGER NOT NULL,
"currency" TEXT NOT NULL DEFAULT 'usd',
"feeModel" TEXT NOT NULL DEFAULT 'unlock',
"status" TEXT NOT NULL DEFAULT 'pending',
"provider" TEXT NOT NULL DEFAULT 'creem',
"checkoutId" TEXT,
"providerOrderId" TEXT,
"paidAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "TalentPlacement_pkey" PRIMARY KEY ("id"),
CONSTRAINT "TalentPlacement_feeCents_check" CHECK ("feeCents" >= 0)
);
CREATE UNIQUE INDEX "TalentPlacement_providerOrderId_key" ON "TalentPlacement"("providerOrderId");
CREATE UNIQUE INDEX "TalentPlacement_opportunityId_candidateId_recruiterId_key" ON "TalentPlacement"("opportunityId", "candidateId", "recruiterId");
CREATE INDEX "TalentPlacement_recruiterId_status_idx" ON "TalentPlacement"("recruiterId", "status");
CREATE INDEX "TalentPlacement_candidateId_idx" ON "TalentPlacement"("candidateId");
CREATE INDEX "TalentPlacement_status_idx" ON "TalentPlacement"("status");
ALTER TABLE "TalentPlacement"
ADD CONSTRAINT "TalentPlacement_opportunityId_fkey"
FOREIGN KEY ("opportunityId") REFERENCES "TalentOpportunity"("id")
ON DELETE CASCADE ON UPDATE CASCADE;