Skip to content

Commit

Permalink
[SLWP] Pass in correct payment meta information.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 18, 2024
1 parent 879ec41 commit 9e4a674
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 20 deletions.
28 changes: 28 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Sutton.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
=head1 NAME
Open311::Endpoint::Integration::UK::Sutton
=head1 DESCRIPTION
The Sutton integration. As well as the boilerplate, and setting it as an Echo
integration, this makes sure the right "Payment Taken By" option is chosen for
bulky collections.
=cut

package Open311::Endpoint::Integration::UK::Sutton;

use Moo;
Expand All @@ -10,4 +22,20 @@ around BUILDARGS => sub {
return $class->$orig(%args);
};

around check_for_data_value => sub {
my ($orig, $class, $name, $args, $request, $parent_name) = @_;

# Bulky items
if ($args->{service_code} eq '1636') {
my $method = $args->{attributes}{payment_method} || '';
if ($method eq 'csc' || $method eq 'cheque') {
return 1 if $name eq 'Payment Taken By'; # Council
} elsif ($method eq 'credit_card') {
return 2 if $name eq 'Payment Taken By'; # Veolia
}
}

return $class->$orig($name, $args, $request, $parent_name);
};

1;
32 changes: 29 additions & 3 deletions perllib/Open311/Endpoint/Role/SLWP.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
=head1 NAME
Open311::Endpoint::Role::SLWP
=head1 DESCRIPTION
Special handling for both Kingston and Sutton. This makes sure the right
container types are picked for requests, and that the right payment options are
chosen for garden/bulky.
=cut

package Open311::Endpoint::Role::SLWP;

use Moo::Role;
Expand All @@ -14,9 +26,23 @@ around check_for_data_value => sub {
return 1 if $name eq 'Refuse Bag' && $service eq '2242';
return 1 if $name eq 'Refuse Bin' && ($service eq '2238' || $service eq '2243' || $service eq '3576');

my $method = $args->{attributes}{LastPayMethod} || '';
return 2 if $name eq 'Payment Type' && $method eq 3; # DD
return 3 if $name eq 'Payment Type' && $method eq 4; # 'cheque' (or phone)
# Garden waste
if ($args->{service_code} eq '1638') {
my $method = $args->{attributes}{LastPayMethod} || '';
return 2 if $name eq 'Payment Type' && $method eq 3; # DD
return 3 if $name eq 'Payment Type' && $method eq 4; # 'cheque' (or phone)
}

# Bulky items
if ($args->{service_code} eq '1636') {
# Default in configuration is Payment Type 1 (Card), Payment Method 2 (Website)
my $method = $args->{attributes}{payment_method} || '';
return 2 if $name eq 'Payment Type' && $method eq 'cheque'; # Cheque
if ($name eq 'Payment Method') {
return 1 if $method eq 'csc' || $method eq 'cheque'; # Borough Phone Payment
return 2 if $method eq 'credit_card'; # Borough Website Payment
}
}

return $class->$orig($name, $args, $request, $parent_name);
};
Expand Down
58 changes: 54 additions & 4 deletions t/open311/endpoint/kingston.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use JSON::MaybeXS;
use_ok 'Open311::Endpoint::Integration::UK::Kingston';

use constant EVENT_TYPE_SUBSCRIBE => 1638;
use constant EVENT_TYPE_BULKY => 1636;

my $soap_lite = Test::MockModule->new('SOAP::Lite');
$soap_lite->mock(call => sub {
Expand All @@ -47,7 +48,21 @@ $soap_lite->mock(call => sub {
my @params = ${$args[3]->value}->value;
if (@params == 5) {
my $client_ref = $params[1]->value;
like $client_ref, qr/RBK-2000123|REF-123/;
like $client_ref, qr/RBK-2000123|REF-123|bulky-cc|bulky-phone/;
my $event_type_id = $params[3]->value;
if ($event_type_id == 1636) {
my @data = ${$params[0]->value}->value->value;
my @payment = ${$data[0]->value}->value;
is $payment[0]->value, 1011;
is $payment[1]->value, 1;
my $val = $client_ref eq 'bulky-cc' ? 2 : 1;
@payment = ${$data[1]->value}->value;
is $payment[0]->value, 1012;
is $payment[1]->value, 1; # Always 1
@payment = ${$data[2]->value}->value;
is $payment[0]->value, 1013;
is $payment[1]->value, $val;
}
} elsif (@params == 2) {
is $params[0]->value, '123pay';
my @data = ${$params[1]->value}->value->value;
Expand All @@ -69,7 +84,7 @@ $soap_lite->mock(call => sub {
} elsif ($args[0]->name eq 'GetEvent') {
return SOAP::Result->new(result => {
Id => '123pay',
EventTypeId => 1636,
EventTypeId => EVENT_TYPE_BULKY,
EventStateId => 4002,
});
} elsif ($method eq 'GetEventType') {
Expand All @@ -82,6 +97,9 @@ $soap_lite->mock(call => sub {
] },
},
{ Id => 1008, Name => "Notes" },
{ Id => 1011, Name => "Payment Type" },
{ Id => 1012, Name => "Payment Taken By" },
{ Id => 1013, Name => "Payment Method" },
] },
});
} elsif ($method eq 'PerformEventAction') {
Expand All @@ -102,7 +120,6 @@ my $endpoint = Open311::Endpoint::Integration::Echo::Dummy->new;
my @params = (
POST => '/requests.json',
api_key => 'test',
service_code => EVENT_TYPE_SUBSCRIBE,
first_name => 'Bob',
last_name => 'Mould',
description => "This is the details",
Expand All @@ -116,7 +133,9 @@ my @params = (
);

subtest "POST subscription request OK" => sub {
my $res = $endpoint->run_test_request(@params);
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_SUBSCRIBE,
);
ok $res->is_success, 'valid request'
or diag $res->content;

Expand All @@ -128,6 +147,7 @@ subtest "POST subscription request OK" => sub {

subtest "POST subscription request with client ref provided OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_SUBSCRIBE,
'attribute[client_reference]' => 'REF-123',
);
ok $res->is_success, 'valid request'
Expand All @@ -139,6 +159,36 @@ subtest "POST subscription request with client ref provided OK" => sub {
} ], 'correct json returned';
};

subtest "POST bulky request card payment OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_BULKY,
'attribute[payment_method]' => 'credit_card',
'attribute[client_reference]' => 'bulky-cc',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

subtest "POST bulky request phone payment OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_BULKY,
'attribute[payment_method]' => 'csc',
'attribute[client_reference]' => 'bulky-phone',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

subtest "POST a successful payment" => sub {
my $res = $endpoint->run_test_request(
POST => '/servicerequestupdates.json',
Expand Down
19 changes: 19 additions & 0 deletions t/open311/endpoint/kingston.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ client_reference_prefix: RBK

service_whitelist:
1638: 'Garden subscription'
1636: 'Bulky collection'

service_extra_data:
1636:
payment: 1
payment_method: 1
Payment_Type: 1
Collection_Date: 1
Bulky_Collection_Bulky_Items: 1
Bulky_Collection_Notes: 1
Exact_Location: 1
GUID: 1
reservation: 1
Customer_Selected_Date_Beyond_SLA?: 1
First_Date_Returned_to_Customer: 1

service_id_override:
1638: 409

default_data_event_type:
1636:
Payment Type: 1
Payment Taken By: 1
47 changes: 35 additions & 12 deletions t/open311/endpoint/sutton.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use_ok 'Open311::Endpoint::Integration::UK::Sutton';

use constant EVENT_TYPE_MISSED => 'missed';
use constant EVENT_TYPE_SUBSCRIBE => 1638;
use constant EVENT_TYPE_BULKY => 1636;

my $soap_lite = Test::MockModule->new('SOAP::Lite');
$soap_lite->mock(call => sub {
Expand All @@ -55,17 +56,14 @@ $soap_lite->mock(call => sub {
my $client_ref = $params[1+$offset]->value;
my $event_type = $params[3+$offset]->value;
my $service_id = $params[4+$offset]->value;
like $client_ref, qr/LBS-200012[345]/;
like $client_ref, qr/LBS-200012[3-6]/;
if ($client_ref eq 'LBS-2000124') {
is $event_type, 1566;
is $service_id, 405;
my @data = ${$params[$offset]->value}->value->value;
my @bin = ${$data[0]->value}->value;
is $bin[0]->value, 2000;
is $bin[1]->value, 1;
my @type = ${$data[1]->value}->value;
is $type[0]->value, 1009;
is $type[1]->value, 2;
} elsif ($client_ref eq 'LBS-2000125') {
is $event_type, 1568;
is $service_id, 408;
Expand All @@ -77,16 +75,26 @@ $soap_lite->mock(call => sub {
my @paper = ${$data[0]->value}->value;
is $paper[0]->value, 2002;
is $paper[1]->value, 1;
my @type = ${$data[1]->value}->value;
is $type[0]->value, 1009;
is $type[1]->value, 1;
} elsif ($client_ref eq 'LBS-2000123') {
is $event_type, EVENT_TYPE_SUBSCRIBE;
is $service_id, 409;
my @data = ${$params[$offset]->value}->value->value;
my @paper = ${$data[0]->value}->value;
is $paper[0]->value, 1009;
is $paper[1]->value, 3;
my @type = ${$data[0]->value}->value;
is $type[0]->value, 1009;
is $type[1]->value, 3;
} elsif ($client_ref eq 'LBS-2000126') {
is $event_type, EVENT_TYPE_BULKY;
is $service_id, 413;
my @data = ${$params[$offset]->value}->value->value;
my @type = ${$data[0]->value}->value;
is $type[0]->value, 1009;
is $type[1]->value, 1;
my @method = ${$data[1]->value}->value;
is $method[0]->value, 1010;
is $method[1]->value, 2;
my @by = ${$data[2]->value}->value;
is $by[0]->value, 1011;
is $by[1]->value, 2;
}
return SOAP::Result->new(result => {
EventGuid => '1234',
Expand All @@ -105,6 +113,8 @@ $soap_lite->mock(call => sub {
{ Id => 2001, Name => "Container Mix" },
{ Id => 2002, Name => "Paper" },
{ Id => 1009, Name => "Payment Type" },
{ Id => 1010, Name => "Payment Method" },
{ Id => 1011, Name => "Payment Taken By" },
] },
});
} else {
Expand Down Expand Up @@ -149,7 +159,6 @@ subtest "POST missed bin OK" => sub {
service_code => EVENT_TYPE_MISSED,
'attribute[fixmystreet_id]' => 2000124,
'attribute[service_id]' => 2238,
'attribute[LastPayMethod]' => 3,
);
ok $res->is_success, 'valid request'
or diag $res->content;
Expand All @@ -165,7 +174,6 @@ subtest "POST missed mixed+paper OK" => sub {
service_code => EVENT_TYPE_MISSED,
'attribute[fixmystreet_id]' => 2000125,
'attribute[service_id]' => 2240,
'attribute[LastPayMethod]' => 2,
'attribute[GUID]' => 'd5f79551-3dc4-11ee-ab68-f0c87781f93b',
'attribute[reservation]' => 'reservation==',
);
Expand All @@ -178,4 +186,19 @@ subtest "POST missed mixed+paper OK" => sub {
} ], 'correct json returned';
};

subtest "POST bulky collection OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_BULKY,
'attribute[fixmystreet_id]' => 2000126,
'attribute[payment_method]' => 'credit_card',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

done_testing;
5 changes: 4 additions & 1 deletion t/open311/endpoint/sutton.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ service_whitelist:
missed: 'Report missed collection'
1635: 'Request new container'
1638: 'Garden Subscription'
1636: 'Bulky collection'
1569: 'General Enquiry'

service_mapping:
Expand All @@ -21,6 +22,7 @@ service_mapping:
service_id_override:
1638: 409
1635: 412
1636: 413

service_to_event_type:
missed:
Expand All @@ -41,8 +43,9 @@ default_data_event_type:
# 1566:
# Refuse Bin: 1
# Refuse Bag: 1
1568:
1636:
Payment Type: 1
Payment Method: 2
# Container Mix: 1
# Paper: 1
# Food: 1
Expand Down

0 comments on commit 9e4a674

Please sign in to comment.