Skip to content

Commit

Permalink
[Kingston] Send through multiple line items.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed May 2, 2024
1 parent 1e7ab53 commit fa1530e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
4 changes: 3 additions & 1 deletion perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,9 @@ sub process_request_data : Private {
my ($id) = /container-(.*)/;
$c->cobrand->call_hook("waste_munge_request_data", $id, $data, $form);
if ($payment) {
$c->set_param('payment', $payment);
unless ($c->cobrand->moniker eq 'kingston') {
$c->set_param('payment', $payment);
}
$c->set_param('payment_method', $data->{payment_method} || 'credit_card');
}
$c->forward('add_report', [ $data, $payment ? 1 : 0 ]) or return;
Expand Down
12 changes: 12 additions & 0 deletions perllib/FixMyStreet/Cobrand/Kingston.pm
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,18 @@ sub waste_munge_request_data {
} else {
$c->set_param('Container_Type', $container_id);
}

if ($data->{payment}) {
my ($cost) = $self->request_cost($container_id); # Will be full price, or nothing if free
if ($cost) {
if ($data->{first_bin_done}) {
$cost = $self->_get_cost('request_replace_cost_more') || $cost/2;
} else {
$data->{first_bin_done} = 1;
}
$c->set_param('payment', $cost);
}
}
}

=head2 request_cost
Expand Down
22 changes: 16 additions & 6 deletions perllib/FixMyStreet/Roles/SCP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ sub waste_cc_get_redirect_url {
my $address = $c->stash->{property}{address};
my @parts = split ',', $address;

my $title = $p->title;
$title = 'Request containers' if $p->get_extra_metadata('grouped_ids');

my @items = ({
amount => $amount,
reference => $customer_ref,
description => $title,
description => $p->title,
lineId => $self->waste_cc_payment_line_item_ref($p),
});
}) if $amount;
if (my $grouped_ids = $p->get_extra_metadata('grouped_ids')) {
foreach my $id (@$grouped_ids) {
my $problem = $c->model('DB::Problem')->find({ id => $id });
my $amount = $problem->get_extra_field_value('payment');
push @items, {
amount => $amount,
reference => $customer_ref,
description => $problem->title,
lineId => $self->waste_cc_payment_line_item_ref($problem),
} if $amount;
}
}

if ($admin_fee) {
push @items, {
amount => $admin_fee,
Expand All @@ -74,7 +84,7 @@ sub waste_cc_get_redirect_url {
backUrl => $backUrl,
ref => $self->waste_cc_payment_sale_ref($p),
request_id => $p->id,
description => $title,
description => $p->title,
name => $p->name,
email => $p->user->email,
uprn => $uprn,
Expand Down
14 changes: 11 additions & 3 deletions t/app/controller/waste_kingston_r.t
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ FixMyStreet::override_config {
$mech->content_contains('Continue to payment');

$mech->waste_submit_check({ with_fields => { process => 'summary' } });
is $sent_params->{items}[0]{amount}, 4500;
my $pay_params = $sent_params;

my ( $token, $report, $report_id ) = get_report_from_redirect( $sent_params->{returnUrl} );
$mech->get_ok("/waste/pay_complete/$report_id/$token");
Expand All @@ -188,13 +188,17 @@ FixMyStreet::override_config {
is $report->detail, "2 Example Street, Kingston, KT1 1AA";
is $report->category, 'Request new container';
is $report->title, 'Request Green recycling bin (240L) collection';
is $report->get_extra_field_value('payment'), 4500, 'correct payment';
is $report->get_extra_field_value('payment'), 1800, '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'), 12, 'correct bin type';
is $report->get_extra_field_value('Action'), 2, 'correct container request action';
is $report->state, 'unconfirmed', 'report not confirmed';
is $report->get_extra_metadata('scpReference'), '12345', 'correct scp reference on report';

my $sent_count = 0;
is $pay_params->{items}[$sent_count]{amount}, 1800;
is $pay_params->{items}[$sent_count++]{lineId}, 'RBK-CCH-' . $report->id . '-Bob Marge';

foreach (@{ $report->get_extra_metadata('grouped_ids') }) {
my $report = FixMyStreet::DB->resultset("Problem")->find($_);
is $report->get_extra_field_value('uprn'), 1000000002;
Expand All @@ -211,7 +215,7 @@ FixMyStreet::override_config {
}
is $report->detail, "2 Example Street, Kingston, KT1 1AA";
is $report->category, 'Request new container';
is $report->get_extra_field_value('payment'), 4500, 'correct payment';
is $report->get_extra_field_value('payment'), 900, 'correct payment';
is $report->get_extra_field_value('payment_method'), 'credit_card', 'correct payment method on report';
if ($report->title =~ /replacement$/) {
is $report->get_extra_field_value('Action'), 3, 'correct container request action';
Expand All @@ -220,6 +224,10 @@ FixMyStreet::override_config {
}
is $report->state, 'confirmed', 'report confirmed';
is $report->get_extra_metadata('scpReference'), undef, 'only original report has SCP ref';
is $pay_params->{items}[$sent_count]{description}, $report->title;
is $pay_params->{items}[$sent_count]{lineId}, 'RBK-CCH-' . $report->id . '-Bob Marge';
is $pay_params->{items}[$sent_count]{amount}, 900;
$sent_count++;
}

FixMyStreet::Script::Reports::send();
Expand Down

0 comments on commit fa1530e

Please sign in to comment.