Skip to content

Commit a04aaf7

Browse files
authored
[ACL-135] Add support for attempt_failed payment status (#57)
1 parent 59e39ec commit a04aaf7

23 files changed

+262
-149
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.3.0] - 2024-07-18
9+
10+
### Added
11+
12+
- Support for `attempt_failed` payment status
13+
814
## [2.2.0] - 2024-07-15
915

1016
### Added

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
4. [Executed Status](#status-executed)
2626
5. [Settled Status](#status-settled)
2727
6. [Failed Status](#status-failed)
28-
7. [Authorization flow config](#auth-flow-config)
29-
8. [Source of funds](#source-of-funds)
28+
7. [Attempt Failed Status](#status-attempt-failed)
29+
8. [Authorization flow config](#auth-flow-config)
30+
9. [Source of funds](#source-of-funds)
3031
7. [Authorizing a payment](#authorizing-payment)
3132
8. [Refunds](#refunds)
3233
9. [Payouts](#payouts)
@@ -418,7 +419,8 @@ $payment->isAuthorizing();
418419
$payment->isAuthorized(); // Will also return false when the payment has progressed to executed, failed or settled states.
419420
$payment->isExecuted(); // Will also return false when the payment has progressed to failed or settled states.
420421
$payment->isSettled();
421-
$payment->isFailed();
422+
$payment->isFailed(); // Payment has failed
423+
$payment->isAttemptFailed(); // Payment attempt has failed, only available if payment retries are enabled.
422424
```
423425

424426
Or you can get the status as a string and compare it to the provided constants in `PaymentStatus`:
@@ -587,6 +589,23 @@ if ($payment instanceof PaymentFailedInterface) {
587589
}
588590
```
589591

592+
<a name="status-attempt-failed"></a>
593+
594+
### Attempt Failed Status
595+
596+
> Status only available when you enable payment retries.
597+
598+
```php
599+
use TrueLayer\Interfaces\Payment\PaymentAttemptFailedInterface;
600+
601+
if ($payment instanceof PaymentAttemptFailedInterface) {
602+
$payment->getFailedAt(); // The date and time the payment failed at
603+
$payment->getFailureStage(); // The status the payment was when it failed, one of `authorization_required`, `authorizing` or `authorized`
604+
$payment->getFailureReason(); // The reason the payment failed. Handle unexpected values gracefully as an unknown failure.
605+
$payment->getAuthorizationFlowConfig(); // see authorization flow config
606+
}
607+
```
608+
590609
<a name="auth-flow-config"></a>
591610

592611
### Authorization flow config

config/bindings.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
Interfaces\Payment\PaymentExecutedInterface::class => Entities\Payment\PaymentRetrieved\PaymentExecuted::class,
2424
Interfaces\Payment\PaymentSettledInterface::class => Entities\Payment\PaymentRetrieved\PaymentSettled::class,
2525
Interfaces\Payment\PaymentFailedInterface::class => Entities\Payment\PaymentRetrieved\PaymentFailed::class,
26+
Interfaces\Payment\PaymentAttemptFailedInterface::class => Entities\Payment\PaymentRetrieved\PaymentAttemptFailed::class,
2627
Interfaces\Payment\PaymentSourceInterface::class => Entities\Payment\PaymentRetrieved\PaymentSource::class,
2728

2829
TrueLayer\Interfaces\Payment\StartAuthorizationFlowRequestInterface::class => Entities\Payment\AuthorizationFlow\StartAuthorizationFlowRequest::class,
2930
Interfaces\Payment\AuthorizationFlow\AuthorizationFlowInterface::class => Entities\Payment\AuthorizationFlow\AuthorizationFlow::class,
3031
Interfaces\Payment\AuthorizationFlow\ConfigurationInterface::class => Entities\Payment\AuthorizationFlow\Configuration::class,
32+
Interfaces\Payment\AuthorizationFlow\ActionInterface::class => Entities\Payment\AuthorizationFlow\Action::class,
3133
Interfaces\Payment\AuthorizationFlow\Action\ProviderSelectionActionInterface::class => Entities\Payment\AuthorizationFlow\Action\ProviderSelectionAction::class,
3234
Interfaces\Payment\AuthorizationFlow\Action\RedirectActionInterface::class => Entities\Payment\AuthorizationFlow\Action\RedirectAction::class,
3335
Interfaces\Payment\AuthorizationFlow\Action\WaitActionInterface::class => Entities\Payment\AuthorizationFlow\Action\WaitAction::class,

config/discriminations.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
PaymentStatus::EXECUTED => Interfaces\Payment\PaymentExecutedInterface::class,
2424
PaymentStatus::SETTLED => Interfaces\Payment\PaymentSettledInterface::class,
2525
PaymentStatus::FAILED => Interfaces\Payment\PaymentFailedInterface::class,
26+
PaymentStatus::ATTEMPT_FAILED => Interfaces\Payment\PaymentAttemptFailedInterface::class,
2627
],
2728
Interfaces\Payment\AuthorizationFlow\AuthorizationFlowResponseInterface::class => [
2829
'discriminate_on' => 'status',

src/Constants/AuthorizationFlowActionTypes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class AuthorizationFlowActionTypes
99
public const PROVIDER_SELECTION = 'provider_selection';
1010
public const REDIRECT = 'redirect';
1111
public const WAIT = 'wait';
12+
public const RETRY = 'retry';
1213
}

src/Constants/PaymentStatus.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ class PaymentStatus
1111
public const AUTHORIZED = 'authorized';
1212
public const EXECUTED = 'executed';
1313
public const FAILED = 'failed';
14+
public const ATTEMPT_FAILED = 'attempt_failed';
1415
public const SETTLED = 'settled';
1516
}

src/Entities/Payment/AuthorizationFlow/Action.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,27 @@
55
namespace TrueLayer\Entities\Payment\AuthorizationFlow;
66

77
use TrueLayer\Entities\Entity;
8-
use TrueLayer\Interfaces\Payment\AuthorizationFlow\ActionInterface;
8+
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\ActionInterface;
99

10-
abstract class Action extends Entity implements ActionInterface
10+
class Action extends Entity implements ActionInterface
1111
{
12+
/**
13+
* @var string
14+
*/
15+
protected string $type;
16+
17+
/**
18+
* @var string[]
19+
*/
20+
protected array $arrayFields = [
21+
'type',
22+
];
23+
1224
/**
1325
* @return string
1426
*/
15-
abstract public function getType(): string;
27+
public function getType(): string
28+
{
29+
return $this->type;
30+
}
1631
}

src/Entities/Payment/AuthorizationFlow/Action/ProviderSelectionAction.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;
66

7-
use TrueLayer\Constants\AuthorizationFlowActionTypes;
87
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
98
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\ProviderSelectionActionInterface;
109
use TrueLayer\Interfaces\Provider\ProviderInterface;
@@ -38,12 +37,4 @@ public function getProviders(): array
3837
{
3938
return $this->providers;
4039
}
41-
42-
/**
43-
* @return string
44-
*/
45-
public function getType(): string
46-
{
47-
return AuthorizationFlowActionTypes::PROVIDER_SELECTION;
48-
}
4940
}

src/Entities/Payment/AuthorizationFlow/Action/RedirectAction.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;
66

7-
use TrueLayer\Constants\AuthorizationFlowActionTypes;
87
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
98
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\RedirectActionInterface;
109
use TrueLayer\Interfaces\Provider\ProviderInterface;
@@ -45,14 +44,6 @@ public function getUri(): string
4544
return $this->uri;
4645
}
4746

48-
/**
49-
* @return string
50-
*/
51-
public function getType(): string
52-
{
53-
return AuthorizationFlowActionTypes::REDIRECT;
54-
}
55-
5647
/**
5748
* @return string
5849
*/

src/Entities/Payment/AuthorizationFlow/Action/WaitAction.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,10 @@
44

55
namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;
66

7-
use TrueLayer\Constants\AuthorizationFlowActionTypes;
87
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
98
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\WaitActionInterface;
109

1110
class WaitAction extends Action implements WaitActionInterface
1211
{
13-
/**
14-
* @var string[]
15-
*/
16-
protected array $arrayFields = [
17-
'type',
18-
];
1912

20-
/**
21-
* @return string
22-
*/
23-
public function getType(): string
24-
{
25-
return AuthorizationFlowActionTypes::WAIT;
26-
}
2713
}

0 commit comments

Comments
 (0)