Skip to content

Commit

Permalink
[SLWP] Submit successful payment action.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jan 18, 2024
1 parent c68e1b1 commit 71307e6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
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
25 changes: 25 additions & 0 deletions perllib/Open311/Endpoint/Role/SLWP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,29 @@ around check_for_data_value => sub {
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
}

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

return $result;
};

1;
54 changes: 52 additions & 2 deletions t/open311/endpoint/kingston.t
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,33 @@ $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/;
} 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 => 1636,
EventStateId => 4002,
});
} elsif ($method eq 'GetEventType') {
return SOAP::Result->new(result => {
Datatypes => { ExtensibleDatatype => [
Expand All @@ -62,6 +84,13 @@ $soap_lite->mock(call => sub {
{ Id => 1008, Name => "Notes" },
] },
});
} 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 Down Expand Up @@ -110,4 +139,25 @@ subtest "POST subscription request with client ref provided OK" => sub {
} ], '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';
};

done_testing;

0 comments on commit 71307e6

Please sign in to comment.