From bcb50079e87766c10332b0715dbe3c3a6247e115 Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Tue, 11 Feb 2025 20:34:11 +0000 Subject: [PATCH 1/3] [Bexley][WW] Implement call to Agile renewal --- perllib/Integrations/Agile.pm | 10 ++++ perllib/Open311/Endpoint/Integration/Agile.pm | 49 ++++++++++++++++++- .../Endpoint/Service/UKCouncil/Agile.pm | 18 ++++++- t/open311/endpoint/agile.t | 26 +++++++--- 4 files changed, 93 insertions(+), 10 deletions(-) diff --git a/perllib/Integrations/Agile.pm b/perllib/Integrations/Agile.pm index 9f833a58d..e948cda66 100644 --- a/perllib/Integrations/Agile.pm +++ b/perllib/Integrations/Agile.pm @@ -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 ) = @_; diff --git a/perllib/Open311/Endpoint/Integration/Agile.pm b/perllib/Open311/Endpoint/Integration/Agile.pm index 2c984f3bd..7065cb155 100644 --- a/perllib/Open311/Endpoint/Integration/Agile.pm +++ b/perllib/Open311/Endpoint/Integration/Agile.pm @@ -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, }; @@ -93,7 +94,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; @@ -149,6 +154,48 @@ 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} }, + } ); + + # 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 ) = @_; diff --git a/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm b/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm index e30946dff..6e200440c 100644 --- a/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm +++ b/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm @@ -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', @@ -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', @@ -84,6 +91,15 @@ sub _build_attributes { 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; diff --git a/t/open311/endpoint/agile.t b/t/open311/endpoint/agile.t index 271aa84bc..36b105fcd 100644 --- a/t/open311/endpoint/agile.t +++ b/t/open311/endpoint/agile.t @@ -135,40 +135,50 @@ 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 => 'type', + description => 'Denotes whether subscription request is a renewal or not', + order => 12, }, ], }, 'correct json returned'; From b267cfb2a655581fadae6631e1646b31af95846c Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Fri, 14 Feb 2025 15:38:46 +0000 Subject: [PATCH 2/3] [Bexley][WW] Use total_containers rather than new_containers for garden sub new_containers already has current_containers subtracted from it; we want to pass the original total to Bexley. --- perllib/Open311/Endpoint/Integration/Agile.pm | 2 +- t/open311/endpoint/agile.t | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/perllib/Open311/Endpoint/Integration/Agile.pm b/perllib/Open311/Endpoint/Integration/Agile.pm index 7065cb155..7c1cb3578 100644 --- a/perllib/Open311/Endpoint/Integration/Agile.pm +++ b/perllib/Open311/Endpoint/Integration/Agile.pm @@ -121,7 +121,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 => diff --git a/t/open311/endpoint/agile.t b/t/open311/endpoint/agile.t index 36b105fcd..5dea6e83b 100644 --- a/t/open311/endpoint/agile.t +++ b/t/open311/endpoint/agile.t @@ -197,7 +197,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', ); @@ -223,7 +223,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', ); @@ -247,7 +247,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', ); From 9ab424d50e57386afc3a617b09e30e7f62a2904c Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Tue, 18 Feb 2025 20:49:54 +0000 Subject: [PATCH 3/3] [Bexley] Implement direct debit fields for Agile. --- perllib/Open311/Endpoint/Integration/Agile.pm | 8 +++++--- .../Open311/Endpoint/Service/UKCouncil/Agile.pm | 16 ++++++++++++++++ t/open311/endpoint/agile.t | 12 +++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/perllib/Open311/Endpoint/Integration/Agile.pm b/perllib/Open311/Endpoint/Integration/Agile.pm index 7c1cb3578..d7f38679e 100644 --- a/perllib/Open311/Endpoint/Integration/Agile.pm +++ b/perllib/Open311/Endpoint/Integration/Agile.pm @@ -130,9 +130,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: @@ -170,6 +169,9 @@ sub _garden_subscription_renew { 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: diff --git a/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm b/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm index 6e200440c..8bcde058f 100644 --- a/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm +++ b/perllib/Open311/Endpoint/Service/UKCouncil/Agile.pm @@ -92,6 +92,22 @@ sub _build_attributes { 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', diff --git a/t/open311/endpoint/agile.t b/t/open311/endpoint/agile.t index 5dea6e83b..9ec7e0582 100644 --- a/t/open311/endpoint/agile.t +++ b/t/open311/endpoint/agile.t @@ -175,10 +175,20 @@ subtest 'GET service' => sub { description => 'Customer external ref', 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 => 12, + order => 14, }, ], }, 'correct json returned';