Skip to content

Commit

Permalink
[Bromley] [Waste] Update bulky refund text.
Browse files Browse the repository at this point in the history
  • Loading branch information
neprune committed Oct 9, 2023
1 parent 5d48342 commit c80b5ee
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 8 deletions.
29 changes: 28 additions & 1 deletion perllib/FixMyStreet/Cobrand/Bromley.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils';
use strict;
use warnings;
use utf8;
use DateTime;
use DateTime::Format::Strptime;
use DateTime::Format::W3CDTF;
use Integrations::Echo;
Expand Down Expand Up @@ -1007,9 +1008,16 @@ sub bulky_free_collection_available { 0 }
sub bulky_hide_later_dates { 1 }
sub bulky_send_before_payment { 1 }

# TODO: Enforce the minumum charge.
sub bulky_minimum_charge {
my $self = shift;
$self->feature('waste_features')->{bulky_minimum_charge};
}

sub bulky_can_refund_collection {
my ($self, $collection) = @_;
return $self->within_bulky_cancel_window($collection);
return 0 if !$self->within_bulky_cancel_window($collection);
return $self->bulky_refund_amount($collection) > 0;
}

sub bulky_refund_collection {
Expand Down Expand Up @@ -1038,6 +1046,25 @@ sub bulky_refund_collection {
);
}

sub bulky_refund_would_be_partial {
my ($self, $collection) = @_;
my $d = $self->collection_date($collection);
my $t = $self->_bulky_cancellation_cutoff_date($d);
return $t->subtract( days => 1 ) <= DateTime->now;
}

sub bulky_refund_amount {
my ($self, $collection) = @_;
my $charged = $collection->get_extra_field_value('payment');
if ($self->bulky_refund_would_be_partial($collection)) {
my $refund_amount = $charged - $self->bulky_minimum_charge;
if ($refund_amount < 0) {
return 0;

Check warning on line 1062 in perllib/FixMyStreet/Cobrand/Bromley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bromley.pm#L1062

Added line #L1062 was not covered by tests
}
return $refund_amount;
}
return $charged;
}

sub bulky_allowed_property {
my ( $self, $id ) = @_;
Expand Down
40 changes: 34 additions & 6 deletions t/app/controller/waste_bromley_bulky.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ END { FixMyStreet::App->log->enable('info'); }
my $mech = FixMyStreet::TestMech->new;
my $sample_file = path(__FILE__)->parent->child("sample.jpg");
my $sample_file_2 = path(__FILE__)->parent->child("sample2.jpg");
my $minimum_charge = 3600;

my $user = $mech->create_user_ok('[email protected]');

Expand Down Expand Up @@ -90,6 +91,7 @@ FixMyStreet::override_config {
waste => { bromley => 1 },
waste_features => {
bromley => {
bulky_minimum_charge => $minimum_charge,
bulky_trade_service_id => 532,
bulky_enabled => 1,
bulky_tandc_link => 'tandc_link',
Expand Down Expand Up @@ -411,8 +413,8 @@ FixMyStreet::override_config {
};

# Collection time: 2023-07-01T:07:00:00
# Time within the cancellation window.
my $cancel_time = '2023-07-01T05:59:59Z'; # 06:59:59 UK time
my $full_refund_time = '2023-06-30T05:59:59Z'; # 06:59:59 UK time
my $partial_refund_time = '2023-07-01T05:59:59Z'; # 06:59:59 UK time

# Consider report to have been sent.
$report->external_id('Echo-123');
Expand All @@ -423,17 +425,43 @@ FixMyStreet::override_config {
$mech->get_ok('/report/' . $report->id);
$mech->content_lacks('This collection has been cancelled');

set_fixed_time($cancel_time);
set_fixed_time($full_refund_time);
$mech->get_ok('/report/' . $report->id);
$mech->content_contains("You can cancel this booking till");
$mech->content_contains("07:00 on 01 July 2023");
$mech->content_contains('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_contains('Cancel this booking');
$mech->content_contains('You can get a refund if cancelled by 7am on the day prior to your collection');
$mech->content_contains('You can get a full refund if cancelled by 7am on the day prior to your collection');
$mech->content_contains(
'Cancellations within 24 hours of collection are only eligible for ' .
'a partial refund for any amount paid over the minimum charge.'
);

$mech->clear_emails_ok();

subtest 'Sends refund email' =>sub {
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');

set_fixed_time($partial_refund_time);
$report->update_extra_field({ name => 'payment', value => $minimum_charge });
$report->update;
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_contains(
'Since you paid no more than the minimum charge you ' .
'are not eligible for a refund if you cancel this booking.'
);
$report->update_extra_field({ name => 'payment', value => $minimum_charge + 1 });
$report->update;
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->content_contains(
'Cancellations within 24 hours of collection are only eligibile to ' .
'be refunded the amount paid above the minimum charge £36.00.'
);
$mech->content_contains('If you cancel you will be refunded £0.01.');
};

subtest 'Sends refund email' => sub {
$mech->get_ok('/waste/12345/bulky/cancel/' . $report->id);
$mech->submit_form_ok( { with_fields => { confirm => 1 } } );
$mech->content_contains('Your booking has been cancelled');
Expand All @@ -450,7 +478,7 @@ FixMyStreet::override_config {
my $text = $email->as_string;

# =C2=A3 is the quoted printable for '£'.
like $text, qr/Payment Amount: =C2=A330.00/, "Correct payment amount";
like $text, qr/Payment Amount: =C2=A336.01/, "Correct payment amount";
like $text, qr/Capita SCP Response: 12345/,
'Correct SCP response';
# XXX Not picking up on mocked time
Expand Down
9 changes: 8 additions & 1 deletion templates/web/base/waste/bulky/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ <h3 class="summary-section--heading">Collection date</h3>
<p class="govuk-!-margin-bottom-3">You can cancel this booking till
[% cobrand.bulky_nice_cancellation_cutoff_date(data.chosen_date) %].</p>
[% IF !cobrand.call_hook('bulky_enabled_staff_only') AND cobrand.bulky_can_refund %]
<p class="govuk-!-margin-bottom-0">You can get a refund if cancelled by [% cobrand.bulky_nice_collection_time %] on the day prior to your collection.</p>
<p class="govuk-!-margin-bottom-0">
[% IF cobrand.moniker == 'bromley' %]
You can get a full refund if cancelled by [% cobrand.bulky_nice_collection_time %] on the day prior to your collection.
Cancellations within 24 hours of collection are only eligible for a partial refund for any amount paid over the minimum charge.
[% ELSE %]
You can get a refund if cancelled by [% cobrand.bulky_nice_collection_time %] on the day prior to your collection.
[% END %]
</p>
[% END %]
</div>
</div>
Expand Down
27 changes: 27 additions & 0 deletions templates/web/bromley/waste/bulky/cancel_intro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[% USE pounds = format('%.2f') %]
[% partial = c.cobrand.bulky_refund_would_be_partial(cancelling_booking) %]
[% IF partial %]
[% minimum_charge_amount = c.cobrand.bulky_minimum_charge %]
[% minimum_charge = pounds(minimum_charge_amount / 100) %]
[% partial_explainer = "Cancellations within 24 hours of collection are only eligibile to be refunded the amount paid above the minimum charge £" _ minimum_charge _ "." %]
[% END %]
[% IF entitled_to_refund %]
[% refund_amount = c.cobrand.bulky_refund_amount(cancelling_booking) %]
<h3>Refund</h3>
<p class="govuk-!-margin-bottom-2">
[% IF partial %]
[% partial_explainer %]
[% END %]
If you cancel you will be refunded £[% pounds(refund_amount / 100) %].
</p>
[% ELSE %]
<h3>No Refund Will Be Issued</h3>
<p class="govuk-!-margin-bottom-2">
[% IF partial %]
[% partial_explainer %]
Since you paid no more than the minimum charge you are not eligible for a refund if you cancel this booking.
[% ELSE %]
You are not eligible for a refund if you cancel this booking.
[% END %]
</p>
[% END %]

0 comments on commit c80b5ee

Please sign in to comment.