I am added a coupon for abc product, while create subscription i can apply that coupon for all products. I want it can apply to only abc product. i m using https://cartalyst.com/manual/stripe/2.0#subscriptions documentation.

 $stripe->subscriptions()->create($stripe_customer_id, [
             'plan'   => $request->plan,
             'coupon' => $coupon,
             'default_payment_method' => $card['id'],
         ]);
1

There are 1 answers

2
v3nkman On BEST ANSWER

You can apply a coupon to a subscription that will be restricted to a particular product by using the applies_to attribute. For example, in the following code, the coupon will only apply to prod_xxx, so when a subscription is created with a price from prod_xxx but also a price from prod_yyy, the discount will only apply to the amount of prod_xxx/price_xxx

$coupon = $stripe->coupons->create([
  'percent_off' => 25,
  'duration' => 'repeating',
  'duration_in_months' => 3,
  'applies_to' => ["products" => ["prod_xxx"]]
]);

$stripe->subscriptions->create([
  'coupon' => $coupon->id,
  'customer' => 'cus_xxx',
  'items' => [
    ['price' => 'price_xxx'], # <-- coupon will apply
    ['price' => 'price_yyy'],
  ],
]);