diff --git a/perllib/FixMyStreet/App/Controller/Waste.pm b/perllib/FixMyStreet/App/Controller/Waste.pm index aeb2a4a0eb..68f230e460 100644 --- a/perllib/FixMyStreet/App/Controller/Waste.pm +++ b/perllib/FixMyStreet/App/Controller/Waste.pm @@ -1674,6 +1674,16 @@ sub add_report : Private { } $c->stash->{bulky_photo_data} = \@bulky_photo_data; +# TODO Move elsewhere, this is mock data +if ( $c->cobrand->moniker eq 'bexley' && $data->{category} eq 'Cancel Garden Subscription' ) { +# TODO Reason selection needs to be implemented in form + $c->set_param('reason', 'Price'); +# TODO customer_reference should be saved on original subscription report (value returned from subscription request) + $c->set_param('customer_reference', 'GWIT-CUST-FC3A-16012025140306' ); +# TODO Need clarification for this - where is this meant to come from? + $c->set_param('due_date', '12/12/2025'); +} + $c->forward('setup_categories_and_bodies') unless $c->stash->{contacts}; $c->forward('/report/new/non_map_creation', [['/waste/remove_name_errors']]) or return; diff --git a/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm b/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm index 46a623ece7..ee16962e0c 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley/Garden.pm @@ -6,15 +6,46 @@ FixMyStreet::Cobrand::Bexley::Garden - code specific to Bexley WasteWorks GGW package FixMyStreet::Cobrand::Bexley::Garden; +use Integrations::Agile; + use Moo::Role; with 'FixMyStreet::Roles::Cobrand::SCP', 'FixMyStreet::Roles::Cobrand::Paye'; +has agile => ( + is => 'lazy', +# TODO url to config + default => sub { Integrations::Agile->new( url => 'https://integration.stg.agileapplications.co.uk/api/bexley/gardenwaste/external/request' ) }, +); + sub garden_service_name { 'garden waste collection service' } -# TODO No current subscription look up here -# -sub garden_current_subscription { undef } +sub garden_service_ids { + return [ 'GA-140', 'GA-240' ]; +} + +sub garden_current_subscription { + my $self = shift; + + my $uprn = $self->{c}->stash->{property}{uprn}; + return undef unless $uprn; + + my $is_free = $self->agile->IsAddressFree($uprn); + return undef if $is_free->{IsFree} eq 'True'; + + # Agile says there is a subscription; now get service data from + # Whitespace + my $services = $self->{c}->stash->{services}; + map { my $srv = $services->{$_}; return $srv if $srv } + @{ $self->garden_service_ids }; + + return { agile_only => 1 }; +} + +# TODO This is a placeholder +sub get_current_garden_bins { 1 } + +sub waste_cancel_asks_staff_for_user_details { 1 } =item * You can order a maximum of five bins diff --git a/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm b/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm index 44b9cee4af..3b163d356c 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley/Waste.pm @@ -1246,7 +1246,7 @@ sub in_cab_logs_reason_prefixes { 'Clear Sacks' => ['MDR-SACK', 'CW-SACK'], 'Paper & Card' => ['PA-1100', 'PA-1280', 'PA-140', 'PA-240', 'PA-55', 'PA-660', 'PA-940', 'PC-180', 'PC-55'], 'Food' => ['FO-140', 'FO-23'], - 'Garden' => ['GA-140', 'GA-240'], + 'Garden' => ['GA-140', 'GA-240'], # TODO Call Garden.pm->garden_service_ids to make sure these IDs are consistent 'Plastics & Glass' => ['PG-1100', 'PG-1280', 'PG-240', 'PG-360', 'PG-55', 'PG-660', 'PG-940', 'PL-1100', 'PL-1280', 'PL-140', 'PL-55', 'PL-660', 'PL-940'], 'Glass' => ['GL-1100', 'GL-1280', 'GL-55', 'GL-660'], 'Refuse' => ['RES-1100', 'RES-1280', 'RES-140', 'RES-180', 'RES-240', 'RES-660', 'RES-720', 'RES-940', 'RES-CHAM', 'RES-DBIN', 'RES-SACK'], diff --git a/perllib/Integrations/Agile.pm b/perllib/Integrations/Agile.pm new file mode 100644 index 0000000000..af8fde4fb5 --- /dev/null +++ b/perllib/Integrations/Agile.pm @@ -0,0 +1,68 @@ +=head1 NAME + +Integrations::Agile - Agile Applications API integration + +=head1 DESCRIPTION + +This module provides an interface to the Agile Applications API + +=cut + +package Integrations::Agile; + +use strict; +use warnings; + +use HTTP::Request; +use JSON::MaybeXS; +use LWP::UserAgent; +use Moo; +use URI; + +has url => ( is => 'ro' ); + +# TODO Logging + +sub call { + my ( $self, %args ) = @_; + + my $action = $args{action}; + my $controller = $args{controller}; + my $data = $args{data}; + my $method = 'POST'; + + my $body = { + Method => $method, + Controller => $controller, + Action => $action, + Data => $data, + }; + my $body_json = encode_json($body); + + my $uri = URI->new( $self->{url} ); + + my $req = HTTP::Request->new( $method, $uri ); + $req->content_type('application/json; charset=UTF-8'); + $req->content($body_json); + + my $ua = LWP::UserAgent->new; + my $res = $ua->request($req); + + if ( $res->is_success ) { + return decode_json( $res->content ); + } else { + die $res->content; + } +} + +sub IsAddressFree { + my ( $self, $uprn ) = @_; + + return $self->call( + action => 'isaddressfree', + controller => 'customer', + data => { UPRN => $uprn }, + ); +} + +1;