Skip to content

Commit

Permalink
[Bromley] [Waste] Fix bookings marked payment failed not being cancel…
Browse files Browse the repository at this point in the history
…led.
  • Loading branch information
neprune committed Dec 13, 2023
1 parent 26cf0b7 commit 7550cf3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,12 @@ sub csc_payment_failed : Path('csc_payment_failed') : Args(0) {
$report->update_extra_field({ name => 'payment_reference', value => 'FAILED' });
$report->update;

if (($report->category eq 'Bulky collection' || $report->category eq 'Small items collection') && $c->cobrand->bulky_send_before_payment) {
$c->stash->{cancelling_booking} = $report;
$c->stash->{non_user_cancel} = 1;
$c->forward('bulky/process_bulky_cancellation');
}

$c->stash->{template} = 'waste/garden/csc_payment_failed.html';
$c->detach;
}
Expand Down
6 changes: 4 additions & 2 deletions perllib/FixMyStreet/App/Controller/Waste/Bulky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ sub add_cancellation_report : Private {
$c->cobrand->call_hook( "waste_munge_bulky_cancellation_data", \%data );

if ($c->cobrand->bulky_cancel_by_update) {
my $description = $c->stash->{non_user_cancel} ? "Booking cancelled" : "Booking cancelled by customer";
$collection_report->add_to_comments({
text => 'Booking cancelled by customer',
text => $description,
user => $collection_report->user,
extra => { bulky_cancellation => 1 },
});
Expand All @@ -409,8 +410,9 @@ sub process_bulky_cancellation : Private {

# Mark original report as closed
$collection_report->state('closed');
my $description = $c->stash->{non_user_cancel} ? "Cancelled" : "Cancelled at user request";
$collection_report->detail(
$collection_report->detail . " | Cancelled at user request", );
$collection_report->detail . " | " . $description );
$collection_report->update;

$c->cobrand->call_hook('bulky_send_cancellation_confirmation' => $collection_report);
Expand Down
31 changes: 30 additions & 1 deletion t/app/controller/waste_bromley_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ $body->set_extra_metadata(
$body->update;

my $staff_user = $mech->create_user_ok('[email protected]', name => 'Council User', from_body => $body);
$staff_user->user_body_permissions->create({ body => $body, permission_type => 'can_pay_with_csc' });
$body->update( { comment_user_id => $staff_user->id } );

my $echo = Test::MockModule->new('Integrations::Echo');
Expand Down Expand Up @@ -687,7 +688,35 @@ FixMyStreet::override_config {
is $cancellation_update->text, "Booking cancelled since payment was not made in time";
is $cancellation_update->get_extra_metadata('bulky_cancellation'), 1;
is $cancellation_update->user_id, $staff_user->id;
}

$p->comments->delete;
$p->delete;
};

subtest "Cancel booking when staff marks as payment failed" => sub {
$mech->log_in_ok($staff_user->email);
$mech->get_ok('/waste/12345/bulky');
$mech->submit_form_ok;
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form_ok({ with_fields => { chosen_date => '2023-07-01T00:00:00;reserve1==;2023-06-25T10:10:00' } });
$mech->submit_form_ok({ with_fields => { 'item_1' => 'BBQ' } });
$mech->submit_form_ok({ with_fields => {location => 'in the middle of the drive' } });
$mech->submit_form_ok({ with_fields => { tandc => 1 } });
$report = FixMyStreet::DB->resultset('Problem')->single();
is $report->state, "confirmed";
$mech->submit_form_ok({ with_fields => { payment_failed => 1 } });
$mech->content_contains('Payment Failed');
$report->discard_changes;
is $report->state, 'closed', "report cancelled after staff marked as payment failed";
my $cancellation_update = $report->comments->first;
is $cancellation_update->text, "Booking cancelled";
is $cancellation_update->get_extra_metadata('bulky_cancellation'), 1;
unlike $report->detail, qr/Cancelled at user request/;
like $report->detail, qr/Cancelled/;
$report->comments->delete;
$report->delete;
};

};

done_testing;
Expand Down

0 comments on commit 7550cf3

Please sign in to comment.