php – 如何在订阅已经创建后使用Laravel Cashier将优惠券添加到* Stripe订阅*

前端之家收集整理的这篇文章主要介绍了php – 如何在订阅已经创建后使用Laravel Cashier将优惠券添加到* Stripe订阅*前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
根据Stripe文档,您似乎可以将优惠券实际应用于整个客户,但您也可以将优惠券应用于他们的订阅.我正在尝试在创建订阅后将优惠券应用于客户的订阅.我使用的是Laravel Cashier 4.2.

这是我尝试过的:

$company = Auth::user()->company;
 $customer = $company->subscription()->getStripeCustomer(); // returns a StripeGateway object
 $customer->subscription->applyCoupon($input['coupon_code']);

这是错误消息:

"Call to undefined method Stripe_Subscription::updateSubscription()"

我可以将applyCoupon()方法作为一个整体用于客户,但不是实际的订阅…想法赞赏.

Stripe文档仅显示如何从订阅删除折扣:
Discount Object.我在他们的文档中找到的唯一其他信息是:

Coupons and discounts

If you want to provide discounts to certain customers,you can create coupon codes in the Dashboard. Coupons have a discount percentage and a duration,so you could create coupons like a 10% lifetime discount,or a one month 50% discount,etc. Coupons can also have expiration dates attached,after which they can’t be used. Here’s an example of adding a discount to a user’s subscription. In this case,we’ve already created a coupon called 50OFF1MONTH:

curl https://api.stripe.com/v1/customers/cus_4fdAW5ftNQow1a \
-u sk_test_4LOIhlh19aUz8yFBLwMIxnBY: \
-d coupon=50OFF1MONTH

但是,这不是很有帮助.再一次,Laravel的文档有点优雅,并且缺少关于该主题的任何信息.

我想知道我是否只需要使用新优惠券完全重新创建订阅对象……但这并不理想,因为您需要一个卡片令牌.

更新1

我可以确认这实际上是将优惠券应用于订阅本身

$user->subscription('monthly')
 ->withCoupon('code')
 ->create($creditCardToken);

然而,问题是如何在事实之后添加优惠券.

解决方法

它看起来不像我想做的事情,所以我找到了另一种方式.我所做的就是将用户现有计划交换到当前计划并使用withCoupon方法.这确实似乎将优惠券应用于订阅,似乎不向用户收费或更改其结算周期,但我可能是错的…

$company->subscription($company->stripe_plan)
        ->withCoupon($input['coupon_code'])
        ->swap();

猜你在找的Laravel相关文章