diff --git a/backend/app/controllers/spree/admin/refunds_controller.rb b/backend/app/controllers/spree/admin/refunds_controller.rb index 7c183cbd0d2..10b6de39c40 100644 --- a/backend/app/controllers/spree/admin/refunds_controller.rb +++ b/backend/app/controllers/spree/admin/refunds_controller.rb @@ -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 } diff --git a/backend/spec/controllers/spree/admin/refunds_controller_spec.rb b/backend/spec/controllers/spree/admin/refunds_controller_spec.rb index 775ccf15ffe..db2a0564bc4 100644 --- a/backend/spec/controllers/spree/admin/refunds_controller_spec.rb +++ b/backend/spec/controllers/spree/admin/refunds_controller_spec.rb @@ -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 diff --git a/core/app/models/spree/refund.rb b/core/app/models/spree/refund.rb index 5ae7be4abfd..42b88ce2a6b 100644 --- a/core/app/models/spree/refund.rb +++ b/core/app/models/spree/refund.rb @@ -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