From 1b6535bbe0ebbdd4f7a37d4b9a0777af5ba93fe7 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 1 Oct 2024 15:03:46 +0100 Subject: [PATCH] [Brent] Apply discount to modifications as well. Use normal cost functions. --- perllib/FixMyStreet/Cobrand/Brent.pm | 11 ++------- perllib/FixMyStreet/Roles/Cobrand/Echo.pm | 6 +++++ perllib/FixMyStreet/Roles/Cobrand/SLWP.pm | 6 ----- t/app/controller/waste_brent_garden.t | 27 ++++++++++++++++++++--- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Brent.pm b/perllib/FixMyStreet/Cobrand/Brent.pm index d0800d0f9ed..417ef0b94b2 100644 --- a/perllib/FixMyStreet/Cobrand/Brent.pm +++ b/perllib/FixMyStreet/Cobrand/Brent.pm @@ -1553,12 +1553,11 @@ sub garden_waste_sacks_cost_pa { sub garden_waste_cost_pa { my ($self, $bin_count) = @_; - $bin_count ||= 1; + my $per_bin_cost = $self->_get_cost('ggw_cost'); + my $cost = $per_bin_cost * $bin_count; - my $cost = $self->feature('payment_gateway')->{ggw_cost} * $bin_count; my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone ); - if ($now->month =~ /^(10|11|12)$/ ) { $cost = $cost/2; } @@ -1595,12 +1594,6 @@ sub apply_garden_waste_discount { sub garden_waste_new_bin_admin_fee { 0 } -sub waste_get_pro_rata_cost { - my $self = shift; - - return $self->feature('payment_gateway')->{ggw_cost}; -} - sub bulky_collection_time { { hours => 7, minutes => 0 } } sub bulky_cancellation_cutoff_time { { hours => 23, minutes => 59 } } sub bulky_cancel_by_update { 1 } diff --git a/perllib/FixMyStreet/Roles/Cobrand/Echo.pm b/perllib/FixMyStreet/Roles/Cobrand/Echo.pm index 96234558793..fd3e3603296 100644 --- a/perllib/FixMyStreet/Roles/Cobrand/Echo.pm +++ b/perllib/FixMyStreet/Roles/Cobrand/Echo.pm @@ -971,6 +971,12 @@ sub garden_waste_cost_pa { return $cost; } +# Same as full cost +sub waste_get_pro_rata_cost { + my ($self, $bins, $end) = @_; + return $self->garden_waste_cost_pa($bins); +} + =head2 garden_waste_cost_pa_in_one_month Returns the cost of garden waste in one month, if it differs from the usual diff --git a/perllib/FixMyStreet/Roles/Cobrand/SLWP.pm b/perllib/FixMyStreet/Roles/Cobrand/SLWP.pm index ae7068a5572..4dd4f7a46f7 100644 --- a/perllib/FixMyStreet/Roles/Cobrand/SLWP.pm +++ b/perllib/FixMyStreet/Roles/Cobrand/SLWP.pm @@ -362,12 +362,6 @@ sub garden_container_data_extract { # We don't have overdue renewals here sub waste_sub_overdue { 0 } -# Same as full cost -sub waste_get_pro_rata_cost { - my ($self, $bins, $end) = @_; - return $self->garden_waste_cost_pa($bins); -} - sub waste_garden_sub_params { my ($self, $data, $type) = @_; my $c = $self->{c}; diff --git a/t/app/controller/waste_brent_garden.t b/t/app/controller/waste_brent_garden.t index 441840b9c2d..6c711559cfc 100644 --- a/t/app/controller/waste_brent_garden.t +++ b/t/app/controller/waste_brent_garden.t @@ -56,6 +56,7 @@ create_contact({ category => 'Amend Garden Subscription', email => 'garden@examp { code => 'System Notes', required => 0, automated => 'hidden_field' }, { code => 'Paid_Collection_Container_Quantity', required => 1, automated => 'hidden_field' }, { code => 'Payment_Value', required => 1, automated => 'hidden_field' }, + { code => 'pro_rata', required => 0, automated => 'hidden_field' }, { code => 'payment', required => 1, automated => 'hidden_field' }, { code => 'payment_method', required => 1, automated => 'hidden_field' }, { code => 'email_renewal_reminders_opt_in', required => 0, automated => 'hidden_field' }, @@ -663,11 +664,13 @@ FixMyStreet::override_config { 'bins_wanted' => 3, 'container_type' => 1, 'container_quantity' => 1, + cost => 2500, }, { 'bins_wanted' => 4, 'container_type' => 1, 'container_quantity' => 2, + cost => 5000, }, { 'bins_wanted' => 1, @@ -689,9 +692,26 @@ FixMyStreet::override_config { email => $user->email } }, 'Request '. $test->{bins_wanted} . ' bins when currently have 2'); $mech->submit_form_ok({ with_fields => { tandc => 1 }}, 'Submit request'); + my $report = FixMyStreet::DB->resultset('Problem')->find({category => 'Amend Garden Subscription'}); - is($report->get_extra_field_value('Container_Type'), $test->{container_type}, $test->{container_type} ? "Container Type is set to request delivery" : "Container Type is not set"); - is($report->get_extra_field_value('Container_Quantity'), $test->{container_quantity}, "Container Quantity is " . ($test->{container_quantity} ? $test->{container_quantity} : 'not set')); + my %check = ( + type => 'Amend', + category => 'Amend Garden Subscription', + quantity => $test->{bins_wanted}, + new_quantity => $test->{container_quantity}, + new_bin_type => $test->{container_type}, + bin_type => undef, + ref_type => 'apn', + ); + if ($test->{bins_wanted} > 2) { + is $mech->res->previous->code, 302, 'payments issues a redirect'; + is $mech->res->previous->header('Location'), 'http://paye.example.org/faq?apnReference=4ab5f886-de7d-4f5b-bbd8-42151a5deb82', "redirects to payment gateway"; + is $sent_params->{items}[0]{amount}, $test->{cost}, 'correct amount used'; + check_extra_data_pre_confirm($report, %check); + } else { + check_extra_data_pre_confirm($report, %check, state => 'confirmed', payment_method => 'csc'); + } + $report->delete; }; }; @@ -871,10 +891,11 @@ sub check_extra_data_pre_confirm { new_quantity => '', new_bin_type => '', ref_type => 'scp', + category => 'Garden Subscription', @_ ); $report->discard_changes; - is $report->category, 'Garden Subscription', 'correct category on report'; + is $report->category, $params{category}, 'correct category on report'; is $report->title, "Garden Subscription - $params{type}", 'correct title on report'; is $report->get_extra_field_value('payment_method'), $params{payment_method}, 'correct payment method on report'; is $report->get_extra_field_value('Paid_Collection_Container_Quantity'), $params{quantity}, 'correct bin count';