Remove Coupon from Stripe Subscription in Update

◇◆丶佛笑我妖孽 提交于 2021-01-28 11:18:24

问题


I need to remove a coupon on a subscription during update, I thought passing coupon of nil to the api should remove it, but it just removes it from the post.

There is another way of doing it like this.. https://stripe.com/docs/api/discounts/subscription_delete

but it requires another call I don't want to do.

Ruby Stripe Gem API:

      Stripe::Subscription.update(
        subscription.stripe_id,
        {
          coupon: nil,
          items: [
            {
              id: subscription.item_stripe_id,
              quantity: 0,

            },
            { 
              plan: to_plan.stripe_id,
              quantity: 1
            }
          ],
        }
      ) 

creates a post request like this:

{
  "items": {
    "0": {
      "id": "si_G5sdf33t89",
      "quantity": "0"
    },
    "1": {
      "plan": "a_plan",
      "quantity": "1"
    }
  }
}

回答1:


coupon: ''

Coupon set to an empty string removes it, while nil/null is ignored



来源:https://stackoverflow.com/questions/58634940/remove-coupon-from-stripe-subscription-in-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!