Skip to content

Commit

Permalink
[Bexley][WW] Cancel GGW subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Feb 5, 2025
1 parent 0c20788 commit 02b5be4
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 5 deletions.
4 changes: 3 additions & 1 deletion perllib/FixMyStreet/App/Controller/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,9 @@ sub garden_cancel : Chained('garden_setup') : Args(0) {
$c->forward('check_if_staff_can_pay', [ $payment_method ]);

$c->stash->{first_page} = 'intro';
$c->stash->{form_class} = 'FixMyStreet::App::Form::Waste::Garden::Cancel';
$c->stash->{form_class}
= $c->cobrand->call_hook('waste_cancel_form_class')

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L1284 was not covered by tests
|| 'FixMyStreet::App::Form::Waste::Garden::Cancel';
$c->forward('form');
}

Expand Down
1 change: 1 addition & 0 deletions perllib/FixMyStreet/App/Form/Waste/Garden/Cancel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ has_field confirm => (
option_label => 'I confirm I wish to cancel my subscription',
required => 1,
label => "Confirm",
order => 998,
);

has_field submit => (
Expand Down
38 changes: 38 additions & 0 deletions perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package FixMyStreet::App::Form::Waste::Garden::Cancel::Bexley;

use utf8;
use HTML::FormHandler::Moose;
extends 'FixMyStreet::App::Form::Waste::Garden::Cancel';

has_field reason => (
type => 'Select',
widget => 'RadioGroup',
required => 1,
label => 'Reason for cancellation',
messages => { required => 'Please select a reason' },
);

sub options_reason {
my $form = shift;

Check warning on line 16 in perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm#L16

Added line #L16 was not covered by tests

my @options = (

Check warning on line 18 in perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm#L18

Added line #L18 was not covered by tests
'Price',
'Service Issues',
'Moving Out of Borough',
'Other',
);
return map { { label => $_, value => $_ } } @options;

Check warning on line 24 in perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Form/Waste/Garden/Cancel/Bexley.pm#L24

Added line #L24 was not covered by tests
}

has_field reason_further_details => (
required => 1,
type => 'Text',
widget => 'Textarea',
label =>
"If you selected 'Other', please provide further details (up to 250 characters)",
required_when => { reason => 'Other' },
maxlength => 250,
messages => { required => 'Please provide further details' },
);

1;
93 changes: 90 additions & 3 deletions perllib/FixMyStreet/Cobrand/Bexley/Garden.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,102 @@ FixMyStreet::Cobrand::Bexley::Garden - code specific to Bexley WasteWorks GGW

package FixMyStreet::Cobrand::Bexley::Garden;

use DateTime::Format::Strptime;
use Integrations::Agile;
use FixMyStreet::App::Form::Waste::Garden::Cancel::Bexley;

use Moo::Role;
with 'FixMyStreet::Roles::Cobrand::SCP',
'FixMyStreet::Roles::Cobrand::Paye';

has agile => (
is => 'lazy',
default => sub {
my $self = shift;
my $cfg = $self->feature('agile');
return Integrations::Agile->new(%$cfg);
},
);

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 29 in perllib/FixMyStreet/Cobrand/Bexley/Garden.pm

View check run for this annotation

Codecov / codecov/patch

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

Added line #L29 was not covered by tests
}

sub garden_current_subscription {
my $self = shift;

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

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L35 was not covered by tests
return $current if $current;

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

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
return undef unless $uprn;

# TODO Fetch active subscription from DB for UPRN
# (get_original_sub() in Controller/Waste.pm needs to handle Bexley UPRN).
# Could be more than one customer, so match against email.
# Could be more than one contract, so match against reference.

my $results = $self->agile->CustomerSearch($uprn);

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
return undef unless $results && $results->{Customers};
my $customer = $results->{Customers}[0];

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
return undef unless $customer && $customer->{ServiceContracts};
my $contract = $customer->{ServiceContracts}[0];

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L50 was not covered by tests
return unless $contract;

my $parser

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L53 was not covered by tests
= DateTime::Format::Strptime->new( pattern => '%d/%m/%Y %H:%M' );
my $end_date = $parser->parse_datetime( $contract->{EndDate} );

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L55 was not covered by tests

# Agile says there is a subscription; now get service data from
# Whitespace
my $services = $self->{c}->stash->{services};
for ( @{ $self->garden_service_ids } ) {

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L59-L60

Added lines #L59 - L60 were not covered by tests
if ( my $srv = $services->{$_} ) {
$srv->{customer_external_ref}
= $customer->{CustomerExternalReference};
$srv->{end_date} = $end_date;
return $srv;

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L63-L65

Added lines #L63 - L65 were not covered by tests
}
}

return {
agile_only => 1,
customer_external_ref => $customer->{CustomerExternalReference},
end_date => $end_date,

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L72 was not covered by tests
};
}

# TODO This is a placeholder
sub get_current_garden_bins { 1 }

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L77 was not covered by tests

sub waste_cancel_asks_staff_for_user_details { 1 }

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L79 was not covered by tests

sub waste_cancel_form_class {
'FixMyStreet::App::Form::Waste::Garden::Cancel::Bexley';

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L82 was not covered by tests
}

sub waste_garden_sub_params {
my ( $self, $data, $type ) = @_;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L86 was not covered by tests

my $c = $self->{c};

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L88 was not covered by tests

if ( $data->{category} eq 'Cancel Garden Subscription' ) {
my $srv = $self->garden_current_subscription;

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L91 was not covered by tests

my $parser = DateTime::Format::Strptime->new( pattern => '%d/%m/%Y' );
my $due_date_str = $parser->format_datetime( $srv->{end_date} );

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L93-L94

Added lines #L93 - L94 were not covered by tests

my $reason = $data->{reason};

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L96 was not covered by tests
$reason .= ': ' . $data->{reason_further_details}
if $data->{reason_further_details};

$c->set_param( 'customer_external_ref', $srv->{customer_external_ref} );
$c->set_param( 'due_date', $due_date_str );
$c->set_param( 'reason', $reason );

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

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Garden.pm#L100-L102

Added lines #L100 - L102 were not covered by tests
}
}

=item * You can order a maximum of five bins
Expand Down
5 changes: 4 additions & 1 deletion perllib/FixMyStreet/Cobrand/Bexley/Waste.pm
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,9 @@ sub bin_services_for_address {
];
}

$property->{garden_current_subscription}
= $self->garden_current_subscription;

Check warning on line 463 in perllib/FixMyStreet/Cobrand/Bexley/Waste.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Cobrand/Bexley/Waste.pm#L463

Added line #L463 was not covered by tests

@site_services_filtered = $self->_remove_service_if_assisted_exists(@site_services_filtered);

@site_services_filtered = $self->service_sort(@site_services_filtered);
Expand Down Expand Up @@ -1246,7 +1249,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
78 changes: 78 additions & 0 deletions perllib/Integrations/Agile.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
=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 },
);
}

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

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

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L69

Added line #L69 was not covered by tests

return $self->call(

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

View check run for this annotation

Codecov / codecov/patch

perllib/Integrations/Agile.pm#L71

Added line #L71 was not covered by tests
action => 'search',
controller => 'customer',
data => { ServiceContractUPRN => $uprn },
);
}

1;
2 changes: 2 additions & 0 deletions t/app/controller/waste_bexley_garden.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ $dbi_mock->mock( 'connect', sub {
return $dbh;
} );

my $agile_mock = Test::MockModule->new('Integrations::Agile');

my $mech = FixMyStreet::TestMech->new;

my $body = $mech->create_body_ok(2494, 'Bexley', { cobrand => 'bexley' });
Expand Down

0 comments on commit 02b5be4

Please sign in to comment.