Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bexley-ww-ggw-renew' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Feb 20, 2025
2 parents bbd1d75 + 66a243b commit 834f328
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 17 deletions.
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
59 changes: 54 additions & 5 deletions 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 @@ -120,7 +125,7 @@ sub _garden_subscription {
TitleCode => 'Default',
CustomerExternalReference => '',
ServiceContractUPRN => $args->{attributes}{uprn},
WasteContainerQuantity => int( $args->{attributes}{new_containers} ) || 1,
WasteContainerQuantity => int( $args->{attributes}{total_containers} ) || 1,
AlreadyHasBinQuantity => int( $args->{attributes}{current_containers} ) || 0,
PaymentReference => $args->{attributes}{PaymentCode},
PaymentMethodCode =>
Expand All @@ -129,9 +134,8 @@ sub _garden_subscription {
# Used for FMS report ID
ActionReference => $args->{attributes}{fixmystreet_id},

# TODO
DirectDebitDate => '',
DirectDebitReference => '',
DirectDebitDate => $args->{attributes}{direct_debit_start_date} // '',
DirectDebitReference => $args->{attributes}{direct_debit_reference} // '',
} );

# Expected response:
Expand All @@ -153,6 +157,51 @@ 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}{total_containers} ) || 1,
AlreadyHasBinQuantity => int( $args->{attributes}{current_containers} ) || 0,
PaymentReference => $args->{attributes}{PaymentCode},
PaymentMethodCode =>
PAYMENT_METHOD_MAPPING->{ $args->{attributes}{payment_method} },

DirectDebitDate => $args->{attributes}{direct_debit_start_date} // '',
DirectDebitReference => $args->{attributes}{direct_debit_reference} // '',
} );

# 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
34 changes: 33 additions & 1 deletion perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ sub _build_attributes {
required => 0,
automated => 'hidden_field',
),
Open311::Endpoint::Service::Attribute->new(
code => 'total_containers',
description => 'Total number of requested containers',
datatype => 'string',
required => 0,
automated => 'hidden_field',
),
Open311::Endpoint::Service::Attribute->new(
code => 'current_containers',
description => 'Number of current containers',
Expand All @@ -42,7 +49,7 @@ sub _build_attributes {
),
Open311::Endpoint::Service::Attribute->new(
code => 'new_containers',
description => 'Number of new containers',
description => 'Number of new containers (total requested minus current)',
datatype => 'string',
required => 0,
automated => 'hidden_field',
Expand Down Expand Up @@ -84,6 +91,31 @@ sub _build_attributes {
required => 0,
automated => 'hidden_field',
),

# For direct debit payments
Open311::Endpoint::Service::Attribute->new(
code => 'direct_debit_reference',
description => 'Direct debit reference',
datatype => 'string',
required => 0,
automated => 'hidden_field',
),
Open311::Endpoint::Service::Attribute->new(
code => 'direct_debit_start_date',
description => 'Direct debit initial payment date',
datatype => 'string',
required => 0,
automated => 'hidden_field',
),

Open311::Endpoint::Service::Attribute->new(
code => 'type',
description => 'Denotes whether subscription request is a renewal or not',
datatype => 'string',
required => 0,
automated => 'hidden_field',
),

);

return \@attributes;
Expand Down
42 changes: 31 additions & 11 deletions t/open311/endpoint/agile.t
Original file line number Diff line number Diff line change
Expand Up @@ -135,40 +135,60 @@ subtest 'GET service' => sub {
description => 'Property ID',
order => 3,
},
{ %defaults,
code => 'total_containers',
description => 'Total number of requested containers',
order => 4,
},
{ %defaults,
code => 'current_containers',
description => 'Number of current containers',
order => 4,
order => 5,
},
{ %defaults,
code => 'new_containers',
description => 'Number of new containers',
order => 5,
description => 'Number of new containers (total requested minus current)',
order => 6,
},
{ %defaults,
code => 'payment_method',
description => 'Payment method: credit card or direct debit',
order => 6,
order => 7,
},
{ %defaults,
code => 'payment',
description => 'Payment amount in pence',
order => 7,
order => 8,
},
{ %defaults,
code => 'reason',
description => 'Cancellation reason',
order => 8,
order => 9,
},
{ %defaults,
code => 'due_date',
description => 'Cancellation date',
order => 9,
order => 10,
},
{ %defaults,
code => 'customer_external_ref',
description => 'Customer external ref',
order => 10,
order => 11,
},
{ %defaults,
code => 'direct_debit_reference',
description => 'Direct debit reference',
order => 12,
},
{ %defaults,
code => 'direct_debit_start_date',
description => 'Direct debit initial payment date',
order => 13,
},
{ %defaults,
code => 'type',
description => 'Denotes whether subscription request is a renewal or not',
order => 14,
},

],
Expand All @@ -188,7 +208,7 @@ subtest 'successfully subscribe to garden waste' => sub {
'attribute[fixmystreet_id]' => 2000001,
'attribute[uprn]' => '123_no_sub',
'attribute[current_containers]' => 1,
'attribute[new_containers]' => 2,
'attribute[total_containers]' => 2,
'attribute[payment_method]' => 'credit_card',
'attribute[PaymentCode]' => 'payment_123',
);
Expand All @@ -214,7 +234,7 @@ subtest 'try to subscribe to garden waste when already subscribed' => sub {
'attribute[fixmystreet_id]' => 2000001,
'attribute[uprn]' => '234_has_sub',
'attribute[current_containers]' => 1,
'attribute[new_containers]' => 2,
'attribute[total_containers]' => 2,
'attribute[payment_method]' => 'credit_card',
'attribute[PaymentCode]' => 'payment_123',
);
Expand All @@ -238,7 +258,7 @@ subtest 'handle unknown error' => sub {
'attribute[fixmystreet_id]' => 'bad_data',
'attribute[uprn]' => '123_no_sub',
'attribute[current_containers]' => 1,
'attribute[new_containers]' => 2,
'attribute[total_containers]' => 2,
'attribute[payment_method]' => 'credit_card',
'attribute[PaymentCode]' => 'payment_123',
);
Expand Down

0 comments on commit 834f328

Please sign in to comment.