Skip to content

Commit

Permalink
WIP [Bexley][WW] Cancel GGW subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Feb 2, 2025
1 parent b834c52 commit e8dfeed
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
10 changes: 10 additions & 0 deletions perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check warning on line 1680 in perllib/FixMyStreet/App/Controller/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Waste.pm#L1680

Added line #L1680 was not covered by tests
# TODO customer_reference should be saved on original subscription report (value returned from subscription request)
$c->set_param('customer_reference', 'GWIT-CUST-FC3A-16012025140306' );

Check warning on line 1682 in perllib/FixMyStreet/App/Controller/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Waste.pm#L1682

Added line #L1682 was not covered by tests
# TODO Need clarification for this - where is this meant to come from?
$c->set_param('due_date', '12/12/2025');

Check warning on line 1684 in perllib/FixMyStreet/App/Controller/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Waste.pm#L1684

Added line #L1684 was not covered by tests
}

$c->forward('setup_categories_and_bodies') unless $c->stash->{contacts};
$c->forward('/report/new/non_map_creation', [['/waste/remove_name_errors']]) or return;

Expand Down
37 changes: 34 additions & 3 deletions perllib/FixMyStreet/Cobrand/Bexley/Garden.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];

Check warning on line 24 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L24

Added line #L24 was not covered by tests
}

sub garden_current_subscription {
my $self = shift;

Check warning on line 28 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L28

Added line #L28 was not covered by tests

my $uprn = $self->{c}->stash->{property}{uprn};

Check warning on line 30 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L30

Added line #L30 was not covered by tests
return undef unless $uprn;

my $is_free = $self->agile->IsAddressFree($uprn);

Check warning on line 33 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L33

Added line #L33 was not covered by tests
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};

Check warning on line 38 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L38

Added line #L38 was not covered by tests
map { my $srv = $services->{$_}; return $srv if $srv }
@{ $self->garden_service_ids };

Check warning on line 40 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L40

Added line #L40 was not covered by tests

return { agile_only => 1 };

Check warning on line 42 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L42

Added line #L42 was not covered by tests
}

# TODO This is a placeholder
sub get_current_garden_bins { 1 }

Check warning on line 46 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L46

Added line #L46 was not covered by tests

sub waste_cancel_asks_staff_for_user_details { 1 }

Check warning on line 48 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L48

Added line #L48 was not covered by tests

=item * You can order a maximum of five bins
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
68 changes: 68 additions & 0 deletions perllib/Integrations/Agile.pm
Original file line number Diff line number Diff line change
@@ -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 ) = @_;

Check warning on line 27 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L27

Added line #L27 was not covered by tests

my $action = $args{action};
my $controller = $args{controller};
my $data = $args{data};
my $method = 'POST';

Check warning on line 32 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L29-L32

Added lines #L29 - L32 were not covered by tests

my $body = {

Check warning on line 34 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L34

Added line #L34 was not covered by tests
Method => $method,
Controller => $controller,
Action => $action,
Data => $data,
};
my $body_json = encode_json($body);

Check warning on line 40 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L40

Added line #L40 was not covered by tests

my $uri = URI->new( $self->{url} );

Check warning on line 42 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L42

Added line #L42 was not covered by tests

my $req = HTTP::Request->new( $method, $uri );
$req->content_type('application/json; charset=UTF-8');
$req->content($body_json);

Check warning on line 46 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L44-L46

Added lines #L44 - L46 were not covered by tests

my $ua = LWP::UserAgent->new;
my $res = $ua->request($req);

Check warning on line 49 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L48-L49

Added lines #L48 - L49 were not covered by tests

if ( $res->is_success ) {
return decode_json( $res->content );

Check warning on line 52 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L52

Added line #L52 was not covered by tests
} else {
die $res->content;

Check warning on line 54 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L54

Added line #L54 was not covered by tests
}
}

sub IsAddressFree {
my ( $self, $uprn ) = @_;

Check warning on line 59 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L59

Added line #L59 was not covered by tests

return $self->call(

Check warning on line 61 in perllib/Integrations/Agile.pm

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L61

Added line #L61 was not covered by tests
action => 'isaddressfree',
controller => 'customer',
data => { UPRN => $uprn },
);
}

1;

0 comments on commit e8dfeed

Please sign in to comment.