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

[SLWP] Submit successful payment action. #301

Merged
merged 3 commits into from
Jan 18, 2024
Merged
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
25 changes: 18 additions & 7 deletions perllib/Integrations/Echo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,34 @@ sub PostEvent {
$self->call('PostEvent', event => $data);
}

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

my $data = ixhash(
Id => $args->{id},
Data => extensible_data($args->{data}),
);
$self->call('PostEvent', event => $data);
}

sub PerformEventAction {
my ($self, $args) = @_;
my $ref = ixhash(
Key => 'Guid',
Type => 'Event',
Value => [ { 'msArray:anyType' => $args->{service_request_id} }, ],
);
my $action = ixhash(
ActionTypeId => $args->{actiontype_id} || 3,
Data => { ExtensibleDatum => ixhash(
my @params;
push @params, ActionTypeId => $args->{actiontype_id} || 3;
if (!defined($args->{datatype_id}) || $args->{datatype_id}) {
push @params, Data => { ExtensibleDatum => ixhash(
DatatypeId => $args->{datatype_id} || 1,
Value => $args->{description},
) },
EventRef => $ref,
);
) };
}
push @params, EventRef => $ref;
my $action = ixhash(@params);
$self->call('PerformEventAction', action => $action);

}

sub ixhash {
Expand Down
28 changes: 28 additions & 0 deletions perllib/Open311/Endpoint/Integration/UK/Sutton.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
=head1 NAME
Open311::Endpoint::Integration::UK::Sutton
=head1 DESCRIPTION
The Sutton integration. As well as the boilerplate, and setting it as an Echo
integration, this makes sure the right "Payment Taken By" option is chosen for
bulky collections.
=cut

package Open311::Endpoint::Integration::UK::Sutton;

use Moo;
Expand All @@ -10,4 +22,20 @@ around BUILDARGS => sub {
return $class->$orig(%args);
};

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

# Bulky items
if ($args->{service_code} eq '1636') {
my $method = $args->{attributes}{payment_method} || '';
if ($method eq 'csc' || $method eq 'cheque') {
return 1 if $name eq 'Payment Taken By'; # Council
} elsif ($method eq 'credit_card') {
return 2 if $name eq 'Payment Taken By'; # Veolia
}
}

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

1;
62 changes: 59 additions & 3 deletions perllib/Open311/Endpoint/Role/SLWP.pm
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
=head1 NAME

Open311::Endpoint::Role::SLWP

=head1 DESCRIPTION

Special handling for both Kingston and Sutton. This makes sure the right
container types are picked for requests, and that the right payment options are
chosen for garden/bulky.

=cut

package Open311::Endpoint::Role::SLWP;

use Moo::Role;
Expand All @@ -14,11 +26,55 @@ around check_for_data_value => sub {
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');

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)
# 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);
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} eq 'Booking cancelled by customer') {
$args->{actiontype_id} = 8;
$args->{datatype_id} = 0;
}

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

return $result;
};

1;
129 changes: 125 additions & 4 deletions t/open311/endpoint/kingston.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use JSON::MaybeXS;
use_ok 'Open311::Endpoint::Integration::UK::Kingston';

use constant EVENT_TYPE_SUBSCRIBE => 1638;
use constant EVENT_TYPE_BULKY => 1636;

my $soap_lite = Test::MockModule->new('SOAP::Lite');
$soap_lite->mock(call => sub {
Expand All @@ -45,11 +46,47 @@ $soap_lite->mock(call => sub {
my $method = $args[0]->name;
if ($method eq 'PostEvent') {
my @params = ${$args[3]->value}->value;
my $client_ref = $params[1]->value;
like $client_ref, qr/RBK-2000123|REF-123/;
if (@params == 5) {
my $client_ref = $params[1]->value;
like $client_ref, qr/RBK-2000123|REF-123|bulky-cc|bulky-phone/;
my $event_type_id = $params[3]->value;
if ($event_type_id == 1636) {
my @data = ${$params[0]->value}->value->value;
my @payment = ${$data[0]->value}->value;
is $payment[0]->value, 1011;
is $payment[1]->value, 1;
my $val = $client_ref eq 'bulky-cc' ? 2 : 1;
@payment = ${$data[1]->value}->value;
is $payment[0]->value, 1012;
is $payment[1]->value, 1; # Always 1
@payment = ${$data[2]->value}->value;
is $payment[0]->value, 1013;
is $payment[1]->value, $val;
}
} elsif (@params == 2) {
is $params[0]->value, '123pay';
my @data = ${$params[1]->value}->value->value;
my @payment = ${$data[0]->value}->value;
is $payment[1]->value, 27409;
my @child = ${$payment[0]->value}->value->value;
my @ref = ${$child[0]->value}->value;
is $ref[0]->value, 27410;
is $ref[1]->value, 'ABC';
@ref = ${$child[1]->value}->value;
is $ref[0]->value, 27411;
is $ref[1]->value, '£34.56';
} else {
is @params, 'UNKNOWN';
}
return SOAP::Result->new(result => {
EventGuid => '1234',
});
} elsif ($args[0]->name eq 'GetEvent') {
return SOAP::Result->new(result => {
Id => '123pay',
EventTypeId => EVENT_TYPE_BULKY,
EventStateId => 4002,
});
} elsif ($method eq 'GetEventType') {
return SOAP::Result->new(result => {
Datatypes => { ExtensibleDatatype => [
Expand All @@ -60,8 +97,18 @@ $soap_lite->mock(call => sub {
] },
},
{ Id => 1008, Name => "Notes" },
{ Id => 1011, Name => "Payment Type" },
{ Id => 1012, Name => "Payment Taken By" },
{ Id => 1013, Name => "Payment Method" },
] },
});
} elsif ($method eq 'PerformEventAction') {
my @params = ${$args[3]->value}->value;
is @params, 2, 'No notes';
my $ref = ${(${$params[1]->value}->value)[2]->value}->value->value->value;
my $actiontype_id = $params[0]->value;
is $actiontype_id, 8;
return SOAP::Result->new(result => { EventActionGuid => 'ABC' });
} else {
is $method, 'UNKNOWN';
}
Expand All @@ -73,7 +120,6 @@ my $endpoint = Open311::Endpoint::Integration::Echo::Dummy->new;
my @params = (
POST => '/requests.json',
api_key => 'test',
service_code => EVENT_TYPE_SUBSCRIBE,
first_name => 'Bob',
last_name => 'Mould',
description => "This is the details",
Expand All @@ -87,7 +133,9 @@ my @params = (
);

subtest "POST subscription request OK" => sub {
my $res = $endpoint->run_test_request(@params);
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_SUBSCRIBE,
);
ok $res->is_success, 'valid request'
or diag $res->content;

Expand All @@ -99,6 +147,7 @@ subtest "POST subscription request OK" => sub {

subtest "POST subscription request with client ref provided OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_SUBSCRIBE,
'attribute[client_reference]' => 'REF-123',
);
ok $res->is_success, 'valid request'
Expand All @@ -110,4 +159,76 @@ subtest "POST subscription request with client ref provided OK" => sub {
} ], 'correct json returned';
};

subtest "POST bulky request card payment OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_BULKY,
'attribute[payment_method]' => 'credit_card',
'attribute[client_reference]' => 'bulky-cc',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

subtest "POST bulky request phone payment OK" => sub {
my $res = $endpoint->run_test_request(@params,
service_code => EVENT_TYPE_BULKY,
'attribute[payment_method]' => 'csc',
'attribute[client_reference]' => 'bulky-phone',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"service_request_id" => '1234',
} ], 'correct json returned';
};

subtest "POST a successful payment" => sub {
my $res = $endpoint->run_test_request(
POST => '/servicerequestupdates.json',
api_key => 'test',
updated_datetime => '2023-09-01T19:00:00+01:00',
service_request_id => '123pay',
update_id => 456,
status => 'OPEN',
description => 'Payment confirmed, reference ABC, amount £34.56',
first_name => 'Bob',
last_name => 'Mould',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"update_id" => 'BLANK',
} ], 'correct json returned';
};

subtest "POST a cancellation" => sub {
my $res = $endpoint->run_test_request(
POST => '/servicerequestupdates.json',
api_key => 'test',
updated_datetime => '2023-09-01T19:00:00+01:00',
service_request_id => '123cancel',
update_id => 456,
status => 'OPEN',
description => 'Booking cancelled by customer',
first_name => 'Bob',
last_name => 'Mould',
);
ok $res->is_success, 'valid request'
or diag $res->content;

is_deeply decode_json($res->content),
[ {
"update_id" => 'ABC',
} ], 'correct json returned';
};

done_testing;
19 changes: 19 additions & 0 deletions t/open311/endpoint/kingston.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,26 @@ client_reference_prefix: RBK

service_whitelist:
1638: 'Garden subscription'
1636: 'Bulky collection'

service_extra_data:
1636:
payment: 1
payment_method: 1
Payment_Type: 1
Collection_Date: 1
Bulky_Collection_Bulky_Items: 1
Bulky_Collection_Notes: 1
Exact_Location: 1
GUID: 1
reservation: 1
Customer_Selected_Date_Beyond_SLA?: 1
First_Date_Returned_to_Customer: 1

service_id_override:
1638: 409

default_data_event_type:
1636:
Payment Type: 1
Payment Taken By: 1
Loading
Loading