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

Pay for a renewal by bank transfer #146

Merged
merged 9 commits into from
Apr 27, 2018
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@import 'elements/forms/form-multiple-choice';
@import 'elements/forms/form-date';
@import 'elements/forms/form-validation';
@import 'elements/icons';
@import 'elements/layout';
@import 'elements/lists';
@import 'elements/panels';
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/bank_transfer_forms_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class BankTransferFormsController < FormsController
def new
super(BankTransferForm, "bank_transfer_form")
end

def create
super(BankTransferForm, "bank_transfer_form")
end
end
15 changes: 15 additions & 0 deletions app/forms/bank_transfer_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BankTransferForm < BaseForm
attr_accessor :total_to_pay

def initialize(transient_registration)
super
self.total_to_pay = @transient_registration.total_to_pay
end

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
attributes = {}

super(attributes, params[:reg_identifier])
end
end
17 changes: 2 additions & 15 deletions app/forms/payment_summary_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def initialize(transient_registration)

self.type_change = @transient_registration.registration_type_changed?
self.registration_cards = @transient_registration.temp_cards || 0
self.registration_card_charge = determine_total_card_charge
self.total_charge = determine_total_charge
self.registration_card_charge = @transient_registration.total_registration_card_charge
self.total_charge = @transient_registration.total_to_pay
end

def submit(params)
Expand All @@ -20,17 +20,4 @@ def submit(params)
end

validates :temp_payment_method, inclusion: { in: %w[card bank_transfer] }

private

def determine_total_charge
charges = [Rails.configuration.renewal_charge]
charges << Rails.configuration.type_change_charge if type_change
charges << registration_card_charge
charges.sum
end

def determine_total_card_charge
registration_cards * Rails.configuration.card_charge
end
end
5 changes: 1 addition & 4 deletions app/forms/renewal_information_form.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
class RenewalInformationForm < BaseForm
# TODO: Define accessible attributes, eg attr_accessor :field
attr_accessor :type_change, :total_fee

def initialize(transient_registration)
super
self.type_change = @transient_registration.registration_type_changed?
self.total_fee = @transient_registration.total_fee
self.total_fee = @transient_registration.fee_including_possible_type_change
end

def submit(params)
# Assign the params for validation and pass them to the BaseForm method for updating
# TODO: Define allowed params, eg self.field = params[:field]
# TODO: Include attributes to update in the attributes hash, eg { field: field }
attributes = {}

super(attributes, params[:reg_identifier])
Expand Down
17 changes: 16 additions & 1 deletion app/models/concerns/can_change_workflow_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module CanChangeWorkflowStatus
state :cards_form
state :payment_summary_form
state :worldpay_form
state :bank_transfer_form

state :renewal_complete_form

Expand Down Expand Up @@ -246,10 +247,17 @@ module CanChangeWorkflowStatus
to: :payment_summary_form

transitions from: :payment_summary_form,
to: :worldpay_form
to: :worldpay_form,
if: :paying_by_card?

transitions from: :payment_summary_form,
to: :bank_transfer_form

transitions from: :worldpay_form,
to: :renewal_complete_form

transitions from: :bank_transfer_form,
to: :renewal_complete_form
end

event :back do
Expand Down Expand Up @@ -421,6 +429,9 @@ module CanChangeWorkflowStatus
transitions from: :worldpay_form,
to: :payment_summary_form

transitions from: :bank_transfer_form,
to: :payment_summary_form

# Exit routes from renewals process

transitions from: :cannot_renew_type_change_form,
Expand Down Expand Up @@ -530,4 +541,8 @@ def should_register_in_wales?
def declared_convictions?
declared_convictions == true
end

def paying_by_card?
temp_payment_method == "card"
end
end
14 changes: 13 additions & 1 deletion app/models/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def registration_type_changed?
original_registration_type != registration_type
end

def total_fee
def fee_including_possible_type_change
if registration_type_changed?
Rails.configuration.renewal_charge + Rails.configuration.type_change_charge
else
Expand All @@ -40,6 +40,18 @@ def projected_renewal_end_date
expiry_date_after_renewal(expires_on.to_date)
end

def total_to_pay
charges = [Rails.configuration.renewal_charge]
charges << Rails.configuration.type_change_charge if registration_type_changed?
charges << total_registration_card_charge
charges.sum
end

def total_registration_card_charge
return 0 unless temp_cards.present?
temp_cards * Rails.configuration.card_charge
end

private

def copy_data_from_registration
Expand Down
113 changes: 113 additions & 0 deletions app/views/bank_transfer_forms/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<%= render("shared/back", back_path: back_bank_transfer_forms_path(@bank_transfer_form.reg_identifier)) %>

<div class="text">
<%= form_for(@bank_transfer_form) do |f| %>
<%= render("shared/errors", object: @bank_transfer_form) %>

<h1 class="heading-large"><%= t(".heading") %></h1>

<p><%= t(".paragraph_1") %></p>

<ol class="list list-number">
<li><%= t(".list_item_1") %></li>
<li><%= t(".list_item_2") %></li>
</ol>

<p><%= t(".paragraph_2") %></p>

<h2 class="heading-medium"><%= t(".subheading_1") %></h2>

<p><%= t(".paragraph_3") %></p>

<div class="form-group">
<table>
<tbody>
<tr>
<td><%= t(".uk_payment_table.reference_number.label") %></td>
<td><%= @bank_transfer_form.reg_identifier %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.total_cost.label") %></td>
<td>£<%= @bank_transfer_form.total_to_pay %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.account_name.label") %></td>
<td><%= t(".uk_payment_table.account_name.value") %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.bank_name.label") %></td>
<td><%= t(".uk_payment_table.bank_name.value") %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.bank_address.label") %></td>
<td><%= t(".uk_payment_table.bank_address.value").join("<br>").html_safe %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.sort_code.label") %></td>
<td><%= t(".uk_payment_table.sort_code.value") %></td>
</tr>
<tr>
<td><%= t(".uk_payment_table.account_number.label") %></td>
<td><%= t(".uk_payment_table.account_number.value") %></td>
</tr>
</tbody>
</table>
</div>

<p><%= t(".paragraph_4") %></p>

<div class="form-group">
<table>
<tbody>
<tr>
<td><%= t(".international_payment_table.iban.label") %></td>
<td><%= t(".international_payment_table.iban.value") %></td>
</tr>
<tr>
<td><%= t(".international_payment_table.swift.label") %></td>
<td><%= t(".international_payment_table.swift.value") %></td>
</tr>
</tbody>
</table>
</div>

<p><%= t(".paragraph_5") %></p>

<h2 class="heading-medium"><%= t(".subheading_2") %></h2>

<p><%= t(".paragraph_6") %></p>

<div class="form-group">
<table>
<tbody>
<tr>
<td><%= t(".send_confirmation_table.email.label") %></td>
<td><%= mail_to(t(".send_confirmation_table.email.value")) %></td>
</tr>
<tr>
<td><%= t(".send_confirmation_table.fax.label") %></td>
<td><%= t(".send_confirmation_table.fax.value") %></td>
</tr>
<tr>
<td><%= t(".send_confirmation_table.post.label") %></td>
<td><%= t(".send_confirmation_table.post.value").join("<br>").html_safe %></td>
</tr>
</tbody>
</table>
</div>

<div class="form-group notice">
<i class="icon icon-important">
<span class="visually-hidden">Warning</span>
</i>
<strong class="bold-small">
<%= t(".paragraph_7") %>
</strong>
</div>

<%= f.hidden_field :reg_identifier, value: @bank_transfer_form.reg_identifier %>
<div class="form-group">
<%= f.submit t(".next_button"), class: "button" %>
</div>
<% end %>
</div>
75 changes: 75 additions & 0 deletions config/locales/forms/bank_transfer_forms/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
en:
bank_transfer_forms:
new:
title: Pay by bank transfer
heading: Pay by bank transfer
paragraph_1: "Before we can complete your renewal, you need to:"
list_item_1: Pay the renewal charge.
list_item_2: Send us confirmation that you’ve paid the renewal charge.
paragraph_2: Your registration will not be renewed until both steps are complete.
subheading_1: 1. Pay the renewal charge
paragraph_3: Use our account details below to make your internet or telephone banking payment.
uk_payment_table:
reference_number:
label: Payment reference number
total_cost:
label: Payment due
account_name:
label: Account name
value: Environment Agency
bank_name:
label: Bank name
value: RBS/Natwest
bank_address:
label: Bank address
value:
- Royal Bank of Scotland plc
- London Corporate Service Centre
- CPB Services 2nd Floor
- 280 Bishopsgate
- London
- EC2M 4RB
sort_code:
label: Sort code
value: 60-70-80
account_number:
label: Account number
value: "10014411"
paragraph_4: "If you are paying from outside the United Kingdom, include the international banking references below:"
international_payment_table:
iban:
label: IBAN
value: GB23 NWBK6070 8010 0144 11
swift:
label: SWIFTBIC
value: NWBK GB2L
paragraph_5: Payments must be made in sterling.
subheading_2: 2. Send us confirmation of your payment
paragraph_6: Tell us the date, amount of your payment and payment reference number, so we can send you your registration. You can contact us by email, fax or in writing.
send_confirmation_table:
email:
label: Email
value: ea_fsc_ar@sscl.gse.gov.uk
fax:
label: Fax
value: "01733 464892"
post:
label: Postal address
value:
- Environment Agency
- SSCL Banking Team
- PO Box 263
- Peterborough
- PE2 8YD
paragraph_7: We need confirmation of your payment to complete your renewal. If you do not complete this step, the payment process could be delayed and prevent us from sending your renewal confirmation.
error_heading: Something is wrong
next_button: Continue
activemodel:
errors:
models:
bank_transfer_form:
attributes:
reg_identifier:
invalid_format: "The registration ID is not in a valid format"
no_registration: "There is no registration matching this ID"
renewal_in_progress: "This renewal is already in progress"
10 changes: 10 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,16 @@
on: :collection
end

resources :bank_transfer_forms,
only: [:new, :create],
path: "bank-transfer",
path_names: { new: "/:reg_identifier" } do
get "back/:reg_identifier",
to: "bank_transfer_forms#go_back",
as: "back",
on: :collection
end

resources :renewal_complete_forms,
only: [:new, :create],
path: "renewal-complete",
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/forms/bank_transfer_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryBot.define do
factory :bank_transfer_form do
trait :has_required_data do
initialize_with { new(create(:transient_registration, :has_required_data, workflow_state: "bank_transfer_form")) }
end
end
end
1 change: 1 addition & 0 deletions spec/factories/transient_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
trait :has_required_data do
location "england"
declared_convictions "false"
temp_cards 1

# Create a new registration when initializing so we can copy its data
initialize_with { new(reg_identifier: create(:registration, :has_required_data, :expires_soon).reg_identifier) }
Expand Down
Loading