Skip to content

Commit

Permalink
Merge pull request #3831 from nebulab/kennyadsl/refund-perform-fix
Browse files Browse the repository at this point in the history
Fix ability to perform refunds after a first failed attempt
  • Loading branch information
kennyadsl authored Nov 12, 2020
2 parents 304da6d + ea7cbe0 commit 3c8ffcc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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

0 comments on commit 3c8ffcc

Please sign in to comment.