Skip to content

Land billing-core Phase 4: Stripe event and snapshot translation - #4

Merged
FlyOverCoderKY merged 3 commits into
mainfrom
cursor/billing-stripe-phase-4-6c7c
Aug 15, 2026
Merged

FlyOverCoderKY merged 3 commits into
mainfrom
cursor/billing-stripe-phase-4-6c7c

Conversation

@FlyOverCoderKY

@FlyOverCoderKY FlyOverCoderKY commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Phase 4 of Billing Core: @pegma/billing-stripe translates verified Stripe events and subscription snapshots into the Phase 1–3 ledger. The core stays provider-agnostic.

What landed

  • @pegma/billing-stripe (0.1.0, unpublished)
    • Maps Stripe subscription statuses onto LifecycleStatus (incomplete_expired → canceled; paused → unpaid so a same-second active cannot resurrect it)
    • translateStripeEvent takes a host-verified Event and writes event.id / event.created as the ledger watermark
    • translateStripeSubscription copies identifiers and derived state only — never card data, raw payloads, line items, or amounts
    • Checkout Session and Invoice objects translate only when they carry an expanded Subscription
    • createStripeSnapshotFetcher / createStripeBillingAdapter keep the vendor client behind retrieveSubscription
  • Signature verification stays with the host. This package never imports stripe, never calls Date.now(), and never processes a payment or resolves an entitlement
  • Named consumers of this translation are RetireGolden.org (Stripe subscriptions) and Exsimplify (Stripe Checkout today). Their private internals stay out of this tree

Tests cover:

  • Lifecycle mapping for every Stripe status, including extras and unknown names
  • Same-second rank: Stripe canceled vs active in both arrival orders, through decideLedgerApplication and ledger.apply
  • Snapshot fetch translation, including drift repair through ledger.reconcile
  • Data-boundary assertions on objects that still carry amounts and card fields
  • PaymentIntent / wrapper rejection: payment_intent.canceled does not write a pi_… subscription id; Checkout Session and Invoice objects with their own id + status unwrap the expanded Subscription

Review follow-up

5ab3c17 annotates the same-second rank loop so tsc does not treat the application decision as an implicit any.

fc488be restricts subscriptionRecord to a real Subscription (object === "subscription", or a discriminator-less sub_… retrieve). PaymentIntents and similar no longer become ledger events. Checkout Session / Invoice wrappers unwrap the expanded Subscription instead of matching on id + status.

Explicitly not in this PR

  • RetireGolden repo.js swap (Phase 5)
  • Payment processing, Checkout UI, webhook signature verification, entitlements, receipt dedup
  • Publish or tag

Plan status is Phase 4 in-tree, unpublished. Do not merge from this PR unless a reviewer asks. Do not publish or tag.

Local gate: pnpm run format:check, pnpm run check, pnpm test — 158 tests passed.

Open in Web Open in Cursor 

Phase 4 adapter maps verified Stripe events and subscription objects
onto LedgerEvent / snapshot fetches. The core stays provider-agnostic;
signature verification and host repo.js swaps stay out of this tree.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

Annotate the same-second rank loop so tsc does not treat the
application decision as an implicit any.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2472a89813

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/billing-stripe/src/index.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ab3c17. Configure here.

Comment thread packages/billing-stripe/src/index.ts Resolved
Drop the id+status fallback that treated PaymentIntents, Checkout
Sessions, and Invoices as subscriptions. Wrappers now unwrap an
expanded Subscription or return null.

Co-authored-by: Fly Over Coder <FlyOverCoder@gmail.com>
@FlyOverCoderKY
FlyOverCoderKY merged commit efc3c93 into main Aug 15, 2026
5 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the cursor/billing-stripe-phase-4-6c7c branch August 15, 2026 18:26
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.

2 participants