Skip to content

Commit

Permalink
[Sutton] Add admin payment for brown/green bins.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Mar 22, 2024
1 parent 2850d02 commit 6cc4a9c
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 10 deletions.
1 change: 1 addition & 0 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,7 @@ sub request : Chained('property') : Args(0) {
request => {
fields => [ grep { ! ref $_ } @$field_list, 'submit' ],
title => $title,
$c->cobrand->moniker eq 'sutton' ? (intro => 'request/intro.html') : (),
check_unique_id => 0,
next => $next,
},
Expand Down
7 changes: 3 additions & 4 deletions perllib/FixMyStreet/App/Form/Waste/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ has_page summary => (
# For payments, updating the submit button
update_field_list => sub {
my $form = shift;
if ($form->can('summary_submit_button_label')) {
if (my $label = $form->summary_submit_button_label($form->saved_data)) {
return { submit => { value => $label } };
}
my $data = $form->saved_data;
if ($data->{payment}) {
return { submit => { value => 'Continue to payment' } };
}
return {};
},
Expand Down
10 changes: 10 additions & 0 deletions perllib/FixMyStreet/App/Form/Waste/Request/Sutton.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ has_page replacement => (
fields => ['request_reason', 'continue'],
title => 'Reason for request',
next => 'about_you',
post_process => sub {
my $form = shift;
my $data = $form->saved_data;
my $c = $form->c;
if ($data) {
my $choice = $data->{'container-choice'};
my ($cost, $hint) = $c->cobrand->request_cost($choice, $c->stash->{quantities});
$data->{payment} = $cost if $cost;
}
},
);

has_field request_reason => (
Expand Down
26 changes: 26 additions & 0 deletions perllib/FixMyStreet/Cobrand/Sutton.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package FixMyStreet::Cobrand::Sutton;
use parent 'FixMyStreet::Cobrand::UKCouncils';

use utf8;
use Moo;
with 'FixMyStreet::Roles::CobrandSLWP';
with 'FixMyStreet::Roles::SCP';
Expand All @@ -14,6 +15,11 @@ sub council_name { return 'Sutton Council'; }
sub council_url { return 'sutton'; }
sub admin_user_domain { 'sutton.gov.uk' }

use constant CONTAINER_REFUSE_140 => 1;
use constant CONTAINER_REFUSE_240 => 2;
use constant CONTAINER_REFUSE_360 => 3;
use constant CONTAINER_PAPER_BIN => 19;

=head2 waste_on_the_day_criteria
If it's before 6pm on the day of collection, treat an Outstanding/Allocated
Expand Down Expand Up @@ -196,6 +202,26 @@ around garden_cc_check_payment_status => sub {
}
};

=head2 request_cost
Calculate how much, if anything, a request for a container should be.
=cut

sub request_cost {
my ($self, $id, $containers) = @_;
if (my $cost = $self->_get_cost('request_replace_cost')) {
foreach (CONTAINER_REFUSE_140, CONTAINER_REFUSE_240, CONTAINER_REFUSE_360, CONTAINER_PAPER_BIN) {
if ($id == $_) {
my $price = sprintf("£%.2f", $cost / 100);
$price =~ s/\.00$//;
my $hint = "There is a $price administration/delivery charge to replace your container";
return ($cost, $hint);
}
}
}
}

=head2 Bulky waste collection
Sutton starts collections at 6am, and lets you cancel up until 6am.
Expand Down
3 changes: 2 additions & 1 deletion perllib/FixMyStreet/Roles/CobrandEcho.pm
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ sub _get_cost_from_array {

sub _get_cost {
my ($self, $cost_ref, $date) = @_;
my $cost = $self->feature('payment_gateway')->{$cost_ref};
my $payments = $self->feature('payment_gateway');
my $cost = $payments->{$cost_ref};
if (ref $cost eq 'ARRAY') {
$cost = $self->_get_cost_from_array($cost, $date);
}
Expand Down
12 changes: 11 additions & 1 deletion perllib/FixMyStreet/Roles/CobrandSLWP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ containers.

sub waste_munge_request_form_fields {
my ($self, $field_list) = @_;
my $c = $self->{c};

my @radio_options;
my %seen;
Expand All @@ -778,10 +779,17 @@ sub waste_munge_request_form_fields {
next unless $key =~ /^container-(\d+)/;
my $id = $1;
next if $self->moniker eq 'kingston' && $seen{$id};

my ($cost, $hint);
if ($self->moniker eq 'sutton') {
($cost, $hint) = $self->request_cost($id, $c->stash->{quantities});
}

push @radio_options, {
value => $id,
label => $self->{c}->stash->{containers}->{$id},
disabled => $value->{disabled},
$hint ? (hint => $hint) : (),
};
$seen{$id} = 1;
}
Expand Down Expand Up @@ -964,7 +972,7 @@ sub garden_waste_new_bin_admin_fee {

=head2 waste_cc_payment_line_item_ref
This is only used by Kingston (which uses the SCP role) to provide the
This is used by the SCP role (all Kingston, Sutton requests) to provide the
reference for the credit card payment. It differs for bulky waste.
=cut
Expand All @@ -973,6 +981,8 @@ sub waste_cc_payment_line_item_ref {
my ($self, $p) = @_;
if ($p->category eq 'Bulky collection') {
return $self->_waste_cc_line_item_ref($p, "BULKY", "");
} elsif ($p->category eq 'Request new container') {
return $self->_waste_cc_line_item_ref($p, "REQ", "");
} else {
return $self->_waste_cc_line_item_ref($p, "GGW", "GW Sub");
}
Expand Down
80 changes: 77 additions & 3 deletions t/app/controller/waste_sutton_r.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,14 @@ create_contact({ category => 'Request new container', email => '1635' }, 'Waste'
{ code => 'Container_Type', required => 1, automated => 'hidden_field' },
{ code => 'Action', required => 1, automated => 'hidden_field' },
{ code => 'Reason', required => 1, automated => 'hidden_field' },
{ code => 'LastPayMethod', required => 0, automated => 'hidden_field' },
{ code => 'PaymentCode', required => 0, automated => 'hidden_field' },
{ code => 'payment_method', required => 0, automated => 'hidden_field' },
{ code => 'payment', required => 0, automated => 'hidden_field' },
);

my $sent_params;

FixMyStreet::override_config {
ALLOWED_COBRANDS => 'sutton',
MAPIT_URL => 'http://mapit.uk/',
Expand All @@ -64,13 +70,19 @@ FixMyStreet::override_config {
url => 'http://example.org/',
} },
waste => { sutton => 1 },
echo => { sutton => { bulky_service_id => 413 }}
echo => { sutton => { bulky_service_id => 413 }},
payment_gateway => { sutton => {
cc_url => 'http://example.com',
request_replace_cost => 500,
} },
},
STAGING_FLAGS => {
send_reports => 1,
},
}, sub {
my ($e) = shared_echo_mocks();
my ($scp) = shared_scp_mocks();

subtest 'Address lookup' => sub {
set_fixed_time('2022-09-10T12:00:00Z');
$mech->get_ok('/waste/12345');
Expand Down Expand Up @@ -109,14 +121,31 @@ FixMyStreet::override_config {
$mech->submit_form_ok({ with_fields => { 'container-choice' => 19 }});
$mech->submit_form_ok({ with_fields => { 'request_reason' => 'damaged' }});
$mech->submit_form_ok({ with_fields => { name => 'Bob Marge', email => $user->email }});
$mech->submit_form_ok({ with_fields => { process => 'summary' } });
$mech->content_contains('Continue to payment');

my $mech2 = $mech->clone;
$mech2->submit_form_ok({ with_fields => { process => 'summary' } });
is $mech2->res->previous->code, 302, 'payments issues a redirect';
is $mech2->res->previous->header('Location'), "http://example.org/faq", "redirects to payment gateway";
is $sent_params->{items}[0]{amount}, 500;

my ( $token, $report, $report_id ) = get_report_from_redirect( $sent_params->{returnUrl} );
$mech->get_ok("/waste/pay_complete/$report_id/$token");

$mech->content_contains('request has been sent');
$mech->content_contains('Containers typically arrive within 20 working days');
my $report = FixMyStreet::DB->resultset("Problem")->search(undef, { order_by => { -desc => 'id' } })->first;

is $report->get_extra_field_value('uprn'), 1000000002;
is $report->detail, "Quantity: 1\n\n2 Example Street, Sutton, SM1 1AA\n\nReason: Damaged";
is $report->category, 'Request new container';
is $report->title, 'Request new Paper and Cardboard Green Wheelie Bin (240L)';
is $report->get_extra_field_value('payment'), 500, 'correct payment';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
is $report->get_extra_field_value('Container_Type'), 19, 'correct bin type';
is $report->get_extra_field_value('Action'), 3, 'correct container request action';
is $report->state, 'unconfirmed', 'report not confirmed';
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';

FixMyStreet::Script::Reports::send();
my $email = $mech->get_text_body_from_email;
like $email, qr/please allow up to 20 working days/;
Expand Down Expand Up @@ -288,6 +317,18 @@ FixMyStreet::override_config {
};
};

sub get_report_from_redirect {
my $url = shift;

my ($report_id, $token) = ( $url =~ m#/(\d+)/([^/]+)$# );
my $new_report = FixMyStreet::DB->resultset('Problem')->find( {
id => $report_id,
});

return undef unless $new_report->get_extra_metadata('redirect_id') eq $token;
return ($token, $new_report, $report_id);
}

sub shared_echo_mocks {
my $e = Test::MockModule->new('Integrations::Echo');
$e->mock('GetPointAddress', sub {
Expand All @@ -310,4 +351,37 @@ sub shared_echo_mocks {
return $e;
}

sub shared_scp_mocks {
my $pay = Test::MockModule->new('Integrations::SCP');

$pay->mock(pay => sub {
my $self = shift;
$sent_params = shift;
return {
transactionState => 'IN_PROGRESS',
scpReference => '12345',
invokeResult => {
status => 'SUCCESS',
redirectUrl => 'http://example.org/faq'
}
};
});
$pay->mock(query => sub {
my $self = shift;
$sent_params = shift;
return {
transactionState => 'COMPLETE',
paymentResult => {
status => 'SUCCESS',
paymentDetails => {
paymentHeader => {
uniqueTranId => 54321
}
}
}
};
});
return $pay;
}

done_testing;
4 changes: 4 additions & 0 deletions templates/web/sutton/waste/request/intro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>
Any Sutton specific request container introductory text here.
Including details/link about needing a 360l for medical purposes.
</p>
8 changes: 8 additions & 0 deletions templates/web/sutton/waste/summary_request.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
<dt class="govuk-summary-list__key govuk-summary-list__key--sub">[% containers.$container_id %]</dt>
<dd class="govuk-summary-list__value">[% data.request_reason.ucfirst %]</dd>
</div>

[% IF data.payment %]
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key govuk-summary-list__key--sub">Administration/delivery charge</dt>
<dd class="govuk-summary-list__value">£[% tprintf( '%.2f', data.payment / 100 ) %]</dd>
</div>
[% END %]

[% END %]

[% PROCESS waste/summary.html %]
Expand Down
2 changes: 1 addition & 1 deletion web/cobrands/sutton/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ p.form-error {
.content[role="main"] {
background-color: $white;

label {
label:last-child {
margin-bottom: 0.5em;
}
}
Expand Down

0 comments on commit 6cc4a9c

Please sign in to comment.