Bugfix: Creating Checkout session with Coupon (#1163) #1164
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.
This PR fixes issue #1163.
Description:
It's not possible to generate a Stripe Checkout session through Cashier when using Coupons via the
->withCoupon()
method.There are two issues:
(1) The Stripe API does not accept both
allow_promotion_codes
anddiscounts
parameters. Stripe throws an exception even when theallow_promotion_codes
parameter is set tofalse
.(2) The
discount
parameter in the session creation payload needs to be an indexed array.Both issues seem to be in inconsistent implementation of the Checkout API. It's not very well documented and this different from the way how regular subscriptions are created (without Checkout). See https://stripe.com/docs/billing/subscriptions/discounts for more details.
Changes:
'allow_promotion_codes' = false
are filtered from the payload before sending it to Stripecoupon
nested one level deeper in thediscounts
parameter