Skip to content

Commit

Permalink
Fix return value of Customer#delete_discount
Browse files Browse the repository at this point in the history
`Customer#delete_discount` has been broken for some time in that it
tries to re-initialize `self` (which is a customer) with a received
discount response. This is incorrect and leads to various problems.

Here, we redefine the return value of `delete_discount` as a discount,
and have it no longer mutate the object on which is was called. We add a
comment as well just to help flag some of the behavior which could
potentially be confusing.

Fixes #963.
  • Loading branch information
brandur committed Feb 8, 2021
1 parent de27275 commit e1fc70b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/stripe/resources/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ class << self
alias detach_source delete_source
end

# Deletes a discount associated with the customer.
#
# Returns the deleted discount. The customer object is not updated,
# so you must call `refresh` on it to get a new version with the
# discount removed.
def delete_discount
resp, opts = execute_resource_request(:delete, resource_url + "/discount")
initialize_from(resp.data, opts, true)
Util.convert_to_stripe_object(resp.data, opts)
end
end
end

0 comments on commit e1fc70b

Please sign in to comment.