diff --git a/app/services/process_payment_intent.rb b/app/services/process_payment_intent.rb index 5c5085cb55f..d3142462f7f 100644 --- a/app/services/process_payment_intent.rb +++ b/app/services/process_payment_intent.rb @@ -20,7 +20,7 @@ def call! last_payment.update_attribute(:cvv_response_message, nil) OrderWorkflow.new(@order).next - last_payment.complete! if !last_payment.completed? + last_payment.complete! if last_payment.can_complete? end private diff --git a/spec/services/process_payment_intent_spec.rb b/spec/services/process_payment_intent_spec.rb index fdb906c2ea0..c93082da2aa 100644 --- a/spec/services/process_payment_intent_spec.rb +++ b/spec/services/process_payment_intent_spec.rb @@ -47,5 +47,19 @@ expect(order).to have_received(:deliver_order_confirmation_email) end end + + context "payment is in a failed state" do + let(:invalid_intent) { "invalid" } + let(:service) { ProcessPaymentIntent.new(invalid_intent, order) } + + before do + payment.update_attribute(:state, "failed") + end + + it "does not complete the payment" do + service.call! + expect(payment.reload.state).to eq("failed") + end + end end end