Resolve APP_URL before the checkout try, and move to SDK rc.9 - #2
Merged
Conversation
appUrl() was called inside the try/catch around createCheckout, so a missing APP_URL was caught alongside declined cards and a missing provider, and reported to the buyer as 'Could not start checkout'. An operator's misconfiguration was being shown as a payment failure, and the one sentence naming the real cause was destroyed on the way. The same bug cost an afternoon on the Next.js starter, where checkout looked broken end to end because one variable was blank. Configuration is now read before the try, so it escapes as a real error. The catch still covers genuine checkout failures, which correctly surface the API's own message. The helper moves to lib/app-url.ts to match the starter, and keeps the throw rather than becoming a boot-time check: next build runs on machines with no environment at all, which is most CI, so failing at import would break the build instead of the request that actually needs the value. lib/rekey.ts is lazy for the same reason. Also moves @rekey.dev/* from rc.6 to rc.9, which carries the restyled drop-in components and the RekeyProvider fix where any failed /auth/me refetch signed the user out. Verified by building and booting the built server: /, /p/grid-icons and /sign-in all serve, and tsc is clean.
Ported from nextjs-starter, where clicking Buy against a live API showed a customer this in the product card, verbatim from the API: This subscriber pays through "paypal", which is no longer configured for this Application. ... Re-add the "paypal" credentials in Panel -> Application -> Billing ... It talks about the buyer in the third person and its only instruction needs a panel they do not have. lib/rekey-error.ts maps the handful of codes whose text is addressed to the operator onto one sentence a customer can act on, logs the real message and fix to the server console, and passes everything else through unchanged. A declined card or an archived product is the buyer's situation and the API already says so in words they can use.
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.
The bug
appUrl()was called inside thetry/catcharoundcreateCheckout:So a missing
APP_URLwas caught alongside declined cards and archived plans,and rendered to the buyer as "Could not start checkout". An operator's
misconfiguration reported as a payment failure, with the one sentence naming
the real cause swallowed on the way out.
This is not hypothetical: the same bug on
nextjs-startercost an afternoon.Checkout looked broken end to end when one variable was blank.
The fix
Configuration is resolved before the try, so it escapes as a real error. The
catch still covers genuine checkout failures, which correctly surface the API's
own message.
The helper moves to
lib/app-url.tsto match the starter. It stays a throwrather than becoming a boot-time check because
next buildruns on machineswith no environment at all, which is most CI: failing at import would break the
build rather than the request that actually needs the value.
lib/rekey.tsislazy for the same reason.
Also
@rekey.dev/*from rc.6 to rc.9. That carries the restyled drop-incomponents and the
RekeyProviderfix where any failed/auth/merefetchsigned the user out.
Verification
tsc --noEmitclean;npm run buildclean; the built server booted and/,/p/grid-iconsand/sign-inall return 200 with the expected content. Agreen build alone was not treated as evidence.