【发布时间】:2016-06-29 01:53:48
【问题描述】:
我有一个订阅,如果我用coupon 更新它,优惠券将如何应用?客户已经支付了金额,现在我将通过从我的管理仪表板进行编辑来申请 100% 的折扣券。
这是如何处理的?
谢谢
【问题讨论】:
标签: ruby-on-rails-4 stripe-payments coupon
我有一个订阅,如果我用coupon 更新它,优惠券将如何应用?客户已经支付了金额,现在我将通过从我的管理仪表板进行编辑来申请 100% 的折扣券。
这是如何处理的?
谢谢
【问题讨论】:
标签: ruby-on-rails-4 stripe-payments coupon
我就是这样做的。
首先我更新了客户的订阅:
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 中使用优惠券更新现有订阅的方法:
customer = Stripe::Customer.retrieve("cus_...")
subscription = customer.subscriptions.retrieve("sub_...")
subscription.coupon = "coupon_code"
subscription.save
优惠券将适用于此订阅的下一张发票,但过去的发票不会受到影响。
【讨论】: