Also re-implement Charge#refund to use our new endpoint

This was already done for `ApplicationFee`.
This commit is contained in:
Brandur 2016-01-14 18:23:29 -08:00
parent 8a20ab8972
commit cd9d2bc71e
3 changed files with 18 additions and 4 deletions

View File

@ -5,8 +5,12 @@ module Stripe
include Stripe::APIOperations::Update
def refund(params={}, opts={})
response, opts = request(:post, refund_url, params, opts)
initialize_from(response, opts)
self.refunds.create
# now that a refund has been created, we expect the state of this object
# to change as well (i.e. `refunded` will now be `true`) so refresh it
# from the server
self.refresh
end
extend Gem::Deprecate
deprecate :refund, "charge.refunds.create", 2016, 07

View File

@ -28,7 +28,8 @@ module Stripe
begin
fee = Stripe::ApplicationFee.construct_from(make_application_fee)
# creates the refund
# creates the refund (this is not how the endpoint would actually
# respond, but we discard the result anyway)
@mock.expects(:post).once.
with("#{Stripe.api_base}/v1/application_fees/#{fee.id}/refunds", nil, '').
returns(make_response({}))

View File

@ -120,9 +120,18 @@ module Stripe
$stderr = StringIO.new
begin
charge = Stripe::Charge.construct_from(make_charge)
# creates the refund (this is not how the endpoint would actually
# respond, but we discard the result anyway)
@mock.expects(:post).once.
with("#{Stripe.api_base}/v1/charges/#{charge.id}/refund", nil, '').
with("#{Stripe.api_base}/v1/charges/#{charge.id}/refunds", nil, '').
returns(make_response({}))
# reloads the charge to get the field updates
@mock.expects(:get).once.
with("#{Stripe.api_base}/v1/charges/#{charge.id}", nil, nil).
returns(make_response({:id => charge.id, :refunded => true}))
charge.refund
message = "NOTE: Stripe::Charge#refund is deprecated; use " +
"charge.refunds.create instead"