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

Fix ability to perform refunds after a first failed attempt #3831

Merged
merged 2 commits into from
Nov 12, 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
5 changes: 3 additions & 2 deletions backend/app/controllers/spree/admin/refunds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class RefundsController < ResourceController
rescue_from Spree::Core::GatewayError, with: :spree_core_gateway_error

def create
@refund.attributes = refund_params.merge(perform_after_create: false)
if @refund.save && @refund.perform!
@refund.attributes = refund_params

if @refund.valid? && @refund.perform!
flash[:success] = flash_message_for(@refund, :successfully_created)
respond_with(@refund) do |format|
format.html { redirect_to location_after_save }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
context "a Spree::Core::GatewayError is raised" do
before do
expect_any_instance_of(Spree::Refund).
to receive(:perform!).
to receive(:process!).
and_raise(Spree::Core::GatewayError.new('An error has occurred'))
end

Expand Down
8 changes: 7 additions & 1 deletion core/app/models/spree/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ def perform!
)

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

self.transaction_id = perform_response.authorization
# This is needed otherwise set_perform_after_create_default callback
# will print a deprecation warning when save! creates a record.
self.perform_after_create = false unless persisted?
save!

update_order
end

Expand Down