Skip to content

Instantly share code, notes, and snippets.

@kylefox
Created June 8, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylefox/070ea4f7eb256e1b4537ffef706a2c43 to your computer and use it in GitHub Desktop.
Save kylefox/070ea4f7eb256e1b4537ffef706a2c43 to your computer and use it in GitHub Desktop.
Inconsistent behavior between previewing subscription changes and saving subscription changes when removing subscription coupons.
# == Let's work with a subscription that has an existing coupon ==
subscription = Stripe::Subscription.retrieve('sub_ABC123')
subscription.discount.coupon.id # => "early-upgrade"
# Preview invoice keeps the coupon, as expected.
Stripe::Invoice.upcoming(
customer: subscription.customer,
subscription: subscription.id
).discount.coupon.id # => "early-upgrade"
# == Use empty string to remove coupon ==
Stripe::Invoice.upcoming(
customer: subscription.customer,
subscription: subscription.id,
coupon: ''
).discount # => nil (coupon REMOVED)
subscription.coupon = "" # => Throws ArgumentError: You cannot set coupon to an empty string.
# == Use nil to remove coupon ==
Stripe::Invoice.upcoming(
customer: subscription.customer,
subscription: subscription.id,
coupon: nil
).discount.coupon.id # => "early-upgrade" (coupon NOT REMOVED)
subscription.coupon = nil # => REMOVES coupon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment