gpt4 book ai didi

ruby-on-rails-4 - 导轨 : Stripe : Updating existing subscription with new coupon code

转载 作者:行者123 更新时间:2023-12-04 06:52:00 25 4
gpt4 key购买 nike

我有一个订阅,如果我用 coupon 更新它优惠券将如何应用?客户已经支付了金额,现在我将通过从我的管理仪表板进行编辑来申请 100% 的折扣券。

这是如何处理的?

谢谢

最佳答案

我就是这样做的。

首先我更新了客户的订阅:

customer = Stripe::Customer.retrieve(customer_id)
subscription = customer.retrieve(subscription_id)
subscription.coupon = "coupon_id"
subscription.save

然后使用 coupon 的详细信息更新客户的订阅。在折扣哈希中。

然后我手动退了 charge该客户的对象(如果优惠券是 100% 折扣优惠券)。
charge = customer.retrieve(stripe_charge_id)
refund = charge.refund

然后更新 charge带有 amount_refunded 的对象使用优惠券后的折扣金额。还有 refunded设置为 true 并更新 refunds哈希。

您还可以通过传递金额来创建特定金额的退款,例如:
re = Stripe::Refund.create(  
charge: charge_id,
amount: amount_you_want_to_refund
)

对于即将到来的发票,为该折扣金额创建发票。

关于ruby-on-rails-4 - 导轨 : Stripe : Updating existing subscription with new coupon code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35980553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com