Skip to content

Commit

Permalink
[Bulky] Allow retrying of failed CSC payments.
Browse files Browse the repository at this point in the history
Add a form for staff to enter a reference number, and show unconfirmed
bookings on the bin day page.
  • Loading branch information
dracos committed Sep 22, 2023
1 parent a4614cc commit 21f75a4
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 51 deletions.
21 changes: 21 additions & 0 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ sub index : Path : Args(0) {
$c->detach('redirect_to_id', [ $id ]);
}

if (my $id = $c->get_param('continue_id')) {
$c->stash->{continue_id} = $id;
if (my $p = $c->cobrand->problems->search({ state => 'unconfirmed' })->find($id)) {
if ($c->stash->{is_staff} && $c->stash->{waste_features}{bulky_retry_bookings}) {
my $property_id = $p->get_extra_field_value('property_id');
my $saved_data = $c->cobrand->waste_reconstruct_bulky_data($p);
$saved_data->{continue_id} = $id;
my $saved_data_field = FixMyStreet::App::Form::Field::JSON->new(name => 'saved_data');
$saved_data = $saved_data_field->deflate_json($saved_data);
$c->set_param(saved_data => $saved_data);
$c->set_param('goto', 'summary');
$c->go('/waste/bulky/index', [ $property_id ], []);
}
}
$c->stash->{form} = {
errors => 1,

Check warning on line 91 in perllib/FixMyStreet/App/Controller/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Waste.pm#L91

Added line #L91 was not covered by tests
all_form_errors => [ 'That booking reference could not be found' ],
};
return;

Check warning on line 94 in perllib/FixMyStreet/App/Controller/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Waste.pm#L94

Added line #L94 was not covered by tests
}

$c->cobrand->call_hook( clear_cached_lookups_postcode => $c->get_param('postcode') )
if $c->get_param('postcode');

Expand Down
36 changes: 24 additions & 12 deletions perllib/FixMyStreet/App/Controller/Waste/Bulky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ sub process_bulky_data : Private {

if ($c->stash->{payment}) {
$c->set_param('payment', $c->stash->{payment});
$c->forward('/waste/add_report', [ $data, 1 ]) or return;
if ($data->{continue_id}) {
$c->stash->{report} = $c->cobrand->problems->find($data->{continue_id});
amend_extra_data($c, $c->stash->{report}, $data);
$c->stash->{report}->update;
} else {
$c->forward('/waste/add_report', [ $data, 1 ]) or return;
}
if ( FixMyStreet->staging_flag('skip_waste_payment') ) {
$c->stash->{message} = 'Payment skipped on staging';
$c->stash->{reference} = $c->stash->{report}->id;
Expand Down Expand Up @@ -253,6 +259,23 @@ sub process_bulky_amend : Private {

$p->detail($p->detail . " | Previously submitted as " . $p->external_id);

amend_extra_data($c, $p, $data);

$c->forward('add_cancellation_report');

$p->resend;
$p->external_id(undef);
$p->update;

# Need to reset stashed report to the amended one, not the new cancellation one
$c->stash->{report} = $p;

return 1;
}

sub amend_extra_data {
my ($c, $p, $data) = @_;

$c->cobrand->waste_munge_bulky_amend($p, $data);

if ($data->{location_photo}) {
Expand All @@ -276,17 +299,6 @@ sub process_bulky_amend : Private {
push @bulky_photo_data, $data->{$_} if $data->{$_};
}
$p->photo( join(',', @bulky_photo_data) );

$c->forward('add_cancellation_report');

$p->resend;
$p->external_id(undef);
$p->update;

# Need to reset stashed report to the amended one, not the new cancellation one
$c->stash->{report} = $p;

return 1;
}

sub add_cancellation_report : Private {
Expand Down
9 changes: 8 additions & 1 deletion perllib/FixMyStreet/Cobrand/Peterborough.pm
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,17 @@ sub look_up_property {

my %premises = map { $_->{uprn} => $_ } @$premises;

my $c = $self->{c};
my @pending = $self->find_pending_bulky_collections($uprn)->all;
$self->{c}->stash->{pending_bulky_collections}
$c->stash->{pending_bulky_collections}
= @pending ? \@pending : undef;

my $cfg = $self->feature('waste_features');
if ($cfg->{bulky_retry_bookings} && $c->stash->{is_staff}) {
my @unconfirmed = $self->find_unconfirmed_bulky_collections($uprn)->all;
$c->stash->{unconfirmed_bulky_collections} = @unconfirmed ? \@unconfirmed : undef;
}

return $premises{$uprn};
}

Expand Down
14 changes: 13 additions & 1 deletion perllib/FixMyStreet/Roles/CobrandBulkyWaste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,25 @@ sub bulky_total_cost {
return $c->stash->{payment};
}

sub find_unconfirmed_bulky_collections {
my ( $self, $uprn ) = @_;

return $self->problems->search({
category => 'Bulky collection',
extra => { '@>' => encode_json({ "_fields" => [ { name => 'uprn', value => $uprn } ] }) },
state => 'unconfirmed',
}, {
order_by => { -desc => 'id' }
});
}

sub find_pending_bulky_collections {
my ( $self, $uprn ) = @_;

return $self->problems->search({
category => 'Bulky collection',
extra => { '@>' => encode_json({ "_fields" => [ { name => 'uprn', value => $uprn } ] }) },
state => { '=', [ FixMyStreet::DB::Result::Problem->open_states ] },
state => [ FixMyStreet::DB::Result::Problem->open_states ],
}, {
order_by => { -desc => 'id' }
});
Expand Down
73 changes: 71 additions & 2 deletions t/app/controller/waste_peterborough_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ FixMyStreet::override_config {
bulky_enabled => 1,
bulky_amend_enabled => 'staff',
bulky_multiple_bookings => 1,
bulky_retry_bookings => 1,
bulky_tandc_link => 'peterborough-bulky-waste-tandc.com'
} },
payment_gateway => { peterborough => {
Expand Down Expand Up @@ -1291,16 +1292,41 @@ FixMyStreet::override_config {
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
$mech->content_contains("Confirm Booking");
$mech->content_lacks("Confirm Subscription");
$mech->submit_form_ok({ with_fields => { payenet_code => 123456 } });

my $report = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;

subtest 'Retrying failed payments' => sub {
$mech->submit_form_ok({ with_fields => { payment_failed => 1 } });
my $id = $report->id;
$mech->content_contains("<strong>$id</strong> – can be used to retry the payment");
my $email = $mech->get_text_body_from_email;
like $email, qr/Provide the reference number $id so you/;

$mech->get_ok('/waste');
$mech->submit_form_ok({ with_fields => { continue_id => $id } });
$mech->submit_form_ok({ form_number => 2 }); # Second change answers, the items
$mech->submit_form_ok({ with_fields => { 'item_1' => 'Amplifiers', 'item_2' => 'High chairs', 'item_3' => 'Wardrobes' } });
$mech->submit_form_ok({ with_fields => { location => 'to the side of the drive' } });
$mech->content_contains('Wardrobes');
$mech->submit_form_ok({ with_fields => { tandc => 1 } });

$mech->get_ok('/waste/PE1%203NA:100090215480');
$mech->follow_link_ok({ text_regex => qr/Retry booking/i, });
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
};

$mech->submit_form_ok({ with_fields => { payenet_code => 123456 } });
$report->discard_changes;

is $report->detail, "Address: 1 Pope Way, Peterborough, PE1 3NA";
is $report->category, 'Bulky collection';
is $report->title, 'Bulky goods collection';
is $report->get_extra_field_value('payment_method'), 'csc';
is $report->get_extra_field_value('uprn'), 100090215480;
is $report->get_extra_field_value('DATE'), '2022-08-26T00:00:00';
is $report->get_extra_field_value('CREW NOTES'), 'in the middle of the drive';
is $report->get_extra_field_value('CREW NOTES'), 'to the side of the drive';
is $report->get_extra_field_value('ITEM_01'), 'Amplifiers';
is $report->get_extra_field_value('ITEM_03'), 'Wardrobes';

subtest 'Refund email includes PAYE.net code' => sub {
$report->external_id('Bartec-SR00100001');
Expand Down Expand Up @@ -1420,10 +1446,53 @@ FixMyStreet::override_config {

$report->delete;
$b->mock('Premises_Attributes_Get', sub { [] });

my $cfg = $body->get_extra_metadata('wasteworks_config');
$cfg->{free_mode} = 0;
$cfg->{per_item_costs} = 0;
$body->set_extra_metadata(wasteworks_config => $cfg);
$body->update;
};

};

FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => 'peterborough',
COBRAND_FEATURES => {
bartec => { peterborough => { sample_data => 1 } },
waste => { peterborough => 1 },
waste_features => { peterborough => {
bulky_enabled => 1,
bulky_multiple_bookings => 1,
bulky_retry_bookings => 0,
bulky_tandc_link => 'peterborough-bulky-waste-tandc.com'
} },
},
}, sub {
my ($b, $jobs_fsd_get, $fs_get) = shared_bartec_mocks();
subtest 'Bulky collection, payment by staff, no retrying enabled' => sub {
$mech->log_in_ok($staff->email);
$mech->get_ok('/waste/PE1%203NA:100090215480/bulky');
$mech->submit_form_ok;
$mech->submit_form_ok({ with_fields => { resident => 'Yes' } });
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form_ok({ with_fields => { chosen_date => '2022-08-26T00:00:00' } });
$mech->submit_form_ok({ with_fields => { 'item_1' => 'Amplifiers', 'item_2' => 'High chairs' } });
$mech->submit_form_ok({ with_fields => { location => 'in the middle of the drive' } });
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
$mech->submit_form_ok({ with_fields => { payment_failed => 1 } });
$mech->content_lacks("can be used to retry the payment");

my $email = $mech->get_text_body_from_email;
unlike $email, qr/Provide the reference number/;
$mech->get_ok('/waste');
$mech->content_lacks('continue_id');
$mech->get_ok('/waste/PE1%203NA:100090215480');
$mech->content_lacks('Retry booking');
};
};

FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
ALLOWED_COBRANDS => 'peterborough',
Expand Down
8 changes: 5 additions & 3 deletions templates/email/default/waste/csc_payment_failed.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
[% start_padded_box | safe %]
<h1 style="[% h1_style %]">There was a problem with your payment</h1>
[% IF report.category == 'Bulky collection' %]
<p style="[% p_style %]">There was a problem taking payment for your [% report.title %]. No details have been saved for the booking.</p>

<p style="[% p_style %]">Please contact 01733 747474 to start again; if you feel you will have difficulty with the auto payment system please advise the call handler at the start of the call.</p>
<p style="[% p_style %]">There was a problem taking payment for your [% report.title %].</p>
<p style="[% p_style %]">Please contact 01733 747474; if you feel you will have difficulty with the auto payment system please advise the call handler at the start of the call.</p>
[% IF waste_features.bulky_retry_bookings %]
<p style="[% p_style %]">Provide the reference number <strong>[% report.id %]</strong> so you do not have to provide details of your collection again.</p>
[% END %]
[% ELSE %]
<p style="[% p_style %]">There was a problem taking payment for your [% report.title %]</p>

Expand Down
8 changes: 6 additions & 2 deletions templates/email/default/waste/csc_payment_failed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Subject: There was a problem with your payment: [% report.title %]
Hello [% report.name %],

[% IF report.category == 'Bulky collection' ~%]
There was a problem taking payment for your [% report.title %]. No details have been saved for the booking.
There was a problem taking payment for your [% report.title %].

Please contact 01733 747474 to start again; if you feel you will have difficulty with the auto payment system please advise the call handler at the start of the call.
Please contact 01733 747474; if you feel you will have difficulty with the auto payment system please advise the call handler at the start of the call.

[% IF waste_features.bulky_retry_bookings %]
Provide the reference number [% report.id %] so you do not have to provide details of your collection again.
[% END %]
[% ELSE ~%]
There was a problem collecting payment for your [% report.title %]. Please
contact the Customer Service Centre to try again.
Expand Down
66 changes: 43 additions & 23 deletions templates/web/base/waste/bulky/_bin_days_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,30 @@
</div>

[% FOR booking IN pending_bulky_collections %]

[% IF c.cobrand.bulky_can_view_collection(booking) %]
<!-- #01 Should only display when: There IS a booking AND is a signed user -->
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Next collection</dt>
<dd class="govuk-summary-list__value">[% c.cobrand.bulky_nice_collection_date(booking) %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Reference number</dt>
<dd class="govuk-summary-list__value">[% booking.id %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Items to be collected</dt>
<dd class="govuk-summary-list__value">
<p class="govuk-!-margin-bottom-0">[% c.cobrand.bulky_nice_item_list(booking).size %]</p>
</dd>
</div>
<!-- END #01 -->
[% END %]
[% NEXT UNLESS c.cobrand.bulky_can_view_collection(booking) %]
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Next collection</dt>
<dd class="govuk-summary-list__value">[% c.cobrand.bulky_nice_collection_date(booking) %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Reference number</dt>
<dd class="govuk-summary-list__value">[% booking.id %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Items to be collected</dt>
<dd class="govuk-summary-list__value">
<p class="govuk-!-margin-bottom-0">[% c.cobrand.bulky_nice_item_list(booking).size %]</p>
</dd>
</div>

<div class="waste-services-launch-panel">
[% IF c.cobrand.bulky_can_view_collection(booking) %]
<!-- #05 Should only display when: There IS a booking AND is a signed user -->
<a class="btn btn-primary govuk-!-margin-bottom-2" href="/report/[% booking.id %]">Check collection details</a>
[% IF c.cobrand.bulky_can_amend_collection(booking) %]
<a class="btn btn-primary govuk-!-margin-bottom-2" href="[% c.uri_for_action('waste/bulky/amend', [ property.id, booking.id ]) %]">Amend booking</a>
[% END %]
[% IF c.cobrand.bulky_collection_can_be_cancelled(booking) %]
<a class="btn btn-primary govuk-!-margin-bottom-2" href="[% c.uri_for_action('waste/bulky/cancel', [ property.id, booking.id ]) %]">Cancel booking</a>
[% END %]
<!-- END #05 -->
[% END %]
</div>
[% END %]

Expand All @@ -71,6 +63,34 @@
[% END %]
</dl>

[% IF unconfirmed_bulky_collections %]
<hr>
<dl class="govuk-summary-list govuk-!-margin-bottom-0">

<h2>Unconfirmed&nbsp;bookings</h2>
[% FOR booking IN unconfirmed_bulky_collections %]
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Collection date</dt>
<dd class="govuk-summary-list__value">[% c.cobrand.bulky_nice_collection_date(booking) %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Reference number</dt>
<dd class="govuk-summary-list__value">[% booking.id %]</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Items to be collected</dt>
<dd class="govuk-summary-list__value">
<p class="govuk-!-margin-bottom-0">[% c.cobrand.bulky_nice_item_list(booking).size %]</p>
</dd>
</div>

<div class="waste-services-launch-panel">
<a class="btn btn-primary govuk-!-margin-bottom-2" href="[% c.uri_for_action('waste/index', { continue_id => booking.id }) %]">Retry booking</a>
</div>
[% END %]
</dl>
[% END %]

<hr>

<div class="waste-services-launch-panel">
Expand Down
4 changes: 2 additions & 2 deletions templates/web/base/waste/bulky/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[% BLOCK change_answers_button %]
[% UNLESS problem %]
<form method="post">
<form method="post" action="[% c.uri_for_action('waste/bulky/index', [ property.id ]) %]">
<input type="hidden" name="saved_data" value="[% form.fif.saved_data %]">
<input type="hidden" name="goto" value="[% goto %]">
<input type="submit" class="fake-link" value="Change answers">
Expand Down Expand Up @@ -187,7 +187,7 @@ <h3 class="summary-section--heading">Location details</h3>
<div class="govuk-grid-column-one-third">
<div class="summary-section-header">
<h3 class="summary-section--heading">Your details</h3>
[% PROCESS change_answers_button goto='about_you' %]
[% IF NOT data.continue_id %][% PROCESS change_answers_button goto='about_you' %][% END %]
</div>
<dl>
<dt>Name</dt>
Expand Down
Loading

0 comments on commit 21f75a4

Please sign in to comment.