Skip to content

Commit

Permalink
[Bexley][WW] Implement call to Agile renewal
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Feb 11, 2025
1 parent 1ff272e commit 8323d98
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
10 changes: 10 additions & 0 deletions perllib/Integrations/Agile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ sub IsAddressFree {
);
}

sub Renew {
my ( $self, $params ) = @_;

return $self->api_call(
action => 'renewal',
controller => 'servicecontract',
data => $params,
);
}

sub SignUp {
my ( $self, $params ) = @_;

Expand Down
48 changes: 47 additions & 1 deletion perllib/Open311/Endpoint/Integration/Agile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ has agile => (

use constant SERVICE_TO_SUB_MAPPING => {
garden_subscription => \&_garden_subscription,
garden_subscription_renew => \&_garden_subscription_renew,
garden_subscription_cancel => \&_garden_subscription_cancel,
};

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

my $sub = SERVICE_TO_SUB_MAPPING->{$service->service_code};
# Garden Subscription may be a 'renew' type
my $lookup = $service->service_code;
$lookup .= "_$args->{attributes}{type}" if $args->{attributes}{type};

my $sub = SERVICE_TO_SUB_MAPPING->{$lookup};

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

Expand Down Expand Up @@ -148,6 +153,47 @@ sub _garden_subscription {
}
}

sub _garden_subscription_renew {
my ( $self, $args ) = @_;

my $integration = $self->get_integration;

my $is_free = $integration->IsAddressFree( $args->{attributes}{uprn} );

if ( $is_free->{IsFree} eq 'False' ) {
my $res = $integration->Renew( {
CustomerExternalReference => $args->{attributes}{customer_external_ref},
ServiceContractUPRN => $args->{attributes}{uprn},
WasteContainerQuantity => int( $args->{attributes}{new_containers} ) || 1,
PaymentReference => $args->{attributes}{PaymentCode},
PaymentMethodCode =>
PAYMENT_METHOD_MAPPING->{ $args->{attributes}{payment_method} },
} );

# Expected response:
# {
# Id: int,
# Address: string,
# ServiceContractStatus: string,
# WasteContainerType: string,
# WasteContainerQuantity: int,
# StartDate: string,
# EndDate: string,
# ReminderDate: string,
# }
my $request = $self->new_request(
service_request_id => $res->{Id}, # TODO Is this correct?
);

return $request;

} else {
die 'UPRN '
. $args->{attributes}{uprn}
. ' does not have a subscription to be renewed, or is invalid';
}
}

sub _garden_subscription_cancel {
my ( $self, $args ) = @_;

Expand Down

0 comments on commit 8323d98

Please sign in to comment.