From 7550cf3cb2a1995e06fb90104d87136368d30f2b Mon Sep 17 00:00:00 2001 From: Nik Gupta Date: Mon, 11 Dec 2023 15:01:38 +0000 Subject: [PATCH] [Bromley] [Waste] Fix bookings marked payment failed not being cancelled. --- perllib/FixMyStreet/App/Controller/Waste.pm | 6 ++++ .../FixMyStreet/App/Controller/Waste/Bulky.pm | 6 ++-- t/app/controller/waste_bromley_bulky.t | 31 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index 02b6bad419a..bead5e67626 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -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; } diff --git a/perllib/FixMyStreet/App/Controller/Waste/Bulky.pm b/perllib/FixMyStreet/App/Controller/Waste/Bulky.pm index 60eb0223c24..4d948bfcbd0 100644 --- a/perllib/FixMyStreet/App/Controller/Waste/Bulky.pm +++ b/perllib/FixMyStreet/App/Controller/Waste/Bulky.pm @@ -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 }, }); @@ -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); diff --git a/t/app/controller/waste_bromley_bulky.t b/t/app/controller/waste_bromley_bulky.t index 00515f9f030..9dad665e962 100644 --- a/t/app/controller/waste_bromley_bulky.t +++ b/t/app/controller/waste_bromley_bulky.t @@ -35,6 +35,7 @@ $body->set_extra_metadata( $body->update; my $staff_user = $mech->create_user_ok('bromley@example.org', 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'); @@ -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;