Skip to content

Commit

Permalink
[Bromley] [Waste] No refunds for unpaid bulky bookings.
Browse files Browse the repository at this point in the history
  • Loading branch information
neprune authored and dracos committed Nov 17, 2023
1 parent b951a75 commit 4aff6ed
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
8 changes: 7 additions & 1 deletion perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,14 @@ sub bulky_location_text_prompt {

sub bulky_minimum_charge { $_[0]->wasteworks_config->{per_item_min_collection_price} }

sub bulky_booking_paid {
my ($self, $collection) = @_;
return $collection->get_extra_metadata('payment_reference');
}

sub bulky_can_refund_collection {
my ($self, $collection) = @_;
return 0 if !$self->bulky_booking_paid($collection);
return 0 if !$self->within_bulky_cancel_window($collection);
return $self->bulky_refund_amount($collection) > 0;
}
Expand All @@ -1047,7 +1053,7 @@ sub bulky_send_cancellation_confirmation {
],

wasteworks_id => $collection_report->id,
payment_reference => $collection_report->get_extra_metadata('payment_reference'),
paid => $self->bulky_booking_paid($collection_report),
refund_amount => $self->bulky_refund_amount($collection_report),
collection_date => $self->bulky_nice_collection_date($collection_report),
},
Expand Down
35 changes: 34 additions & 1 deletion t/app/controller/waste_bromley_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,39 @@ FixMyStreet::override_config {

$mech->clear_emails_ok();

subtest 'No payment yet made' => sub {
$report->unset_extra_metadata('payment_reference');
$report->update;
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_lacks('If you cancel you will be refunded £30.00');
$mech->submit_form_ok( { with_fields => { confirm => 1 } } );
$mech->content_contains('Your booking has been cancelled');
$mech->content_lacks('If you need to contact us about your application please use the application reference');

my $report_id = $report->id;
my $email = $mech->get_email;
subtest 'Sends cancellation confirmation' => sub {
is $email->header('Subject'),
'Cancelled bulky goods collection ' . $report_id,
'Correct subject';
is $email->header('To'),
'"Bob Marge"' . ' <' . $report->user->email . '>',
'Correct recipient';
my $text = $email->as_string;
like $text, qr/Bulky goods collection slot ${report_id}/, "Correct ID";
like $text, qr/scheduled for 01 July/, "Correct scheduled time";
unlike $text, qr/=C2=A30.01 will be refunded/, "Correct refund amount";
};

# No refund email

$report->discard_changes;
$report->set_extra_metadata(payment_reference => 12345);
$report->state('confirmed');
$report->update;
$mech->clear_emails_ok;
};

subtest 'Refund info' => sub {
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_contains('If you cancel you will be refunded £30.00');
Expand Down Expand Up @@ -494,7 +527,7 @@ FixMyStreet::override_config {
'"Bob Marge"' . ' <' . $report->user->email . '>',
'Correct recipient';
my $text = $email->as_string;
like $text, qr/Bulky goods collection ${report_id}/, "Correct ID";
like $text, qr/Bulky goods collection slot ${report_id}/, "Correct ID";
like $text, qr/scheduled for 01 July/, "Correct scheduled time";
like $text, qr/=C2=A30.01 will be refunded/, "Correct refund amount";
};
Expand Down
4 changes: 2 additions & 2 deletions templates/email/bromley/waste/bulky-confirm-cancellation.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[% USE pounds = format('%.2f'); ~%]
Subject: Cancelled bulky goods collection [% wasteworks_id %]

Bulky goods collection [% wasteworks_id %] scheduled for [%collection_date %] has been cancelled.
Bulky goods collection slot [% wasteworks_id %] scheduled for [%collection_date %] has been cancelled.

[% IF refund_amount > 0 && payment_reference %]
[% IF refund_amount > 0 && paid %]
£[% pounds(refund_amount / 100) %] will be refunded.
[% END %]

Expand Down

0 comments on commit 4aff6ed

Please sign in to comment.