diff --git a/perllib/Open311/Endpoint/Integration/Echo.pm b/perllib/Open311/Endpoint/Integration/Echo.pm index 5ff8b7a10..748eb65d0 100644 --- a/perllib/Open311/Endpoint/Integration/Echo.pm +++ b/perllib/Open311/Endpoint/Integration/Echo.pm @@ -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; @@ -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; diff --git a/perllib/Open311/Endpoint/Integration/UK/Merton/Echo.pm b/perllib/Open311/Endpoint/Integration/UK/Merton/Echo.pm index 7f63396fa..4ccc6e228 100644 --- a/perllib/Open311/Endpoint/Integration/UK/Merton/Echo.pm +++ b/perllib/Open311/Endpoint/Integration/UK/Merton/Echo.pm @@ -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) = @_; @@ -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; diff --git a/perllib/Open311/Endpoint/Role/SLWP.pm b/perllib/Open311/Endpoint/Role/SLWP.pm index dd9b1c004..062584518 100644 --- a/perllib/Open311/Endpoint/Role/SLWP.pm +++ b/perllib/Open311/Endpoint/Role/SLWP.pm @@ -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'); @@ -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; } diff --git a/perllib/Open311/Endpoint/Role/mySociety.pm b/perllib/Open311/Endpoint/Role/mySociety.pm index 756fd8a58..83e074be7 100644 --- a/perllib/Open311/Endpoint/Role/mySociety.pm +++ b/perllib/Open311/Endpoint/Role/mySociety.pm @@ -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 diff --git a/t/open311/endpoint/merton_echo.t b/t/open311/endpoint/merton_echo.t index a55aaf100..c3c2b38be 100644 --- a/t/open311/endpoint/merton_echo.t +++ b/t/open311/endpoint/merton_echo.t @@ -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', );