Skip to content

Commit

Permalink
Add "Payments" flow to the Support Claims page.
Browse files Browse the repository at this point in the history
Add secondary navigation to Support claims page
  • Loading branch information
Nitemaeric committed Oct 10, 2024
1 parent 8d5acc9 commit 21321e0
Show file tree
Hide file tree
Showing 62 changed files with 997 additions and 39 deletions.
15 changes: 9 additions & 6 deletions app/assets/stylesheets/components/_heading.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.govuk-heading-l {
.govuk-heading-group {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: govuk-spacing(2);
.govuk-heading-group {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: govuk-spacing(2);
margin-bottom: govuk-spacing(6);

.govuk-heading-l {
margin: 0;
}
}
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/_tag.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.govuk-tag {
max-width: unset;
}

h1 .govuk-tag {
vertical-align: middle;
}
2 changes: 1 addition & 1 deletion app/components/claim/card_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="claim-card">
<div class="claim-card__header">
<div class="claim-card__header__name govuk-heading-s">
<%= govuk_link_to t(".claim_title", reference: claim.reference, school_name: claim.school.name), claims_support_claim_path(claim), no_visited_state: true %>
<%= govuk_link_to t(".claim_title", reference: claim.reference, school_name: claim.school.name), href, no_visited_state: true %>
</div>
<div><%= render Claim::StatusTagComponent.new(claim:, classes: %w[govuk-body-s]) %></div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions app/components/claim/card_component.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Claim::CardComponent < ApplicationComponent
attr_reader :claim
attr_reader :claim, :href

def initialize(claim:, classes: [], html_attributes: {})
def initialize(claim:, href:, classes: [], html_attributes: {})
super(classes:, html_attributes:)

@claim = claim
@href = href
end
end
12 changes: 8 additions & 4 deletions app/components/claim/status_tag_component.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
class Claim::StatusTagComponent < ApplicationComponent
attr_reader :claim

def initialize(claim:, classes: [], html_attributes: {})
super(classes:, html_attributes:)

@claim = claim
end

def call
govuk_tag(text: claim.status.humanize, colour:)
govuk_tag(text: t(".#{claim.status}"), colour:)
end

private

attr_reader :claim

def default_attributes
super.merge!(class: super.class)
end
Expand All @@ -26,7 +26,11 @@ def status_colours
internal_draft: "grey",
draft: "grey",
submitted: "blue",
payment_in_progress: "light-blue",
payment_in_progress: "turquoise",
paid: "green",
payment_information_requested: "light-blue",
payment_information_sent: "yellow",
payment_not_approved: "red",
}.with_indifferent_access
end
end
27 changes: 27 additions & 0 deletions app/controllers/claims/payments/claims_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Claims::Payments::ClaimsController < Claims::ApplicationController
skip_before_action :authenticate_user!

before_action :skip_authorization
before_action :validate_token
before_action :set_payment

def download
send_data Claims::Claim::GenerateCSV.call(claims: @payment.claims), filename: "claims-#{Date.current}.csv"
end

private

def validate_token
@payment_id = Rails.application.message_verifier(:payment).verify(token_param)
rescue ActiveSupport::MessageVerifier::InvalidSignature, ActionController::ParameterMissing
render "errors/link_expired"
end

def token_param
params.require(:token)
end

def set_payment
@payment = Claims::Payment.find(@payment_id)
end
end
8 changes: 6 additions & 2 deletions app/controllers/claims/support/claims_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def show; end
def download_csv
csv_data = Claims::Claim::GenerateCSV.call(claims: @filtered_claims)

send_data csv_data, filename: "claims-#{Date.current}.csv", type: "text/csv", disposition: "attachment"
send_data csv_data, filename: "claims-#{Time.current.iso8601}.csv", type: "text/csv", disposition: "attachment"
end

private

def set_filtered_claims
@filtered_claims = Claims::ClaimsQuery.call(params: filter_form.query_params)
@filtered_claims = Claims::ClaimsQuery.call(params: filter_form.query_params.merge(query_params))
end

def filter_form
Expand All @@ -49,6 +49,10 @@ def filter_params
)
end

def query_params
request.query_parameters.symbolize_keys
end

def set_claim
@claim = Claims::Claim.find(params.require(:id))
end
Expand Down
26 changes: 26 additions & 0 deletions app/controllers/claims/support/payments/claims_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Claims::Support::Payments::ClaimsController < Claims::Support::ApplicationController
before_action :set_claim
before_action :authorize_claim

def information_sent
@claim.update!(status: :payment_information_sent)

redirect_to claims_support_claim_path(@claim)
end

def reject
@claim.update!(status: :payment_not_approved)

redirect_to claims_support_claim_path(@claim)
end

private

def set_claim
@claim = policy_scope(Claims::Claim, policy_scope_class: Claims::Support::Payments::ClaimPolicy::Scope).find(params[:id])
end

def authorize_claim
authorize @claim, policy_class: Claims::Support::Payments::ClaimPolicy
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Claims::Support::Payments::ConfirmationsController < Claims::Support::ApplicationController
before_action :authorize_confirmation

def create
Claims::Payment::ParseConfirmation.call(file: file_param)

redirect_to claims_support_payments_path, flash: { heading: t(".success"), success: true }
end

private

def file_param
params.require(:file)
end

def authorize_confirmation
authorize :confirmation, policy_class: Claims::Support::Payments::ConfirmationPolicy
end

def policy(record = nil)
Claims::Support::Payments::ConfirmationPolicy.new(current_user, record)
end
end
22 changes: 22 additions & 0 deletions app/controllers/claims/support/payments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Claims::Support::PaymentsController < Claims::ApplicationController
before_action :set_claims, only: %i[index]
before_action :authorize_payment

def index; end

def create
Claims::Payment::CreateAndDeliver.call(current_user:)

redirect_to claims_support_payments_path, flash: { heading: t(".success"), success: true }
end

private

def set_claims
@pagy, @claims = pagy(Claims::Claim.where(status: %i[payment_information_requested payment_information_sent]))
end

def authorize_payment
authorize Claims::Payment
end
end
9 changes: 7 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ class ApplicationMailer < Mail::Notify::Mailer
default from: "[email protected]"

def notify_email(subject:, **headers)
headers.merge!(rails_mailer: mailer_name, rails_mail_template: action_name)
view_mail(GENERIC_NOTIFY_TEMPLATE, subject: environment_prefix + subject, **headers)
headers.merge!(
rails_mailer: mailer_name,
rails_mail_template: action_name,
subject: environment_prefix + subject,
)

view_mail(GENERIC_NOTIFY_TEMPLATE, **headers)
end

private
Expand Down
26 changes: 26 additions & 0 deletions app/mailers/claims/payment_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Claims::PaymentMailer < ApplicationMailer
def payment_created_notification(payment)
notify_email to: esfa_email_addresses,
from: t("claims.support_email"),
subject: t(".subject"),
body: t(
".body",
link_to: download_claims_payments_claims_url(token: message_verifier.generate(payment.id, expires_at:)),
service_name:,
)
end

private

def esfa_email_addresses
ENV["CLAIMS_ESFA_EMAIL_ADDRESSES"].split(",")
end

def message_verifier
Rails.application.message_verifier(:payment)
end

def expires_at
30.days.from_now
end
end
5 changes: 5 additions & 0 deletions app/models/claims/claim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# status :enum
# submitted_at :datetime
# submitted_by_type :string
# unpaid_reason :string
# created_at :datetime not null
# updated_at :datetime not null
# claim_window_id :uuid
Expand Down Expand Up @@ -71,6 +72,10 @@ class Claims::Claim < ApplicationRecord
draft: "draft",
submitted: "submitted",
payment_in_progress: "payment_in_progress",
paid: "paid",
payment_information_requested: "payment_information_requested",
payment_information_sent: "payment_information_sent",
payment_not_approved: "payment_not_approved",
},
validate: true

Expand Down
25 changes: 25 additions & 0 deletions app/models/claims/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# == Schema Information
#
# Table name: payments
#
# id :uuid not null, primary key
# claim_ids :string default([]), is an Array
# created_at :datetime not null
# updated_at :datetime not null
# sent_by_id :uuid not null
#
# Indexes
#
# index_payments_on_sent_by_id (sent_by_id)
#
# Foreign Keys
#
# fk_rails_... (sent_by_id => users.id)
#
class Claims::Payment < ApplicationRecord
belongs_to :sent_by, class_name: "Claims::SupportUser"

def claims
@claims ||= Claims::Claim.where(id: claim_ids)
end
end
2 changes: 1 addition & 1 deletion app/policies/claims/claim_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def create?
end

def edit?
claim_claim_window_current? && !record.submitted?
claim_claim_window_current? && (record.internal_draft? || record.draft?)
end

def update?
Expand Down
17 changes: 17 additions & 0 deletions app/policies/claims/payment_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Claims::PaymentPolicy < Claims::ApplicationPolicy
def new?
true
end

def create?
Claims::Claim.submitted.any?
end

def instructions?
true
end

def summary?
true
end
end
17 changes: 17 additions & 0 deletions app/policies/claims/support/payments/claim_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Claims::Support::Payments::ClaimPolicy < Claims::ApplicationPolicy
def information_sent?
user.support_user? && record.payment_information_requested?
end
alias_method :check_information_sent?, :information_sent?

def reject?
user.support_user? && record.payment_information_requested?
end
alias_method :check_reject?, :reject?

class Scope < ApplicationPolicy::Scope
def resolve
scope.where(status: %i[payment_information_requested payment_information_sent])
end
end
end
9 changes: 9 additions & 0 deletions app/policies/claims/support/payments/confirmation_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Claims::Support::Payments::ConfirmationPolicy < Claims::ApplicationPolicy
def new?
true
end

def create?
Claims::Claim.where(status: %i[payment_in_progress payment_information_sent payment_information_requested]).any?
end
end
7 changes: 7 additions & 0 deletions app/queries/claims/claims_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def call
scope = submitted_before(scope)
scope = status_condition(scope)
scope = academic_year_condition(scope)
scope = payment_condition(scope)

scope.order_created_at_desc
end
Expand Down Expand Up @@ -55,4 +56,10 @@ def academic_year_condition(scope)

scope.where(claim_window_id: Claims::ClaimWindow.select(:id).where(academic_year_id: params[:academic_year_ids]))
end

def payment_condition(scope)
return scope if params[:payment_id].blank?

scope.where(id: Claims::Payment.find_by(id: params[:payment_id]).claim_ids)
end
end
Loading

0 comments on commit 21321e0

Please sign in to comment.