Skip to content

Commit

Permalink
[SLWP] Add way to pass in multiple payment details.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jul 31, 2024
1 parent 160cac1 commit c1cf268
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 81 deletions.
30 changes: 30 additions & 0 deletions perllib/Open311/Endpoint/Integration/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pushed to us by Echo or fetched directly.
package Open311::Endpoint::Integration::Echo;

use v5.14;
use utf8;

use Moo;
use JSON::MaybeXS;
Expand Down Expand Up @@ -501,4 +502,33 @@ used as part of a Multi integration.

sub get_service_request_updates { }

=head2 update_event_payment
Given an update args and an arrayref of payment details, update the event
to add those details. This is currently only for SLWP, and includes
hard-coded SLWP IDs.
=cut

sub update_event_payment {
my ($self, $args, $payments) = @_;

my $integ = $self->get_integration;
my $event = $integ->GetEvent($args->{service_request_id});
my $data = [];
foreach (@$payments) {
$_->{amount} =~ s/£//;
push @$data, {
# Could GetEventType and loop through it all to find these IDs out but for just this seemed okay
id => 27409,
childdata => [
{ id => 27410, value => $_->{ref} },
{ id => 27411, value => $_->{amount} },
],
};
}
$integ->UpdateEvent({ id => $event->{Id}, data => $data });
$args->{description} = ''; # Blank out so nothing sent to Echo now
}

1;
66 changes: 1 addition & 65 deletions perllib/Open311/Endpoint/Integration/UK/Merton/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Merton specifics for its Echo backend
package Open311::Endpoint::Integration::UK::Merton::Echo;

use utf8;
use DateTime;
use Moo;
extends 'Open311::Endpoint::Integration::Echo';
with 'Open311::Endpoint::Role::SLWP';

around BUILDARGS => sub {
my ($orig, $class, %args) = @_;
Expand All @@ -42,68 +42,4 @@ around process_service_request_args => sub {
return $request;
};

around check_for_data_value => sub {
my ($orig, $class, $name, $args, $request, $parent_name) = @_;

my $service = $args->{attributes}{service_id} || '';

return 1 if $name eq 'Container Mix' && ($service eq '2241' || $service eq '2250' || $service eq '2246' || $service eq '3571');
return 1 if $name eq 'Paper' && ($service eq '2240' || $service eq '2249' || $service eq '2632');
return 1 if $name eq 'Food' && ($service eq '2239' || $service eq '2248');
return 1 if ($name eq 'Garden' || $name eq 'Garden Waste ') && $service eq '2247'; # Attribute has a space at the end
return 1 if $name eq 'Refuse Bag' && $service eq '2242';
return 1 if $name eq 'Refuse Bin' && ($service eq '2238' || $service eq '2243' || $service eq '3576');

# Garden waste
if ($args->{service_code} eq '1638') {
my $method = $args->{attributes}{LastPayMethod} || '';
return 2 if $name eq 'Payment Type' && $method eq 3; # DD
return 3 if $name eq 'Payment Type' && $method eq 4; # 'cheque' (or phone)
}

# Bulky items
if ($args->{service_code} eq '1636') {
# Default in configuration is Payment Type 1 (Card), Payment Method 2 (Website)
my $method = $args->{attributes}{payment_method} || '';
return 2 if $name eq 'Payment Type' && $method eq 'cheque'; # Cheque
if ($name eq 'Payment Method') {
return 1 if $method eq 'csc' || $method eq 'cheque'; # Borough Phone Payment
return 2 if $method eq 'credit_card'; # Borough Website Payment
}
}

return $class->$orig($name, $args, $request, $parent_name);
};

around post_service_request_update => sub {
my ($orig, $class, $args) = @_;
return $class->$orig($args) unless $args->{description};

if ($args->{description} =~ /Payment confirmed, reference (.*), amount (.*)/) {
my ($ref, $amount) = ($1, $2);
$amount =~ s/£//;
my $integ = $class->get_integration;
my $event = $integ->GetEvent($args->{service_request_id});
# Could GetEventType and loop through it all to find these IDs out but for just this seemed okay
my $data = {
id => 27409,
childdata => [
{ id => 27410, value => $ref },
{ id => 27411, value => $amount },
],
};
$integ->UpdateEvent({ id => $event->{Id}, data => [ $data ] });
$args->{description} = ''; # Blank out so nothing sent to Echo now
}

if ($args->{description} =~ /Booking cancelled/) {
$args->{actiontype_id} = 8;
$args->{datatype_id} = 0;
}

my $result = $class->$orig($args);

return $result;
};

1;
26 changes: 10 additions & 16 deletions perllib/Open311/Endpoint/Role/SLWP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ around check_for_data_value => sub {
return 1 if $name eq 'Container Mix' && ($service eq '2241' || $service eq '2250' || $service eq '2246' || $service eq '3571');
return 1 if $name eq 'Paper' && ($service eq '2240' || $service eq '2249' || $service eq '2632');
return 1 if $name eq 'Food' && ($service eq '2239' || $service eq '2248');
return 1 if $name eq 'Garden' && $service eq '2247';
return 1 if ($name eq 'Garden' || $name eq 'Garden Waste ') && $service eq '2247'; # Attribute has a space at the end
return 1 if $name eq 'Refuse Bag' && $service eq '2242';
return 1 if $name eq 'Refuse Bin' && ($service eq '2238' || $service eq '2243' || $service eq '3576');

Expand Down Expand Up @@ -52,24 +52,18 @@ around post_service_request_update => sub {
my ($orig, $class, $args) = @_;
return $class->$orig($args) unless $args->{description};

if ($args->{description} =~ /Payment confirmed, reference (.*), amount (.*)/) {
if (my $payments = $args->{attributes}{payments}) {
my @payments = map {
my ($ref, $amount) = split /,/, $_;
{ ref => $ref, amount => $amount }
} split /\|/, $payments;
$class->update_event_payment($args, \@payments);
} elsif ($args->{description} =~ /Payment confirmed, reference (.*), amount (.*)/) {
my ($ref, $amount) = ($1, $2);
$amount =~ s/£//;
my $integ = $class->get_integration;
my $event = $integ->GetEvent($args->{service_request_id});
# Could GetEventType and loop through it all to find these IDs out but for just this seemed okay
my $data = {
id => 27409,
childdata => [
{ id => 27410, value => $ref },
{ id => 27411, value => $amount },
],
};
$integ->UpdateEvent({ id => $event->{Id}, data => [ $data ] });
$args->{description} = ''; # Blank out so nothing sent to Echo now
$class->update_event_payment($args, [ { ref => $ref, amount => $amount } ]);
}

if ($args->{description} eq 'Booking cancelled by customer') {
if ($args->{description} =~ /Booking cancelled/ || $args->{attributes}{booking_cancelled}) {
$args->{actiontype_id} = 8;
$args->{datatype_id} = 0;
}
Expand Down

0 comments on commit c1cf268

Please sign in to comment.