Merge pull request #10933 from Matt-Yorkley/fix-payment-intents

Fix ProcessPaymentIntent service
This commit is contained in:
Filipe
2023-06-13 11:00:27 +01:00
committed by GitHub
3 changed files with 24 additions and 19 deletions

View File

@@ -56,8 +56,9 @@ class ProcessPaymentIntent
attr_reader :order, :payment_intent, :payment
def process_payment
OrderWorkflow.new(order).next if order.state == "payment"
order.process_payments!
return unless order.process_payments!
OrderWorkflow.new(order).complete
end
def ready_for_capture?

View File

@@ -46,21 +46,6 @@ module PaymentGateways
order.payments << payment
end
shared_examples "successful order completion" do
it "completes the order and redirects to the order confirmation page" do
expect(controller).to receive(:processing_succeeded).and_call_original
expect(controller).to receive(:order_completion_reset).and_call_original
get :confirm, params: { payment_intent: "pi_123" }
expect(order.completed?).to be true
expect(response).to redirect_to order_path(order, order_token: order.token)
expect(flash[:notice]).to eq 'Your order has been processed successfully'
end
end
include_examples "successful order completion"
it "creates a customer record" do
order.update_columns(customer_id: nil)
Customer.delete_all
@@ -94,7 +79,16 @@ Please try again!"
order.update_attribute :state, "confirmation"
end
include_examples "successful order completion"
it "completes the order and redirects to the order confirmation page" do
expect(controller).to receive(:processing_succeeded).and_call_original
expect(controller).to receive(:order_completion_reset).and_call_original
get :confirm, params: { payment_intent: "pi_123" }
expect(order.completed?).to be true
expect(response).to redirect_to order_path(order, order_token: order.token)
expect(flash[:notice]).to eq 'Your order has been processed successfully'
end
end
end
@@ -236,6 +230,16 @@ completed due to stock issues."
expect(payment.state).to eq("completed")
expect(payment.cvv_response_message).to be nil
end
it "moves the order state to completed" do
expect(order).to receive(:process_payments!) do
payment.complete!
end
get :authorize, params: { order_number: order.number, payment_intent: payment_intent }
expect(order.reload.state).to eq "complete"
end
end
context "when the order is already completed" do

View File

@@ -9,7 +9,7 @@ describe ProcessPaymentIntent do
let(:customer) { create(:customer) }
let(:order) {
create(:order_with_totals, customer: customer, distributor: customer.enterprise,
state: "payment")
state: "confirmation")
}
let(:payment_method) { create(:stripe_sca_payment_method) }