fix(stripe): lock the real checkout price from the Stripe API (BUNYIP-215) #237
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/bunyip-215-pricelock-line-items"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Fixes BUNYIP-215: the price-lock feature stored placeholder data instead of the real purchased price.
Root cause
handle_checkout_completedlocked the member's "price for life" by readingsession["line_items"]["data"][0]["price"]["id"]andamount_totaldirectly off thecheckout.session.completedwebhook payload. Stripe does not embedline_itemsin that payload unless they are explicitly expanded, so the price id always fell back to the placeholder"price_default"and the amount could fall back to a hardcoded300. Every checkout locked junk; any later logic readinglocked_price_id(re-pricing, plan migration, grandfathering) operated on a bogus id.Fix
StripeService::get_checkout_session_price(session_id)(bunyip-domain), which retrieves the session withline_itemsandline_items.data.priceexpanded and returns the first line item's price id plus its amount (unit_amount, falling back to the line item'samount_total).StripeServicefrom the webhook entry point intohandle_checkout_completed."price_default"/300fallbacks are removed: a session with no resolvable line-item price (should not happen for a completed checkout) logs an error and leaves the price unlocked rather than persisting placeholder data, and still activates membership.New
StripeCheckoutPriceresponse struct added tocrates/bunyip-domain/src/models/stripe.rs.Testing
cargo clippy -p bunyip-domain -p bunyip-api --all-targetsclean;cargo fmt --checkclean..sqlx/offline cache regen.Relates to BUNYIP-210.