Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Refund#perform_response and reintroduce @response ivar #3672

Merged
merged 2 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions core/app/models/spree/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class Refund < Spree::Base

validate :amount_is_less_than_or_equal_to_allowed_amount, on: :create

attr_reader :perform_response
attr_accessor :perform_after_create

after_create :set_perform_after_create_default
after_create :perform!
after_create :clear_perform_after_create
Expand Down Expand Up @@ -48,10 +50,18 @@ def perform!

credit_cents = money.cents

response = process!(credit_cents)
log_entries.build(details: response.to_yaml)
@perform_response = process!(credit_cents)

@response = Spree::DeprecatedInstanceVariableProxy.new(
self,
:perform_response,
:@response,
Spree::Deprecation,
"Please, do not use Spree::Refund @response anymore, use Spree::Refund#perform_response"
)

update!(transaction_id: response.authorization)
log_entries.build(details: perform_response.to_yaml)
update!(transaction_id: perform_response.authorization)
update_order
end

Expand Down
13 changes: 13 additions & 0 deletions core/spec/models/spree/refund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@
context "with perform_after_create: true" do
let(:perform_after_create) { true }

it "deprecates usage of the instance variable @response" do
expect(Spree::Deprecation).to receive(:warn).twice

response = refund.instance_variable_get("@response")
response.to_s
end

it "sets #perform_response with the gateway response from the payment provider" do
expect(Spree::Deprecation).to receive(:warn)

expect(refund.perform_response).to eq gateway_response
end

it "does nothing, perform! already happened after create" do
expect(Spree::Deprecation).to receive(:warn)
refund
Expand Down