Skip to content

Commit 8323d98

Browse files
[Bexley][WW] Implement call to Agile renewal
1 parent 1ff272e commit 8323d98

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
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

+47-1
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

@@ -148,6 +153,47 @@ sub _garden_subscription {
148153
}
149154
}
150155

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

0 commit comments

Comments
 (0)