Skip to content

Commit 834f328

Browse files
committed
Merge remote-tracking branch 'origin/bexley-ww-ggw-renew' into staging
2 parents bbd1d75 + 66a243b commit 834f328

File tree

4 files changed

+128
-17
lines changed

4 files changed

+128
-17
lines changed

perllib/Integrations/Agile.pm

+10
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ sub IsAddressFree {
9090
);
9191
}
9292

93+
sub Renew {
94+
my ( $self, $params ) = @_;
95+
96+
return $self->api_call(
97+
action => 'renewal',
98+
controller => 'servicecontract',
99+
data => $params,
100+
);
101+
}
102+
93103
sub SignUp {
94104
my ( $self, $params ) = @_;
95105

perllib/Open311/Endpoint/Integration/Agile.pm

+54-5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ has agile => (
4949

5050
use constant SERVICE_TO_SUB_MAPPING => {
5151
garden_subscription => \&_garden_subscription,
52+
garden_subscription_renew => \&_garden_subscription_renew,
5253
garden_subscription_cancel => \&_garden_subscription_cancel,
5354
};
5455

@@ -92,7 +93,11 @@ sub post_service_request {
9293
$self->logger->debug(
9394
"post_service_request arguments: " . encode_json($args) );
9495

95-
my $sub = SERVICE_TO_SUB_MAPPING->{$service->service_code};
96+
# Garden Subscription may be a 'renew' type
97+
my $lookup = $service->service_code;
98+
$lookup .= "_$args->{attributes}{type}" if $args->{attributes}{type};
99+
100+
my $sub = SERVICE_TO_SUB_MAPPING->{$lookup};
96101

97102
die 'Service \'' . $service->service_code . '\' not handled' unless $sub;
98103

@@ -120,7 +125,7 @@ sub _garden_subscription {
120125
TitleCode => 'Default',
121126
CustomerExternalReference => '',
122127
ServiceContractUPRN => $args->{attributes}{uprn},
123-
WasteContainerQuantity => int( $args->{attributes}{new_containers} ) || 1,
128+
WasteContainerQuantity => int( $args->{attributes}{total_containers} ) || 1,
124129
AlreadyHasBinQuantity => int( $args->{attributes}{current_containers} ) || 0,
125130
PaymentReference => $args->{attributes}{PaymentCode},
126131
PaymentMethodCode =>
@@ -129,9 +134,8 @@ sub _garden_subscription {
129134
# Used for FMS report ID
130135
ActionReference => $args->{attributes}{fixmystreet_id},
131136

132-
# TODO
133-
DirectDebitDate => '',
134-
DirectDebitReference => '',
137+
DirectDebitDate => $args->{attributes}{direct_debit_start_date} // '',
138+
DirectDebitReference => $args->{attributes}{direct_debit_reference} // '',
135139
} );
136140

137141
# Expected response:
@@ -153,6 +157,51 @@ sub _garden_subscription {
153157
}
154158
}
155159

160+
sub _garden_subscription_renew {
161+
my ( $self, $args ) = @_;
162+
163+
my $integration = $self->get_integration;
164+
165+
my $is_free = $integration->IsAddressFree( $args->{attributes}{uprn} );
166+
167+
if ( $is_free->{IsFree} eq 'False' ) {
168+
my $res = $integration->Renew( {
169+
CustomerExternalReference => $args->{attributes}{customer_external_ref},
170+
ServiceContractUPRN => $args->{attributes}{uprn},
171+
WasteContainerQuantity => int( $args->{attributes}{total_containers} ) || 1,
172+
AlreadyHasBinQuantity => int( $args->{attributes}{current_containers} ) || 0,
173+
PaymentReference => $args->{attributes}{PaymentCode},
174+
PaymentMethodCode =>
175+
PAYMENT_METHOD_MAPPING->{ $args->{attributes}{payment_method} },
176+
177+
DirectDebitDate => $args->{attributes}{direct_debit_start_date} // '',
178+
DirectDebitReference => $args->{attributes}{direct_debit_reference} // '',
179+
} );
180+
181+
# Expected response:
182+
# {
183+
# Id: int,
184+
# Address: string,
185+
# ServiceContractStatus: string,
186+
# WasteContainerType: string,
187+
# WasteContainerQuantity: int,
188+
# StartDate: string,
189+
# EndDate: string,
190+
# ReminderDate: string,
191+
# }
192+
my $request = $self->new_request(
193+
service_request_id => $res->{Id}, # TODO Is this correct?
194+
);
195+
196+
return $request;
197+
198+
} else {
199+
die 'UPRN '
200+
. $args->{attributes}{uprn}
201+
. ' does not have a subscription to be renewed, or is invalid';
202+
}
203+
}
204+
156205
sub _garden_subscription_cancel {
157206
my ( $self, $args ) = @_;
158207

perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm

+33-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ sub _build_attributes {
3333
required => 0,
3434
automated => 'hidden_field',
3535
),
36+
Open311::Endpoint::Service::Attribute->new(
37+
code => 'total_containers',
38+
description => 'Total number of requested containers',
39+
datatype => 'string',
40+
required => 0,
41+
automated => 'hidden_field',
42+
),
3643
Open311::Endpoint::Service::Attribute->new(
3744
code => 'current_containers',
3845
description => 'Number of current containers',
@@ -42,7 +49,7 @@ sub _build_attributes {
4249
),
4350
Open311::Endpoint::Service::Attribute->new(
4451
code => 'new_containers',
45-
description => 'Number of new containers',
52+
description => 'Number of new containers (total requested minus current)',
4653
datatype => 'string',
4754
required => 0,
4855
automated => 'hidden_field',
@@ -84,6 +91,31 @@ sub _build_attributes {
8491
required => 0,
8592
automated => 'hidden_field',
8693
),
94+
95+
# For direct debit payments
96+
Open311::Endpoint::Service::Attribute->new(
97+
code => 'direct_debit_reference',
98+
description => 'Direct debit reference',
99+
datatype => 'string',
100+
required => 0,
101+
automated => 'hidden_field',
102+
),
103+
Open311::Endpoint::Service::Attribute->new(
104+
code => 'direct_debit_start_date',
105+
description => 'Direct debit initial payment date',
106+
datatype => 'string',
107+
required => 0,
108+
automated => 'hidden_field',
109+
),
110+
111+
Open311::Endpoint::Service::Attribute->new(
112+
code => 'type',
113+
description => 'Denotes whether subscription request is a renewal or not',
114+
datatype => 'string',
115+
required => 0,
116+
automated => 'hidden_field',
117+
),
118+
87119
);
88120

89121
return \@attributes;

t/open311/endpoint/agile.t

+31-11
Original file line numberDiff line numberDiff line change
@@ -135,40 +135,60 @@ subtest 'GET service' => sub {
135135
description => 'Property ID',
136136
order => 3,
137137
},
138+
{ %defaults,
139+
code => 'total_containers',
140+
description => 'Total number of requested containers',
141+
order => 4,
142+
},
138143
{ %defaults,
139144
code => 'current_containers',
140145
description => 'Number of current containers',
141-
order => 4,
146+
order => 5,
142147
},
143148
{ %defaults,
144149
code => 'new_containers',
145-
description => 'Number of new containers',
146-
order => 5,
150+
description => 'Number of new containers (total requested minus current)',
151+
order => 6,
147152
},
148153
{ %defaults,
149154
code => 'payment_method',
150155
description => 'Payment method: credit card or direct debit',
151-
order => 6,
156+
order => 7,
152157
},
153158
{ %defaults,
154159
code => 'payment',
155160
description => 'Payment amount in pence',
156-
order => 7,
161+
order => 8,
157162
},
158163
{ %defaults,
159164
code => 'reason',
160165
description => 'Cancellation reason',
161-
order => 8,
166+
order => 9,
162167
},
163168
{ %defaults,
164169
code => 'due_date',
165170
description => 'Cancellation date',
166-
order => 9,
171+
order => 10,
167172
},
168173
{ %defaults,
169174
code => 'customer_external_ref',
170175
description => 'Customer external ref',
171-
order => 10,
176+
order => 11,
177+
},
178+
{ %defaults,
179+
code => 'direct_debit_reference',
180+
description => 'Direct debit reference',
181+
order => 12,
182+
},
183+
{ %defaults,
184+
code => 'direct_debit_start_date',
185+
description => 'Direct debit initial payment date',
186+
order => 13,
187+
},
188+
{ %defaults,
189+
code => 'type',
190+
description => 'Denotes whether subscription request is a renewal or not',
191+
order => 14,
172192
},
173193

174194
],
@@ -188,7 +208,7 @@ subtest 'successfully subscribe to garden waste' => sub {
188208
'attribute[fixmystreet_id]' => 2000001,
189209
'attribute[uprn]' => '123_no_sub',
190210
'attribute[current_containers]' => 1,
191-
'attribute[new_containers]' => 2,
211+
'attribute[total_containers]' => 2,
192212
'attribute[payment_method]' => 'credit_card',
193213
'attribute[PaymentCode]' => 'payment_123',
194214
);
@@ -214,7 +234,7 @@ subtest 'try to subscribe to garden waste when already subscribed' => sub {
214234
'attribute[fixmystreet_id]' => 2000001,
215235
'attribute[uprn]' => '234_has_sub',
216236
'attribute[current_containers]' => 1,
217-
'attribute[new_containers]' => 2,
237+
'attribute[total_containers]' => 2,
218238
'attribute[payment_method]' => 'credit_card',
219239
'attribute[PaymentCode]' => 'payment_123',
220240
);
@@ -238,7 +258,7 @@ subtest 'handle unknown error' => sub {
238258
'attribute[fixmystreet_id]' => 'bad_data',
239259
'attribute[uprn]' => '123_no_sub',
240260
'attribute[current_containers]' => 1,
241-
'attribute[new_containers]' => 2,
261+
'attribute[total_containers]' => 2,
242262
'attribute[payment_method]' => 'credit_card',
243263
'attribute[PaymentCode]' => 'payment_123',
244264
);

0 commit comments

Comments
 (0)