Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit registration - pay by worldpay #760

Merged
merged 4 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions app/services/waste_carriers_engine/worldpay_xml_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<div class="text">
<%= 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) %>

<h1 class="heading-large"><%= t(".heading") %></h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

<div class="text">
<%= form_for(@payment_summary_form) do |f| %>
<% if flash[:error].present? %>
<div class="error-summary" role="alert">
<h2 class="heading-medium error-summary-heading"><%= t(".payment_error_heading") %></h2>

<ul class="error-summary-list">
<p><%= flash[:error] %></p>
</ul>
</div>
<% end %>
<%= render("waste_carriers_engine/shared/payment_errors") %>

<%= render("waste_carriers_engine/shared/errors", object: @payment_summary_form) %>

Expand Down
10 changes: 10 additions & 0 deletions app/views/waste_carriers_engine/shared/_payment_errors.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!-- This is used for showing errors from worldpay when the transaction fails -->
<% if flash[:error].present? %>
<div class="error-summary" role="alert">
<h2 class="heading-medium error-summary-heading"><%= t(".payment_error_heading") %></h2>

<ul class="error-summary-list">
<p><%= flash[:error] %></p>
</ul>
</div>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion config/locales/forms/payment_summary_forms/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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