laravel / cashier-stripe

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.
https://laravel.com/docs/billing
MIT License
2.39k stars 679 forks source link

You may only specify one of these parameters: allow_promotion_codes, discounts. #1134

Closed amanvision closed 3 years ago

amanvision commented 3 years ago

Description:

Getting error "You may only specify one of these parameters: allow_promotion_codes, discounts." even when allowPromotionalCodes() is not specified in below code.

Looks like the allow_promotion_codes option has a default value setup.

$checkout = auth()->user()->newSubscription('default', config('setting.subscription.pricing.rl_yearly')) ->withCoupon(config('setting.subscription.coupon.discounted_subscription')) ->checkout([ 'success_url' => route('home'), 'cancel_url' => route('subscriber.setup'), 'billing_address_collection' => 'required', ]);

driesvints commented 3 years ago

Seems like you're trying to define a promotion code through your subscription settings and a coupon at the same time. This isn't supported by Stripe.

amanvision commented 3 years ago

I would like to offer a discounted subscription to end-users, so I have created the following on Stripe:

  1. Product with recurring payment
  2. Coupon code (20% off) (not promotion code)

And using the above code to apply the coupon, but getting a response "You may only specify one of these parameters: allow_promotion_codes, discounts", not sure what I did wrong.

driesvints commented 3 years ago

config('setting.subscription.pricing.rl_yearly') Remove the promotion code from this config.

driesvints commented 3 years ago

Ah hmm, no that's not the issue it seems. I wonder what's going wrong for you but it's best that you contact Stripe for this as I can't see anything wrong with your code.

amanvision commented 3 years ago

Ok, I figured it out. Instead of using withCouponCode, i'm using subscripton_data option like shown below:

$checkout = auth()->user()->newSubscription('default', config('setting.subscription.pricing.rl_yearly')) ->checkout([ 'success_url' => route('home'), 'cancel_url' => route('subscriber.setup'), 'billing_address_collection' => 'required', 'subscription_data' => [ 'coupon' => config('setting.subscription.coupon.discounted_subscription') ] ]);

driesvints commented 3 years ago

That doesn't sound right. The current implementation uses the documented way by Stripe: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-discounts-coupon