Skip to content

Commit 9e4a674

Browse files
committed
[SLWP] Pass in correct payment meta information.
1 parent 879ec41 commit 9e4a674

File tree

6 files changed

+169
-20
lines changed

6 files changed

+169
-20
lines changed

perllib/Open311/Endpoint/Integration/UK/Sutton.pm

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
=head1 NAME
2+
3+
Open311::Endpoint::Integration::UK::Sutton
4+
5+
=head1 DESCRIPTION
6+
7+
The Sutton integration. As well as the boilerplate, and setting it as an Echo
8+
integration, this makes sure the right "Payment Taken By" option is chosen for
9+
bulky collections.
10+
11+
=cut
12+
113
package Open311::Endpoint::Integration::UK::Sutton;
214

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

25+
around check_for_data_value => sub {
26+
my ($orig, $class, $name, $args, $request, $parent_name) = @_;
27+
28+
# Bulky items
29+
if ($args->{service_code} eq '1636') {
30+
my $method = $args->{attributes}{payment_method} || '';
31+
if ($method eq 'csc' || $method eq 'cheque') {
32+
return 1 if $name eq 'Payment Taken By'; # Council
33+
} elsif ($method eq 'credit_card') {
34+
return 2 if $name eq 'Payment Taken By'; # Veolia
35+
}
36+
}
37+
38+
return $class->$orig($name, $args, $request, $parent_name);
39+
};
40+
1341
1;

perllib/Open311/Endpoint/Role/SLWP.pm

+29-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
=head1 NAME
2+
3+
Open311::Endpoint::Role::SLWP
4+
5+
=head1 DESCRIPTION
6+
7+
Special handling for both Kingston and Sutton. This makes sure the right
8+
container types are picked for requests, and that the right payment options are
9+
chosen for garden/bulky.
10+
11+
=cut
12+
113
package Open311::Endpoint::Role::SLWP;
214

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

17-
my $method = $args->{attributes}{LastPayMethod} || '';
18-
return 2 if $name eq 'Payment Type' && $method eq 3; # DD
19-
return 3 if $name eq 'Payment Type' && $method eq 4; # 'cheque' (or phone)
29+
# Garden waste
30+
if ($args->{service_code} eq '1638') {
31+
my $method = $args->{attributes}{LastPayMethod} || '';
32+
return 2 if $name eq 'Payment Type' && $method eq 3; # DD
33+
return 3 if $name eq 'Payment Type' && $method eq 4; # 'cheque' (or phone)
34+
}
35+
36+
# Bulky items
37+
if ($args->{service_code} eq '1636') {
38+
# Default in configuration is Payment Type 1 (Card), Payment Method 2 (Website)
39+
my $method = $args->{attributes}{payment_method} || '';
40+
return 2 if $name eq 'Payment Type' && $method eq 'cheque'; # Cheque
41+
if ($name eq 'Payment Method') {
42+
return 1 if $method eq 'csc' || $method eq 'cheque'; # Borough Phone Payment
43+
return 2 if $method eq 'credit_card'; # Borough Website Payment
44+
}
45+
}
2046

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

t/open311/endpoint/kingston.t

+54-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use JSON::MaybeXS;
3535
use_ok 'Open311::Endpoint::Integration::UK::Kingston';
3636

3737
use constant EVENT_TYPE_SUBSCRIBE => 1638;
38+
use constant EVENT_TYPE_BULKY => 1636;
3839

3940
my $soap_lite = Test::MockModule->new('SOAP::Lite');
4041
$soap_lite->mock(call => sub {
@@ -47,7 +48,21 @@ $soap_lite->mock(call => sub {
4748
my @params = ${$args[3]->value}->value;
4849
if (@params == 5) {
4950
my $client_ref = $params[1]->value;
50-
like $client_ref, qr/RBK-2000123|REF-123/;
51+
like $client_ref, qr/RBK-2000123|REF-123|bulky-cc|bulky-phone/;
52+
my $event_type_id = $params[3]->value;
53+
if ($event_type_id == 1636) {
54+
my @data = ${$params[0]->value}->value->value;
55+
my @payment = ${$data[0]->value}->value;
56+
is $payment[0]->value, 1011;
57+
is $payment[1]->value, 1;
58+
my $val = $client_ref eq 'bulky-cc' ? 2 : 1;
59+
@payment = ${$data[1]->value}->value;
60+
is $payment[0]->value, 1012;
61+
is $payment[1]->value, 1; # Always 1
62+
@payment = ${$data[2]->value}->value;
63+
is $payment[0]->value, 1013;
64+
is $payment[1]->value, $val;
65+
}
5166
} elsif (@params == 2) {
5267
is $params[0]->value, '123pay';
5368
my @data = ${$params[1]->value}->value->value;
@@ -69,7 +84,7 @@ $soap_lite->mock(call => sub {
6984
} elsif ($args[0]->name eq 'GetEvent') {
7085
return SOAP::Result->new(result => {
7186
Id => '123pay',
72-
EventTypeId => 1636,
87+
EventTypeId => EVENT_TYPE_BULKY,
7388
EventStateId => 4002,
7489
});
7590
} elsif ($method eq 'GetEventType') {
@@ -82,6 +97,9 @@ $soap_lite->mock(call => sub {
8297
] },
8398
},
8499
{ Id => 1008, Name => "Notes" },
100+
{ Id => 1011, Name => "Payment Type" },
101+
{ Id => 1012, Name => "Payment Taken By" },
102+
{ Id => 1013, Name => "Payment Method" },
85103
] },
86104
});
87105
} elsif ($method eq 'PerformEventAction') {
@@ -102,7 +120,6 @@ my $endpoint = Open311::Endpoint::Integration::Echo::Dummy->new;
102120
my @params = (
103121
POST => '/requests.json',
104122
api_key => 'test',
105-
service_code => EVENT_TYPE_SUBSCRIBE,
106123
first_name => 'Bob',
107124
last_name => 'Mould',
108125
description => "This is the details",
@@ -116,7 +133,9 @@ my @params = (
116133
);
117134

118135
subtest "POST subscription request OK" => sub {
119-
my $res = $endpoint->run_test_request(@params);
136+
my $res = $endpoint->run_test_request(@params,
137+
service_code => EVENT_TYPE_SUBSCRIBE,
138+
);
120139
ok $res->is_success, 'valid request'
121140
or diag $res->content;
122141

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

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

162+
subtest "POST bulky request card payment OK" => sub {
163+
my $res = $endpoint->run_test_request(@params,
164+
service_code => EVENT_TYPE_BULKY,
165+
'attribute[payment_method]' => 'credit_card',
166+
'attribute[client_reference]' => 'bulky-cc',
167+
);
168+
ok $res->is_success, 'valid request'
169+
or diag $res->content;
170+
171+
is_deeply decode_json($res->content),
172+
[ {
173+
"service_request_id" => '1234',
174+
} ], 'correct json returned';
175+
};
176+
177+
subtest "POST bulky request phone payment OK" => sub {
178+
my $res = $endpoint->run_test_request(@params,
179+
service_code => EVENT_TYPE_BULKY,
180+
'attribute[payment_method]' => 'csc',
181+
'attribute[client_reference]' => 'bulky-phone',
182+
);
183+
ok $res->is_success, 'valid request'
184+
or diag $res->content;
185+
186+
is_deeply decode_json($res->content),
187+
[ {
188+
"service_request_id" => '1234',
189+
} ], 'correct json returned';
190+
};
191+
142192
subtest "POST a successful payment" => sub {
143193
my $res = $endpoint->run_test_request(
144194
POST => '/servicerequestupdates.json',

t/open311/endpoint/kingston.yml

+19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,26 @@ client_reference_prefix: RBK
66

77
service_whitelist:
88
1638: 'Garden subscription'
9+
1636: 'Bulky collection'
10+
11+
service_extra_data:
12+
1636:
13+
payment: 1
14+
payment_method: 1
15+
Payment_Type: 1
16+
Collection_Date: 1
17+
Bulky_Collection_Bulky_Items: 1
18+
Bulky_Collection_Notes: 1
19+
Exact_Location: 1
20+
GUID: 1
21+
reservation: 1
22+
Customer_Selected_Date_Beyond_SLA?: 1
23+
First_Date_Returned_to_Customer: 1
924

1025
service_id_override:
1126
1638: 409
1227

28+
default_data_event_type:
29+
1636:
30+
Payment Type: 1
31+
Payment Taken By: 1

t/open311/endpoint/sutton.t

+35-12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use_ok 'Open311::Endpoint::Integration::UK::Sutton';
3636

3737
use constant EVENT_TYPE_MISSED => 'missed';
3838
use constant EVENT_TYPE_SUBSCRIBE => 1638;
39+
use constant EVENT_TYPE_BULKY => 1636;
3940

4041
my $soap_lite = Test::MockModule->new('SOAP::Lite');
4142
$soap_lite->mock(call => sub {
@@ -55,17 +56,14 @@ $soap_lite->mock(call => sub {
5556
my $client_ref = $params[1+$offset]->value;
5657
my $event_type = $params[3+$offset]->value;
5758
my $service_id = $params[4+$offset]->value;
58-
like $client_ref, qr/LBS-200012[345]/;
59+
like $client_ref, qr/LBS-200012[3-6]/;
5960
if ($client_ref eq 'LBS-2000124') {
6061
is $event_type, 1566;
6162
is $service_id, 405;
6263
my @data = ${$params[$offset]->value}->value->value;
6364
my @bin = ${$data[0]->value}->value;
6465
is $bin[0]->value, 2000;
6566
is $bin[1]->value, 1;
66-
my @type = ${$data[1]->value}->value;
67-
is $type[0]->value, 1009;
68-
is $type[1]->value, 2;
6967
} elsif ($client_ref eq 'LBS-2000125') {
7068
is $event_type, 1568;
7169
is $service_id, 408;
@@ -77,16 +75,26 @@ $soap_lite->mock(call => sub {
7775
my @paper = ${$data[0]->value}->value;
7876
is $paper[0]->value, 2002;
7977
is $paper[1]->value, 1;
80-
my @type = ${$data[1]->value}->value;
81-
is $type[0]->value, 1009;
82-
is $type[1]->value, 1;
8378
} elsif ($client_ref eq 'LBS-2000123') {
8479
is $event_type, EVENT_TYPE_SUBSCRIBE;
8580
is $service_id, 409;
8681
my @data = ${$params[$offset]->value}->value->value;
87-
my @paper = ${$data[0]->value}->value;
88-
is $paper[0]->value, 1009;
89-
is $paper[1]->value, 3;
82+
my @type = ${$data[0]->value}->value;
83+
is $type[0]->value, 1009;
84+
is $type[1]->value, 3;
85+
} elsif ($client_ref eq 'LBS-2000126') {
86+
is $event_type, EVENT_TYPE_BULKY;
87+
is $service_id, 413;
88+
my @data = ${$params[$offset]->value}->value->value;
89+
my @type = ${$data[0]->value}->value;
90+
is $type[0]->value, 1009;
91+
is $type[1]->value, 1;
92+
my @method = ${$data[1]->value}->value;
93+
is $method[0]->value, 1010;
94+
is $method[1]->value, 2;
95+
my @by = ${$data[2]->value}->value;
96+
is $by[0]->value, 1011;
97+
is $by[1]->value, 2;
9098
}
9199
return SOAP::Result->new(result => {
92100
EventGuid => '1234',
@@ -105,6 +113,8 @@ $soap_lite->mock(call => sub {
105113
{ Id => 2001, Name => "Container Mix" },
106114
{ Id => 2002, Name => "Paper" },
107115
{ Id => 1009, Name => "Payment Type" },
116+
{ Id => 1010, Name => "Payment Method" },
117+
{ Id => 1011, Name => "Payment Taken By" },
108118
] },
109119
});
110120
} else {
@@ -149,7 +159,6 @@ subtest "POST missed bin OK" => sub {
149159
service_code => EVENT_TYPE_MISSED,
150160
'attribute[fixmystreet_id]' => 2000124,
151161
'attribute[service_id]' => 2238,
152-
'attribute[LastPayMethod]' => 3,
153162
);
154163
ok $res->is_success, 'valid request'
155164
or diag $res->content;
@@ -165,7 +174,6 @@ subtest "POST missed mixed+paper OK" => sub {
165174
service_code => EVENT_TYPE_MISSED,
166175
'attribute[fixmystreet_id]' => 2000125,
167176
'attribute[service_id]' => 2240,
168-
'attribute[LastPayMethod]' => 2,
169177
'attribute[GUID]' => 'd5f79551-3dc4-11ee-ab68-f0c87781f93b',
170178
'attribute[reservation]' => 'reservation==',
171179
);
@@ -178,4 +186,19 @@ subtest "POST missed mixed+paper OK" => sub {
178186
} ], 'correct json returned';
179187
};
180188

189+
subtest "POST bulky collection OK" => sub {
190+
my $res = $endpoint->run_test_request(@params,
191+
service_code => EVENT_TYPE_BULKY,
192+
'attribute[fixmystreet_id]' => 2000126,
193+
'attribute[payment_method]' => 'credit_card',
194+
);
195+
ok $res->is_success, 'valid request'
196+
or diag $res->content;
197+
198+
is_deeply decode_json($res->content),
199+
[ {
200+
"service_request_id" => '1234',
201+
} ], 'correct json returned';
202+
};
203+
181204
done_testing;

t/open311/endpoint/sutton.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ service_whitelist:
88
missed: 'Report missed collection'
99
1635: 'Request new container'
1010
1638: 'Garden Subscription'
11+
1636: 'Bulky collection'
1112
1569: 'General Enquiry'
1213

1314
service_mapping:
@@ -21,6 +22,7 @@ service_mapping:
2122
service_id_override:
2223
1638: 409
2324
1635: 412
25+
1636: 413
2426

2527
service_to_event_type:
2628
missed:
@@ -41,8 +43,9 @@ default_data_event_type:
4143
# 1566:
4244
# Refuse Bin: 1
4345
# Refuse Bag: 1
44-
1568:
46+
1636:
4547
Payment Type: 1
48+
Payment Method: 2
4649
# Container Mix: 1
4750
# Paper: 1
4851
# Food: 1

0 commit comments

Comments
 (0)