Created
June 8, 2017 19:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == 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