From cd6c3c45e62d890d2be9faaca7045c78e97a0deb Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Thu, 27 Jul 2023 14:08:42 +0200 Subject: [PATCH 1/6] Allow an order in confirmation state to transition to payment --- app/controllers/spree/admin/payments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/admin/payments_controller.rb b/app/controllers/spree/admin/payments_controller.rb index 1933962c1a..5f1168d2b4 100644 --- a/app/controllers/spree/admin/payments_controller.rb +++ b/app/controllers/spree/admin/payments_controller.rb @@ -140,7 +140,8 @@ module Spree # # Otherwise redirect user to that step def can_transition_to_payment - return if @order.payment? || @order.complete? || @order.canceled? || @order.resumed? + return if @order.confirmation? || @order.payment? || + @order.complete? || @order.canceled? || @order.resumed? flash[:notice] = Spree.t(:fill_in_customer_info) redirect_to spree.edit_admin_order_customer_url(@order) From d6daf25b984616d3661a66f04436e044af915ba2 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Thu, 27 Jul 2023 14:09:24 +0200 Subject: [PATCH 2/6] Spec checking order in confirmation state transition to payment --- spec/system/admin/order_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/system/admin/order_spec.rb b/spec/system/admin/order_spec.rb index bc398e7673..b3cc01a0b5 100644 --- a/spec/system/admin/order_spec.rb +++ b/spec/system/admin/order_spec.rb @@ -507,6 +507,20 @@ describe ' page.has_selector? "table.index tbody tr" # Wait for JS end + context 'when order is in confirmation state' do + before do + order.update(state: 'confirmation') + end + + it 'checks order may proceed to payments' do + login_as_admin + visit spree.edit_admin_order_path(order) + + click_link "Payments" + expect(page).to have_content "NEW PAYMENT" + end + end + context "as an enterprise manager" do let(:coordinator1) { create(:distributor_enterprise) } let(:coordinator2) { create(:distributor_enterprise) } From e1374d5837ca572c5ec24e588543756654fcc216 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Sun, 29 Oct 2023 21:05:05 +0100 Subject: [PATCH 3/6] Add Order completion after capturing event - A new processing method - Payment means that link to it - Altering methods that handle next status choice --- app/controllers/spree/admin/payments_controller.rb | 3 ++- app/models/spree/credit_card.rb | 4 ++-- app/models/spree/payment/processing.rb | 5 +++++ app/models/spree/payment_method/check.rb | 4 ++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/spree/admin/payments_controller.rb b/app/controllers/spree/admin/payments_controller.rb index 5f1168d2b4..6369f1ff74 100644 --- a/app/controllers/spree/admin/payments_controller.rb +++ b/app/controllers/spree/admin/payments_controller.rb @@ -185,7 +185,8 @@ module Spree end def allowed_events - %w{capture void_transaction credit refund resend_authorization_email} + %w{capture void_transaction credit refund resend_authorization_email + capture_and_complete_order} end end end diff --git a/app/models/spree/credit_card.rb b/app/models/spree/credit_card.rb index c4ec4f0967..5949023cb5 100644 --- a/app/models/spree/credit_card.rb +++ b/app/models/spree/credit_card.rb @@ -67,7 +67,7 @@ module Spree end def actions - %w{capture void credit resend_authorization_email} + %w{capture_and_complete_order void credit resend_authorization_email} end def can_resend_authorization_email?(payment) @@ -75,7 +75,7 @@ module Spree end # Indicates whether its possible to capture the payment - def can_capture?(payment) + def can_capture_and_complete_order?(payment) return false if payment.requires_authorization? payment.pending? || payment.checkout? diff --git a/app/models/spree/payment/processing.rb b/app/models/spree/payment/processing.rb index 17918078de..499a669987 100644 --- a/app/models/spree/payment/processing.rb +++ b/app/models/spree/payment/processing.rb @@ -47,6 +47,11 @@ module Spree end end + def capture_and_complete_order! + OrderWorkflow.new(order).complete! + capture! + end + def void_transaction! return true if void? diff --git a/app/models/spree/payment_method/check.rb b/app/models/spree/payment_method/check.rb index 9819a52c6c..9f4378830c 100644 --- a/app/models/spree/payment_method/check.rb +++ b/app/models/spree/payment_method/check.rb @@ -4,11 +4,11 @@ module Spree class PaymentMethod class Check < Spree::PaymentMethod def actions - %w{capture void} + %w{capture_and_complete_order void} end # Indicates whether its possible to capture the payment - def can_capture?(payment) + def can_capture_and_complete_order?(payment) ['checkout', 'pending'].include?(payment.state) end From 31cc0494c229d4a68afd7e71701b504fec97dfa7 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Sun, 29 Oct 2023 21:16:26 +0100 Subject: [PATCH 4/6] Icon for the new action - Similar to the actual capture action --- app/webpacker/css/admin/shared/icons.scss | 3 ++- app/webpacker/css/admin/shared/tables.scss | 2 +- app/webpacker/css/admin_v3/shared/icons.scss | 4 +++- app/webpacker/css/admin_v3/shared/tables.scss | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/webpacker/css/admin/shared/icons.scss b/app/webpacker/css/admin/shared/icons.scss index a6ad0a7f09..2e581b209b 100644 --- a/app/webpacker/css/admin/shared/icons.scss +++ b/app/webpacker/css/admin/shared/icons.scss @@ -20,5 +20,6 @@ .icon-cancel:before, .icon-void:before { @extend .icon-remove, :before; } -.icon-capture { @extend .icon-ok } +.icon-capture, +.icon-capture_and_complete_order { @extend .icon-ok } .icon-credit:before { @extend .icon-ok, :before ; } diff --git a/app/webpacker/css/admin/shared/tables.scss b/app/webpacker/css/admin/shared/tables.scss index 7346efff7c..a518f223b1 100644 --- a/app/webpacker/css/admin/shared/tables.scss +++ b/app/webpacker/css/admin/shared/tables.scss @@ -84,7 +84,7 @@ table { background-color: $color-notice; color: $color-1; } - .icon-edit:hover, .icon-capture:hover, .icon-ok:hover, .icon-plus:hover, .icon-road:hover { + .icon-edit:hover, .icon-capture:hover, .icon-capture_and_complete_order:hover, .icon-ok:hover, .icon-plus:hover, .icon-road:hover { background-color: $color-success; color: $color-1; } diff --git a/app/webpacker/css/admin_v3/shared/icons.scss b/app/webpacker/css/admin_v3/shared/icons.scss index 0bc8f0341d..13c3c516f3 100644 --- a/app/webpacker/css/admin_v3/shared/icons.scss +++ b/app/webpacker/css/admin_v3/shared/icons.scss @@ -34,9 +34,11 @@ button[class*="icon-"] { @extend .icon-remove, :before; } -.icon-capture { +.icon-capture, +.icon-capture_and_complete_order { @extend .icon-ok; } + .icon-credit:before { @extend .icon-ok, :before; } diff --git a/app/webpacker/css/admin_v3/shared/tables.scss b/app/webpacker/css/admin_v3/shared/tables.scss index 7e187099fb..0511d0a9f4 100644 --- a/app/webpacker/css/admin_v3/shared/tables.scss +++ b/app/webpacker/css/admin_v3/shared/tables.scss @@ -96,6 +96,7 @@ table { } .icon-edit:hover, .icon-capture:hover, + .icon-capture_and_complete_order:hover, .icon-ok:hover, .icon-plus:hover { background-color: $teal; From 7c89458a959a52e7617faf0fd75a8618d871ce32 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Sun, 29 Oct 2023 21:18:30 +0100 Subject: [PATCH 5/6] New locale (tooltip) --- config/locales/en.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/en.yml b/config/locales/en.yml index 2e9842a73f..1cefafe986 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3856,6 +3856,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using credit_card: "Credit Card" new_payment: "New Payment" capture: "Capture" + capture_and_complete_order: "Capture and complete order" void: "Void" login: "Login" password: "Password" From a764cc0f89fc59e28cc673e0798f1cf298fcb845 Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Sun, 29 Oct 2023 21:21:02 +0100 Subject: [PATCH 6/6] Specs for the new action complete after capture - In admin dashboard, clicking on capture leads to a completed order - Modifications of actual specs to take into account new action --- spec/models/spree/credit_card_spec.rb | 4 ++-- spec/models/spree/payment_spec.rb | 2 +- spec/system/admin/payments_spec.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spec/models/spree/credit_card_spec.rb b/spec/models/spree/credit_card_spec.rb index 3ef4c951ca..5e6e950565 100644 --- a/spec/models/spree/credit_card_spec.rb +++ b/spec/models/spree/credit_card_spec.rb @@ -28,14 +28,14 @@ module Spree it "should be true if payment is pending" do payment = build_stubbed(:payment, created_at: Time.zone.now) allow(payment).to receive(:pending?) { true } - expect(credit_card.can_capture?(payment)).to be_truthy + expect(credit_card.can_capture_and_complete_order?(payment)).to be_truthy end it "should be true if payment is checkout" do payment = build_stubbed(:payment, created_at: Time.zone.now) allow(payment).to receive_messages pending?: false, checkout?: true - expect(credit_card.can_capture?(payment)).to be_truthy + expect(credit_card.can_capture_and_complete_order?(payment)).to be_truthy end end diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 624911bbb1..db1f8e65d6 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -812,7 +812,7 @@ describe Spree::Payment do let(:payment) { build_stubbed(:payment, source: build_stubbed(:credit_card)) } it "can capture and void" do - expect(payment.actions).to match_array %w(capture void) + expect(payment.actions).to match_array %w(capture_and_complete_order void) end describe "when a payment has been taken" do diff --git a/spec/system/admin/payments_spec.rb b/spec/system/admin/payments_spec.rb index b5434045d6..6abf55b1dc 100644 --- a/spec/system/admin/payments_spec.rb +++ b/spec/system/admin/payments_spec.rb @@ -9,6 +9,7 @@ describe ' include AuthenticationHelper let(:order) { create(:completed_order_with_fees) } + let(:confirmed_order) { create(:order_ready_for_confirmation) } describe "payments/new" do it "displays the order balance as the default payment amount" do @@ -67,4 +68,14 @@ describe ' expect(order.shipment_state).to eq "pending" end end + + describe 'Capture & complete order' do + it 'completes order when capturing payment' do + login_as_admin + visit spree.admin_order_payments_path confirmed_order + expect(page).to have_content "CHECKOUT" + page.find('a.icon-capture_and_complete_order').click + expect(confirmed_order.reload.state).to eq 'complete' + end + end end