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

Add 'are you sure?' screen when paying by bank transfer #820

Merged
merged 3 commits into from
Apr 30, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

module WasteCarriersEngine
class BankTransferFormsController < FormsController
class ConfirmBankTransferFormsController < FormsController
def new
return unless super(BankTransferForm, "bank_transfer_form")
return unless super(ConfirmBankTransferForm, "confirm_bank_transfer_form")

set_up_finance_details
end

def create
super(BankTransferForm, "bank_transfer_form")
super(ConfirmBankTransferForm, "confirm_bank_transfer_form")
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

module WasteCarriersEngine
class BankTransferForm < BaseForm
delegate :total_to_pay, to: :transient_registration

class ConfirmBankTransferForm < BaseForm
def self.can_navigate_flexibly?
false
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# frozen_string_literal: true

module WasteCarriersEngine
class CopyCardsBankTransferForm < BankTransferForm
class CopyCardsBankTransferForm < BaseForm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing this? I thought the scope of the ticket wasn't including copy cards flow?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Never mind. I got it :)

delegate :total_to_pay, to: :transient_registration

def self.can_navigate_flexibly?
false
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module CanUseNewRegistrationWorkflow
state :cards_form
state :payment_summary_form
state :worldpay_form
state :bank_transfer_form
state :confirm_bank_transfer_form

state :registration_completed_form
state :registration_received_pending_payment_form
Expand Down Expand Up @@ -290,10 +290,10 @@ module CanUseNewRegistrationWorkflow
if: :paying_by_card?

transitions from: :payment_summary_form,
to: :bank_transfer_form
to: :confirm_bank_transfer_form

# Registration completion forms
transitions from: :bank_transfer_form,
transitions from: :confirm_bank_transfer_form,
to: :registration_received_pending_payment_form,
# TODO: This don't get triggered if in the `success`
# callback block, hence we went for `after`
Expand Down Expand Up @@ -517,7 +517,7 @@ module CanUseNewRegistrationWorkflow
transitions from: :worldpay_form,
to: :payment_summary_form

transitions from: :bank_transfer_form,
transitions from: :confirm_bank_transfer_form,
to: :payment_summary_form
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module CanUseRenewingRegistrationWorkflow
state :cards_form
state :payment_summary_form
state :worldpay_form
state :bank_transfer_form
state :confirm_bank_transfer_form

state :renewal_complete_form
state :renewal_received_form
Expand Down Expand Up @@ -257,7 +257,7 @@ module CanUseRenewingRegistrationWorkflow
if: :paying_by_card?

transitions from: :payment_summary_form,
to: :bank_transfer_form
to: :confirm_bank_transfer_form

transitions from: :worldpay_form,
to: :renewal_received_form,
Expand All @@ -273,7 +273,7 @@ module CanUseRenewingRegistrationWorkflow
# callback block, hence we went for `after`
after: :set_metadata_route

transitions from: :bank_transfer_form,
transitions from: :confirm_bank_transfer_form,
to: :renewal_received_form,
success: :send_renewal_received_email,
# TODO: This don't get triggered if in the `success`
Expand Down Expand Up @@ -450,7 +450,7 @@ module CanUseRenewingRegistrationWorkflow
transitions from: :worldpay_form,
to: :payment_summary_form

transitions from: :bank_transfer_form,
transitions from: :confirm_bank_transfer_form,
to: :payment_summary_form

# Exit routes from renewals process
Expand Down
85 changes: 0 additions & 85 deletions app/views/waste_carriers_engine/bank_transfer_forms/new.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%= render("waste_carriers_engine/shared/back", back_path: back_confirm_bank_transfer_forms_path(@confirm_bank_transfer_form.token)) %>

<div class="text">
<%= form_for(@confirm_bank_transfer_form) do |f| %>
<h1 class="heading-large"><%= t(".heading") %></h1>

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

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

<p>
<%= link_to(t(".link_text"),
back_confirm_bank_transfer_forms_path(@confirm_bank_transfer_form.token)) %>
</p>

<div class="form-group">
<%= f.submit t(".next_button"), class: "button" %>
</div>
<% end %>
</div>
34 changes: 0 additions & 34 deletions config/locales/forms/bank_transfer_forms/en.yml

This file was deleted.

10 changes: 10 additions & 0 deletions config/locales/forms/confirm_bank_transfer_forms/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
en:
waste_carriers_engine:
confirm_bank_transfer_forms:
new:
title: Pay by bank transfer
heading: Registration takes longer if you pay by bank transfer
paragraph_1: "In order to pay by bank transfer, you will need to follow the instructions on the next screen and email us to confirm payment. This will take approximately 5 working days."
paragraph_2: "In most cases we can provide instant confirmation if you pay by card."
link_text: "Go back to pay by credit or debit card instead"
next_button: "Confirm you’ll pay by bank transfer"
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,12 +566,12 @@
on: :collection
end

resources :bank_transfer_forms,
resources :confirm_bank_transfer_forms,
only: %i[new create],
path: "bank-transfer",
path: "confirm-bank-transfer",
path_names: { new: "" } do
get "back",
to: "bank_transfer_forms#go_back",
to: "confirm_bank_transfer_forms#go_back",
as: "back",
on: :collection
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

FactoryBot.define do
factory :bank_transfer_form, class: WasteCarriersEngine::BankTransferForm do
factory :confirm_bank_transfer_form, class: WasteCarriersEngine::ConfirmBankTransferForm do
trait :has_required_data do
initialize_with { new(create(:renewing_registration, :has_required_data, workflow_state: "bank_transfer_form")) }
initialize_with { new(create(:renewing_registration, :has_required_data, workflow_state: "confirm_bank_transfer_form")) }
end
end
end
29 changes: 0 additions & 29 deletions spec/forms/waste_carriers_engine/bank_transfer_forms_spec.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require "rails_helper"

module WasteCarriersEngine
RSpec.describe ConfirmBankTransferForm, type: :model do
describe "#submit" do
let(:confirm_bank_transfer_form) { build(:confirm_bank_transfer_form, :has_required_data) }

context "when the form is valid" do
let(:valid_params) { { token: confirm_bank_transfer_form.token } }

it "should submit" do
expect(confirm_bank_transfer_form.submit(valid_params)).to eq(true)
end
end

context "when the form is not valid" do
before do
expect(confirm_bank_transfer_form).to receive(:valid?).and_return(false)
end

it "should not submit" do
expect(confirm_bank_transfer_form.submit({})).to eq(false)
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

module WasteCarriersEngine
RSpec.describe NewRegistration do
subject { build(:new_registration, workflow_state: "bank_transfer_form") }
subject { build(:new_registration, workflow_state: "confirm_bank_transfer_form") }

describe "#workflow_state" do
context ":bank_transfer_form state transitions" do
context ":confirm_bank_transfer_form state transitions" do
context "on next" do
include_examples "has next transition", next_state: "registration_received_pending_payment_form"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module WasteCarriersEngine
include_examples "has next transition", next_state: "worldpay_form"
end

include_examples "has next transition", next_state: "bank_transfer_form"
include_examples "has next transition", next_state: "confirm_bank_transfer_form"
end

context "on back" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module WasteCarriersEngine
end
end

context "when transitioning from bank_transfer_form to renewal_received_form succesfully" do
context "when transitioning from confirm_bank_transfer_form to renewal_received_form succesfully" do
it "set the transient registration metadata route" do
expect(renewing_registration).to receive(:set_metadata_route).once

renewing_registration.update_attributes(workflow_state: :bank_transfer_form)
renewing_registration.update_attributes(workflow_state: :confirm_bank_transfer_form)
renewing_registration.next
end
end
Expand Down
Loading