diff --git a/app/models/concerns/waste_carriers_engine/can_use_edit_registration_workflow.rb b/app/models/concerns/waste_carriers_engine/can_use_edit_registration_workflow.rb index 1bf71b30e..f99883144 100644 --- a/app/models/concerns/waste_carriers_engine/can_use_edit_registration_workflow.rb +++ b/app/models/concerns/waste_carriers_engine/can_use_edit_registration_workflow.rb @@ -41,6 +41,7 @@ module CanUseEditRegistrationWorkflow state :declaration_form state :edit_payment_summary_form state :edit_bank_transfer_form + state :worldpay_form state :edit_complete_form # Cancel an edit @@ -182,12 +183,19 @@ module CanUseEditRegistrationWorkflow to: :edit_payment_summary_form, if: :registration_type_changed? + transitions from: :edit_payment_summary_form, + to: :worldpay_form, + if: :paying_by_card? + transitions from: :edit_payment_summary_form, to: :edit_bank_transfer_form transitions from: :edit_bank_transfer_form, to: :edit_complete_form + transitions from: :worldpay_form, + to: :edit_complete_form + # Cancel an edit transitions from: :confirm_edit_cancelled_form, to: :edit_cancelled_form @@ -257,6 +265,9 @@ module CanUseEditRegistrationWorkflow transitions from: :edit_bank_transfer_form, to: :edit_payment_summary_form + transitions from: :worldpay_form, + to: :edit_payment_summary_form + # Cancelling the edit process transitions from: :confirm_edit_cancelled_form, to: :edit_form @@ -288,6 +299,10 @@ def based_overseas? def skip_to_manual_address? temp_os_places_error end + + def paying_by_card? + temp_payment_method == "card" + end end # rubocop:enable Metrics/ModuleLength end diff --git a/app/services/waste_carriers_engine/worldpay_xml_service.rb b/app/services/waste_carriers_engine/worldpay_xml_service.rb index d57d66d5a..7659f5ed9 100644 --- a/app/services/waste_carriers_engine/worldpay_xml_service.rb +++ b/app/services/waste_carriers_engine/worldpay_xml_service.rb @@ -40,6 +40,8 @@ def build_order(xml) if @transient_registration.is_a?(WasteCarriersEngine::RenewingRegistration) xml.orderContent "Waste Carrier Registration renewal: #{reg_identifier} for #{company_name}" + elsif @transient_registration.is_a?(WasteCarriersEngine::EditRegistration) + xml.orderContent "Waste Carrier Registration edit: #{reg_identifier} for #{company_name}" else xml.orderContent "Waste Carrier Registration: #{reg_identifier} for #{company_name}" end diff --git a/app/views/waste_carriers_engine/edit_payment_summary_forms/new.html.erb b/app/views/waste_carriers_engine/edit_payment_summary_forms/new.html.erb index f79305eba..39ecc58e6 100644 --- a/app/views/waste_carriers_engine/edit_payment_summary_forms/new.html.erb +++ b/app/views/waste_carriers_engine/edit_payment_summary_forms/new.html.erb @@ -2,6 +2,8 @@
<%= form_for(@edit_payment_summary_form) do |f| %> + <%= render("waste_carriers_engine/shared/payment_errors") %> + <%= render("waste_carriers_engine/shared/errors", object: @edit_payment_summary_form) %>

<%= t(".heading") %>

diff --git a/app/views/waste_carriers_engine/payment_summary_forms/new.html.erb b/app/views/waste_carriers_engine/payment_summary_forms/new.html.erb index 8ff057109..d44b152ab 100644 --- a/app/views/waste_carriers_engine/payment_summary_forms/new.html.erb +++ b/app/views/waste_carriers_engine/payment_summary_forms/new.html.erb @@ -2,15 +2,7 @@
<%= form_for(@payment_summary_form) do |f| %> - <% if flash[:error].present? %> - - <% end %> + <%= render("waste_carriers_engine/shared/payment_errors") %> <%= render("waste_carriers_engine/shared/errors", object: @payment_summary_form) %> diff --git a/app/views/waste_carriers_engine/shared/_payment_errors.html.erb b/app/views/waste_carriers_engine/shared/_payment_errors.html.erb new file mode 100644 index 000000000..e9aa1367a --- /dev/null +++ b/app/views/waste_carriers_engine/shared/_payment_errors.html.erb @@ -0,0 +1,10 @@ + +<% if flash[:error].present? %> + +<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index a1d15edc0..fcf3446cb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -16,6 +16,8 @@ en: dob_year: Year dob_month: Month dob_day: Day + payment_errors: + payment_error_heading: A problem with your payment errors: heading: A problem to fix manual_address: diff --git a/config/locales/forms/payment_summary_forms/en.yml b/config/locales/forms/payment_summary_forms/en.yml index 2163330db..59b45b622 100644 --- a/config/locales/forms/payment_summary_forms/en.yml +++ b/config/locales/forms/payment_summary_forms/en.yml @@ -3,7 +3,6 @@ en: payment_summary_forms: new: title: Payment summary - payment_error_heading: A problem with your payment heading: Payment summary renewal_fee: Renewal of registration registration_fee: Initial registration diff --git a/spec/models/waste_carriers_engine/edit_registration_workflow/edit_payment_summary_form_spec.rb b/spec/models/waste_carriers_engine/edit_registration_workflow/edit_payment_summary_form_spec.rb index a1d5f06ab..75ae157b0 100644 --- a/spec/models/waste_carriers_engine/edit_registration_workflow/edit_payment_summary_form_spec.rb +++ b/spec/models/waste_carriers_engine/edit_registration_workflow/edit_payment_summary_form_spec.rb @@ -9,6 +9,12 @@ module WasteCarriersEngine describe "#workflow_state" do context ":payment_summary_form state transitions" do context "on next" do + context "when the payment type is :card" do + subject { build(:edit_registration, workflow_state: "edit_payment_summary_form", temp_payment_method: "card") } + + include_examples "has next transition", next_state: "worldpay_form" + end + include_examples "has next transition", next_state: "edit_bank_transfer_form" end diff --git a/spec/models/waste_carriers_engine/edit_registration_workflow/worldpay_form_spec.rb b/spec/models/waste_carriers_engine/edit_registration_workflow/worldpay_form_spec.rb new file mode 100644 index 000000000..15249f63a --- /dev/null +++ b/spec/models/waste_carriers_engine/edit_registration_workflow/worldpay_form_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require "rails_helper" + +module WasteCarriersEngine + RSpec.describe EditRegistration do + subject { build(:edit_registration, workflow_state: "worldpay_form") } + + describe "#workflow_state" do + context ":worldpay_form state transitions" do + context "on next" do + include_examples "has next transition", next_state: "edit_complete_form" + end + + context "on back" do + include_examples "has back transition", previous_state: "edit_payment_summary_form" + end + end + end + end +end