Repository navigation
Conversation
This was referenced Dec 2, 2026
Contributor
|
This looks like the right fix for refunds and Stripe subscription webhooks failing on a real shop. #107 already adds the refundRequestId index, so after that lands this mainly needs the stripeCustomerId index. CI failed on the EmDash 1.1.0 starter typecheck, and this branch does not touch the starter, so I think that is a flake. Could you rerun that job? |
cavewebs
added a commit
that referenced
this pull request
Dec 3, 2026
## Bug From API version 2025-03-31, Stripe sends `current_period_start` and `current_period_end` on each subscription item instead of on the subscription. `upsertFromStripe` reads them from the subscription only, so on current API versions both are missing and fall back to "now". Found while testing a shop end to end: a subscription paid on 1 December showed "1 Dec → 1 Dec" in the admin, and the cancel-at-period-end dialog said "Access continues until" that same day, while Stripe would end it a month later. ## Fix In `upsertFromStripe` the period now comes from, in order: 1. the subscription item (with several items, the one whose period ends first, which is what the customer has paid up to); 2. the subscription's own fields, for older API versions; 3. the period already stored, if the event carries none; 4. "now", as before. The `StripeSubscription` type gains the item-level fields, and the top-level ones become optional. ## Tests New `packages/core/test/stripe-subscription-period.test.ts`, 4 tests, each through the real webhook route with a signed `customer.subscription.updated`: - the period on the item is stored; - the older API shape (period on the subscription) is still read; - with two items, the earlier end wins; - an event with no period keeps the stored one. 3 fail without the fix; the older-API test passes both ways, as intended. Full suite: core 364 pass (plus the 4 local `routing-response-adapter` failures: the EmDash patch isn't applied in a fresh worktree; they pass on CI), paystack 105, lite 144. Core typecheck and Biome lint clean. ## Compatibility No change for accounts on API versions before 2025-03-31. Nothing else reads the top-level fields. ## Review points - `upsertInvoiceFromStripe` also moves the period on `invoice.paid`, from `period_start` / `period_end`; that is untouched. - Not in this PR, but worth a look: on the same API versions Stripe also moved `invoice.subscription` under `invoice.parent.subscription_details.subscription`. I haven't checked how that affects `invoice.paid` handling here. **Works on a real store once #127 merges:** until `customers.stripeCustomerId` is indexed, `customer.subscription.*` webhooks fail before they reach this code. The code doesn't depend on #127 and merges on its own.
cavewebs
added a commit
that referenced
this pull request
Dec 3, 2026
#137) ## Bug The admin's Pause sets `pause_collection` at Stripe, but Stripe keeps the subscription's status `active`. `upsertFromStripe` stores Stripe's status as it is, so the row stays Active after the `customer.subscription.updated` webhook, and Resume, which the admin offers only for `paused` rows, never appears. Found while testing a shop end to end: once paused, a subscription couldn't be resumed from the admin. ## Fix An `active` or `trialing` subscription with `pause_collection` set is stored as `paused`. When collection resumes, Stripe clears `pause_collection` and the row goes back to Stripe's status. Other statuses (`past_due`, `unpaid`, `canceled`, …) are kept as Stripe sends them, so a payment problem isn't hidden behind "paused". ## Tests New `packages/core/test/stripe-subscription-paused.test.ts`, 4 tests, each through the real webhook route with a signed `customer.subscription.updated`: - active with `pause_collection` is stored as `paused`; - the same during a trial; - after a pause, an event with `pause_collection: null` sets it back to `active`; - `past_due` with `pause_collection` stays `past_due`. 3 fail without the fix; the `past_due` test passes both ways, as intended. Full suite: core 364 pass (plus the 4 local `routing-response-adapter` failures noted in the other PRs), paystack 105, lite 144. Core typecheck and Biome lint clean. ## Compatibility Only rows for paused Stripe subscriptions change. `paused` is already a `SubscriptionStatus` and the admin already offers Resume for it. ## Review points - Stripe's own `paused` status (a trial that ended with no payment method) is unchanged and still comes through as `paused`. - The admin list updates when the webhook arrives, not the instant Pause is clicked. Making it instant means storing Stripe's reply in `lifecycle.ts`, which #107 is changing, so it's left for later. **Works on a real store once #127 merges:** until `customers.stripeCustomerId` is indexed, `customer.subscription.*` webhooks fail before they reach this code. The code doesn't depend on #127 and merges on its own.
EmDash refuses a where on a field the collection doesn't index. customer.subscription.* webhooks find the local customer by stripeCustomerId, which wasn't indexed, so every paid Stripe subscription answered 500 and was never recorded. (refunds.refundRequestId had the same gap; emdashCommerce#107 indexed it.) An audit of every storage query, count and orderBy in core found no other gaps. The route harness now refuses non-indexed where, orderBy and count fields like EmDash does, so the refund tests and a new Stripe subscription webhook test catch these. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moset15
force-pushed
the
fix/index-refund-request-id
branch
from
December 5, 2026 22:53
cd991de to
394ffb2
Compare
Contributor
Author
|
Rebased onto main. #107 already indexes |
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.
EmDash refuses a
whereon a field the collection doesn't index.customer.subscription.createdandcustomer.subscription.updatedfind the local customer bystripeCustomerId, andcustomersdoesn't index that field. So on a real shop every paid Stripe subscription gets a 500 from the webhook: "Cannot query on non-indexed field 'stripeCustomerId'." Stripe keeps retrying, and the subscription is never recorded.The route test harness didn't enforce the rule, so the tests passed.
refunds.refundRequestIdhad the same gap; #107 indexed it, so this PR no longer touches refunds.I checked every storage
query,countandorderByin core, including dynamicwhereobjects.stripeCustomerIdis the only field still missing an index.Changes
customersindexes now includestripeCustomerId. This is a plain index, not a unique one, so existing rows can't break it.where,orderByandcounton a field the collection doesn't index, as EmDash does.checkout.session.completed,customer.subscription.createdandcustomer.subscription.updatedwebhooks.Checks
This should go in before the pending release (#120), which would otherwise ship with Stripe subscriptions unrecorded.
#138 builds on this index and fixes two more Stripe subscription bugs from the same test.