only complete the payment if it is in a completable state

This commit is contained in:
Andy Brett
2021-02-26 18:05:27 -08:00
parent b3610e035d
commit 3b15e0ee15
2 changed files with 15 additions and 1 deletions

View File

@@ -20,7 +20,7 @@ class ProcessPaymentIntent
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

View File

@@ -47,5 +47,19 @@ describe ProcessPaymentIntent do
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