【问题标题】:Rails : Stripe : Updating existing subscription with new coupon codeRails : Stripe : 使用新的优惠券代码更新现有订阅
【发布时间】:2016-06-29 01:53:48
【问题描述】:

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

这是如何处理的?

谢谢

【问题讨论】:

    标签: ruby-on-rails-4 stripe-payments coupon


    【解决方案1】:

    我就是这样做的。

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

    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
                              )
    

    对于即将开具的发票,会为该折扣金额创建发票。

    【讨论】:

    • 表示,如果我们不手动退款,折扣将仅适用于即将到来的发票?
    【解决方案2】:

    以下是在 Ruby 中使用优惠券更新现有订阅的方法:

    customer = Stripe::Customer.retrieve("cus_...")
    subscription = customer.subscriptions.retrieve("sub_...")
    subscription.coupon = "coupon_code"
    subscription.save
    

    优惠券将适用于此订阅的下一张发票,但过去的发票不会受到影响。

    【讨论】:

    • 但是如果我在订阅月/年的中间添加优惠券怎么办?
    • 如我所说,折扣将适用于下一张或多张发票。
    • 意思是我需要手动退还之前的费用吧?
    猜你喜欢
    • 2020-02-26
    • 2015-08-23
    • 2021-06-04
    • 2021-10-17
    • 2014-12-31
    • 2021-02-18
    • 1970-01-01
    • 2018-07-09
    • 2016-05-03
    相关资源
    最近更新 更多