-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0817e1b
commit c746340
Showing
31 changed files
with
624 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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 @payment.csv_file.download, filename: "payments-claims-#{Time.current.iso8601}.csv" | ||
end | ||
|
||
private | ||
|
||
def validate_token | ||
@payment_id = Rails.application.message_verifier(:payments).verify(token_param) | ||
rescue ActiveSupport::MessageVerifier::InvalidSignature | ||
render "error" | ||
end | ||
|
||
def set_payment | ||
@payment = Claims::Payment.find(@payment_id) | ||
rescue ActiveRecord::RecordNotFound | ||
render "error" | ||
end | ||
|
||
def token_param | ||
params.fetch(:token, nil) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Claims::PaymentMailer < Claims::ApplicationMailer | ||
def payment_created_notification(payment) | ||
@payment = payment | ||
|
||
notify_email to: esfa_email_addresses, | ||
from: support_email, | ||
subject: t(".subject"), | ||
body: t( | ||
".body", | ||
download_page_url: claims_payments_claims_url(token:), | ||
support_email:, | ||
) | ||
end | ||
|
||
private | ||
|
||
def esfa_email_addresses | ||
ENV.fetch("CLAIMS_ESFA_EMAIL_ADDRESSES").split(",") | ||
end | ||
|
||
def token | ||
Rails.application.message_verifier(:payments).generate(@payment.id, expires_in: 7.days) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Claims::Support::Claims::PaymentPolicy < Claims::ApplicationPolicy | ||
def new? | ||
true | ||
end | ||
|
||
def create? | ||
Claims::Claim.submitted.any? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Claims::Support::Claims::Payments::ClaimPolicy < Claims::ApplicationPolicy | ||
def update? | ||
false | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class Claims::Payment::CreateAndDeliver < ApplicationService | ||
def initialize(current_user:) | ||
@current_user = current_user | ||
end | ||
|
||
def call | ||
return if submitted_claims.none? | ||
|
||
ActiveRecord::Base.transaction do |transaction| | ||
csv_file = Claims::Payments::Claim::GenerateCSVFile.call(claims: submitted_claims) | ||
|
||
payment = Claims::Payment.create!(sent_by: current_user, csv_file: File.open(csv_file.to_io), claims: submitted_claims) | ||
|
||
submitted_claims.find_each do |claim| | ||
claim.update!(status: :payment_in_progress, payment_in_progress_at: Time.current) | ||
end | ||
|
||
Claims::ClaimActivity.create!(action: :payment_delivered, user: current_user, record: payment) | ||
|
||
transaction.after_commit do | ||
Claims::PaymentMailer.payment_created_notification(payment).deliver_later | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :current_user | ||
|
||
def submitted_claims | ||
@submitted_claims ||= Claims::Claim.submitted | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "csv" | ||
|
||
class Claims::Payments::Claim::GenerateCSVFile < ApplicationService | ||
HEADERS = %w[ | ||
claim_reference | ||
school_urn | ||
school_name | ||
school_local_authority | ||
claim_amount | ||
school_type_of_establishment | ||
school_group | ||
claim_submission_date | ||
claim_status | ||
claim_unpaid_reason | ||
].freeze | ||
|
||
def initialize(claims:) | ||
@claims = claims | ||
end | ||
|
||
def call | ||
CSV.open(file_name, "w", headers: true) do |csv| | ||
csv << HEADERS | ||
|
||
claims.each do |claim| | ||
csv << [ | ||
claim.reference, | ||
claim.school.urn, | ||
claim.school_name, | ||
claim.school.local_authority_name, | ||
claim.amount.format(symbol: false, decimal_mark: ".", no_cents: false), | ||
claim.school.type_of_establishment, | ||
claim.school.group, | ||
claim.submitted_at&.iso8601, | ||
claim.status, | ||
] | ||
end | ||
|
||
csv | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :claims | ||
|
||
def file_name | ||
Rails.root.join("tmp/payment-claims-#{Time.current}.csv") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description") %></p> | ||
|
||
<p class="govuk-body"><%= t(".support_html", mail_to: govuk_mail_to(t("claims.support_email"), t("claims.support_email_html"))) %></p> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description_html") %></p> | ||
|
||
<p class="govuk-body"><%= t(".support_html", mail_to: govuk_mail_to(t("claims.support_email"), t("claims.support_email_html"))) %></p> | ||
|
||
<%= govuk_button_link_to t(".submit"), download_claims_payments_claims_path(token: params[:token]) %> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%= render "claims/support/primary_navigation", current: :claims %> | ||
<% content_for(:page_title) { sanitize t(".page_title") } %> | ||
|
||
<% content_for(:before_content) do %> | ||
<%= govuk_back_link href: claims_support_claims_payments_path %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-caption-l"><%= t(".page_caption") %></p> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description", count: @submitted_claims.count) %></p> | ||
|
||
<p class="govuk-body"><%= t(".details.heading") %></p> | ||
|
||
<%= govuk_list type: :bullet do %> | ||
<% t(".details.list").each do |item| %> | ||
<li><%= item %></li> | ||
<% end %> | ||
<% end %> | ||
|
||
<%= govuk_warning_text text: t(".warning") %> | ||
|
||
<%= govuk_button_to t(".submit"), claims_support_claims_payments_path %> | ||
|
||
<p class="govuk-body"><%= govuk_link_to t(".cancel"), claims_support_claims_payments_path %></p> | ||
</div> | ||
</div> | ||
</div> |
19 changes: 19 additions & 0 deletions
19
app/views/claims/support/claims/payments/new_not_permitted.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<%= render "claims/support/primary_navigation", current: :claims %> | ||
<% content_for(:page_title) { sanitize t(".page_title") } %> | ||
|
||
<% content_for(:before_content) do %> | ||
<%= govuk_back_link href: claims_support_claims_payments_path %> | ||
<% end %> | ||
|
||
<div class="govuk-width-container"> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<p class="govuk-caption-l"><%= t(".page_caption") %></p> | ||
<h1 class="govuk-heading-l"><%= t(".page_title") %></h1> | ||
|
||
<p class="govuk-body"><%= t(".description") %></p> | ||
|
||
<p class="govuk-body"><%= govuk_link_to t(".cancel"), claims_support_claims_payments_path %></p> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
en: | ||
claims: | ||
payment_mailer: | ||
payment_created_notification: | ||
subject: Claims ready for payment - Claim funding for mentor training | ||
body: | | ||
To ESFA, | ||
These claims from the Claim funding for mentor training service (Claim) are ready for payment — the link to the latest CSV file is valid for 7 days: | ||
[%{download_page_url}](%{download_page_url}) | ||
What you need to do: | ||
1. Check and validate the claims in the CSV file by marking them as ‘paid’ or ‘unpaid’ in the ‘claim_status’ column. | ||
2. If you mark a claim as ‘unpaid’, add the reason in the ‘claim_unpaid_reason’ column. | ||
3. Reply to this email and attach the updated CSV file. | ||
The Claim Support team will follow up on the reasons for unpaid claims and email back an updated version. | ||
If you have a problem opening the link or it has expired, reply to this email and request that it be sent again. | ||
# Give feedback or report a problem | ||
If you have any questions or feedback, please contact the team at [%{support_email}](%{support_email}). | ||
Regards | ||
Claim funding for mentor training team |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
en: | ||
claims: | ||
payments: | ||
claims: | ||
index: | ||
page_title: Download payments file | ||
description_html: Download the Claim funding for mentor training payments <span title="Comma separated values">CSV</span> file. | ||
support_html: If you have any questions, email %{mail_to}. | ||
submit: Download CSV file | ||
error: | ||
page_title: Sorry, there is a problem with the download link | ||
description: You are seeing this page because the download link is not working. It may have timed out or contained an invalid security token. | ||
support_html: Email %{mail_to} to request a new download link. |
Oops, something went wrong.