Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merton] Payment passthrough #351

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
27 changes: 11 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,19 @@ 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 @data = split /\|/, $payments;
my @payments;
for (my $i=0; $i<@data; $i+=2) {
push @payments, { ref => $data[$i], amount => $data[$i+1] }
}
$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
8 changes: 3 additions & 5 deletions perllib/Open311/Endpoint/Role/mySociety.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ sub POST_Service_Request_Update_input_schema {
delete $attributes->{required}{update_id};
}

# Allow attributes through for Oxfordshire XXX
if ($jurisdiction eq 'oxfordshire') {
for my $key (grep { /^attribute\[\w+\]$/ } keys %$args) {
$attributes->{optional}{$key} = '//str';
}
# Allow attributes through
for my $key (grep { /^attribute\[\w+\]$/ } keys %$args) {
$attributes->{optional}{$key} = '//str';
}

# Allow nsg_ref through for Bexley XXX
Expand Down
1 change: 1 addition & 0 deletions t/open311/endpoint/merton_echo.t
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ subtest "POST a successful payment" => sub {
update_id => 456,
status => 'OPEN',
description => 'Payment confirmed, reference ABC, amount £34.56',
'attribute[payments]' => 'ABC|34.56',
first_name => 'Bob',
last_name => 'Mould',
);
Expand Down
Loading