Skip to content

Commit

Permalink
Add APN (PAYE) checking support as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Mar 6, 2025
1 parent 8a471c6 commit 5fd1b46
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 30 deletions.
78 changes: 50 additions & 28 deletions perllib/FixMyStreet/Roles/Cobrand/Paye.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,40 +110,62 @@ around waste_cc_get_redirect_url => sub {
return $self->$orig($c, $back);
};

sub paye_check_payment_status {
my ($self, $apn, $p) = @_;

my $payment = Integrations::Paye->new({
config => $self->feature('payment_gateway')
});

my $resp = $payment->query({
request_id => $p->id,
apnReference => $apn,
});

my ($error, $auth_code, $can, $tx_id);
if ($resp->{transactionState} eq 'Complete') {
if ($resp->{paymentResult}->{status} eq 'Success') {
my $auth_details
= $resp->{paymentResult}{paymentDetails}{authDetails};
$auth_code = $auth_details->{authCode};
$can = $resp->{paymentResult}{paymentDetails}{payments}{paymentSummary}{continuousAuditNumber};
$tx_id = $auth_details->{uniqueAuthId};
} else {
$error = $resp->{paymentResult}->{status};

Check warning on line 134 in perllib/FixMyStreet/Roles/Cobrand/Paye.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Roles/Cobrand/Paye.pm#L134

Added line #L134 was not covered by tests
}
} else {
$error = $resp->{transactionState};

Check warning on line 137 in perllib/FixMyStreet/Roles/Cobrand/Paye.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Roles/Cobrand/Paye.pm#L137

Added line #L137 was not covered by tests
}

return ($error, $auth_code, $can, $tx_id);
}

sub paye_check_payment_and_update {
my ($self, $apn, $p) = @_;
my ($error, $auth_code, $can, $tx_id) = $self->paye_check_payment_status($apn, $p);
if ($error) {
return ($error, undef);

Check warning on line 147 in perllib/FixMyStreet/Roles/Cobrand/Paye.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Roles/Cobrand/Paye.pm#L147

Added line #L147 was not covered by tests
}

$p->update_extra_metadata(
authCode => $auth_code,
continuousAuditNumber => $can,
);
$p->update_extra_field({ name => 'payment_method', value => 'csc' });
$p->update;
return (undef, $tx_id);
}

around waste_cc_check_payment_status => sub {
my ($orig, $self, $c, $p) = @_;

if (my $apn = $p->get_extra_metadata('apnReference')) {
my $payment = Integrations::Paye->new({
config => $self->feature('payment_gateway')
});

my $resp = $payment->query({
request_id => $p->id,
apnReference => $apn,
});

if ($resp->{transactionState} eq 'Complete') {
if ($resp->{paymentResult}->{status} eq 'Success') {
my $auth_details
= $resp->{paymentResult}{paymentDetails}{authDetails};
$p->update_extra_metadata(
authCode => $auth_details->{authCode},
continuousAuditNumber => $resp->{paymentResult}{paymentDetails}{payments}{paymentSummary}{continuousAuditNumber},
);
$p->update_extra_field({ name => 'payment_method', value => 'csc' });
$p->update;

my $ref = $auth_details->{uniqueAuthId};
return $ref;
} else {
$c->stash->{error} = $resp->{paymentResult}->{status};
return undef;
}
} else {
$c->stash->{error} = $resp->{transactionState};
my ($error, $id) = $self->paye_check_payment_and_update($apn, $p);
if ($error) {
$c->stash->{error} = $error;
return undef;
}
return $id;
}

return $self->$orig($c, $p);
Expand Down
8 changes: 6 additions & 2 deletions perllib/FixMyStreet/Script/Waste/CheckPayments.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ sub check_payments {
});
while (my $row = $problems->next) {
$cobrand->set_lang_and_domain($row->lang, 1);
my $query_id = $row->get_extra_metadata('scpReference') or next; # Problem fetching unique ID from payment provider
my ($error, $reference) = $cobrand->cc_check_payment_and_update($query_id, $row);
my ($error, $reference);
if (my $scp = $row->get_extra_metadata('scpReference')) {
($error, $reference) = $cobrand->cc_check_payment_and_update($scp, $row);
} elsif (my $apn = $row->get_extra_metadata('apnReference')) {
($error, $reference) = $cobrand->paye_check_payment_and_update($apn, $row);

Check warning on line 26 in perllib/FixMyStreet/Script/Waste/CheckPayments.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/Script/Waste/CheckPayments.pm#L26

Added line #L26 was not covered by tests
}
if ($reference) {
$row->waste_confirm_payment($reference);
}
Expand Down

0 comments on commit 5fd1b46

Please sign in to comment.