如何为特定产品(计划)应用条纹优惠券? POST 详情:$request->plan price id , $coupon => coupon id $card['id'] => card token

how to apply coupon in stripe for particular product (plan)? POST details: $request->plan price id , $coupon => coupon id $card['id'] => card token

我添加了 abc 产品的优惠券,在创建订阅时我可以为所有人应用该优惠券 产品。我希望它只能适用于 abc 产品。我在用着 https://cartalyst.com/manual/stripe/2.0#subscriptions 文档。

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

您可以使用 applies_to 属性将优惠券应用于将仅限于特定产品的订阅。例如,在下面的代码中,优惠券将仅适用于 prod_xxx,因此当使用 prod_xxx 的价格创建订阅并且同时使用 prod_yyy 的价格创建订阅时,折扣只会适用金额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'],
  ],
]);