Skip to content

Commit

Permalink
[ACL-135] Add support for attempt_failed payment status (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
lighe authored Jul 19, 2024
1 parent 59e39ec commit a04aaf7
Show file tree
Hide file tree
Showing 23 changed files with 262 additions and 149 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.3.0] - 2024-07-18

### Added

- Support for `attempt_failed` payment status

## [2.2.0] - 2024-07-15

### Added
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
4. [Executed Status](#status-executed)
5. [Settled Status](#status-settled)
6. [Failed Status](#status-failed)
7. [Authorization flow config](#auth-flow-config)
8. [Source of funds](#source-of-funds)
7. [Attempt Failed Status](#status-attempt-failed)
8. [Authorization flow config](#auth-flow-config)
9. [Source of funds](#source-of-funds)
7. [Authorizing a payment](#authorizing-payment)
8. [Refunds](#refunds)
9. [Payouts](#payouts)
Expand Down Expand Up @@ -418,7 +419,8 @@ $payment->isAuthorizing();
$payment->isAuthorized(); // Will also return false when the payment has progressed to executed, failed or settled states.
$payment->isExecuted(); // Will also return false when the payment has progressed to failed or settled states.
$payment->isSettled();
$payment->isFailed();
$payment->isFailed(); // Payment has failed
$payment->isAttemptFailed(); // Payment attempt has failed, only available if payment retries are enabled.
```

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

<a name="status-attempt-failed"></a>

### Attempt Failed Status

> Status only available when you enable payment retries.
```php
use TrueLayer\Interfaces\Payment\PaymentAttemptFailedInterface;

if ($payment instanceof PaymentAttemptFailedInterface) {
$payment->getFailedAt(); // The date and time the payment failed at
$payment->getFailureStage(); // The status the payment was when it failed, one of `authorization_required`, `authorizing` or `authorized`
$payment->getFailureReason(); // The reason the payment failed. Handle unexpected values gracefully as an unknown failure.
$payment->getAuthorizationFlowConfig(); // see authorization flow config
}
```

<a name="auth-flow-config"></a>

### Authorization flow config
Expand Down
2 changes: 2 additions & 0 deletions config/bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
Interfaces\Payment\PaymentExecutedInterface::class => Entities\Payment\PaymentRetrieved\PaymentExecuted::class,
Interfaces\Payment\PaymentSettledInterface::class => Entities\Payment\PaymentRetrieved\PaymentSettled::class,
Interfaces\Payment\PaymentFailedInterface::class => Entities\Payment\PaymentRetrieved\PaymentFailed::class,
Interfaces\Payment\PaymentAttemptFailedInterface::class => Entities\Payment\PaymentRetrieved\PaymentAttemptFailed::class,
Interfaces\Payment\PaymentSourceInterface::class => Entities\Payment\PaymentRetrieved\PaymentSource::class,

TrueLayer\Interfaces\Payment\StartAuthorizationFlowRequestInterface::class => Entities\Payment\AuthorizationFlow\StartAuthorizationFlowRequest::class,
Interfaces\Payment\AuthorizationFlow\AuthorizationFlowInterface::class => Entities\Payment\AuthorizationFlow\AuthorizationFlow::class,
Interfaces\Payment\AuthorizationFlow\ConfigurationInterface::class => Entities\Payment\AuthorizationFlow\Configuration::class,
Interfaces\Payment\AuthorizationFlow\ActionInterface::class => Entities\Payment\AuthorizationFlow\Action::class,
Interfaces\Payment\AuthorizationFlow\Action\ProviderSelectionActionInterface::class => Entities\Payment\AuthorizationFlow\Action\ProviderSelectionAction::class,
Interfaces\Payment\AuthorizationFlow\Action\RedirectActionInterface::class => Entities\Payment\AuthorizationFlow\Action\RedirectAction::class,
Interfaces\Payment\AuthorizationFlow\Action\WaitActionInterface::class => Entities\Payment\AuthorizationFlow\Action\WaitAction::class,
Expand Down
1 change: 1 addition & 0 deletions config/discriminations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
PaymentStatus::EXECUTED => Interfaces\Payment\PaymentExecutedInterface::class,
PaymentStatus::SETTLED => Interfaces\Payment\PaymentSettledInterface::class,
PaymentStatus::FAILED => Interfaces\Payment\PaymentFailedInterface::class,
PaymentStatus::ATTEMPT_FAILED => Interfaces\Payment\PaymentAttemptFailedInterface::class,
],
Interfaces\Payment\AuthorizationFlow\AuthorizationFlowResponseInterface::class => [
'discriminate_on' => 'status',
Expand Down
1 change: 1 addition & 0 deletions src/Constants/AuthorizationFlowActionTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class AuthorizationFlowActionTypes
public const PROVIDER_SELECTION = 'provider_selection';
public const REDIRECT = 'redirect';
public const WAIT = 'wait';
public const RETRY = 'retry';
}
1 change: 1 addition & 0 deletions src/Constants/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class PaymentStatus
public const AUTHORIZED = 'authorized';
public const EXECUTED = 'executed';
public const FAILED = 'failed';
public const ATTEMPT_FAILED = 'attempt_failed';
public const SETTLED = 'settled';
}
21 changes: 18 additions & 3 deletions src/Entities/Payment/AuthorizationFlow/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@
namespace TrueLayer\Entities\Payment\AuthorizationFlow;

use TrueLayer\Entities\Entity;
use TrueLayer\Interfaces\Payment\AuthorizationFlow\ActionInterface;
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\ActionInterface;

abstract class Action extends Entity implements ActionInterface
class Action extends Entity implements ActionInterface
{
/**
* @var string
*/
protected string $type;

/**
* @var string[]
*/
protected array $arrayFields = [
'type',
];

/**
* @return string
*/
abstract public function getType(): string;
public function getType(): string
{
return $this->type;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;

use TrueLayer\Constants\AuthorizationFlowActionTypes;
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\ProviderSelectionActionInterface;
use TrueLayer\Interfaces\Provider\ProviderInterface;
Expand Down Expand Up @@ -38,12 +37,4 @@ public function getProviders(): array
{
return $this->providers;
}

/**
* @return string
*/
public function getType(): string
{
return AuthorizationFlowActionTypes::PROVIDER_SELECTION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;

use TrueLayer\Constants\AuthorizationFlowActionTypes;
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\RedirectActionInterface;
use TrueLayer\Interfaces\Provider\ProviderInterface;
Expand Down Expand Up @@ -45,14 +44,6 @@ public function getUri(): string
return $this->uri;
}

/**
* @return string
*/
public function getType(): string
{
return AuthorizationFlowActionTypes::REDIRECT;
}

/**
* @return string
*/
Expand Down
14 changes: 0 additions & 14 deletions src/Entities/Payment/AuthorizationFlow/Action/WaitAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,10 @@

namespace TrueLayer\Entities\Payment\AuthorizationFlow\Action;

use TrueLayer\Constants\AuthorizationFlowActionTypes;
use TrueLayer\Entities\Payment\AuthorizationFlow\Action;
use TrueLayer\Interfaces\Payment\AuthorizationFlow\Action\WaitActionInterface;

class WaitAction extends Action implements WaitActionInterface
{
/**
* @var string[]
*/
protected array $arrayFields = [
'type',
];

/**
* @return string
*/
public function getType(): string
{
return AuthorizationFlowActionTypes::WAIT;
}
}
8 changes: 8 additions & 0 deletions src/Entities/Payment/PaymentRetrieved.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ public function isFailed(): bool
return $this->getStatus() === PaymentStatus::FAILED;
}

/**
* @return bool
*/
public function isAttemptFailed(): bool
{
return $this->getStatus() === PaymentStatus::ATTEMPT_FAILED;
}

/**
* @return bool
*/
Expand Down
11 changes: 11 additions & 0 deletions src/Entities/Payment/PaymentRetrieved/PaymentAttemptFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace TrueLayer\Entities\Payment\PaymentRetrieved;

use TrueLayer\Interfaces\Payment\PaymentAttemptFailedInterface;

final class PaymentAttemptFailed extends PaymentFailure implements PaymentAttemptFailedInterface
{
}
62 changes: 1 addition & 61 deletions src/Entities/Payment/PaymentRetrieved/PaymentFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,6 @@

use TrueLayer\Interfaces\Payment\PaymentFailedInterface;

final class PaymentFailed extends _PaymentWithAuthorizationConfig implements PaymentFailedInterface
final class PaymentFailed extends PaymentFailure implements PaymentFailedInterface
{
/**
* @var \DateTimeInterface
*/
protected \DateTimeInterface $failedAt;

/**
* @var string
*/
protected string $failureStage;

/**
* @var string
*/
protected string $failureReason;

/**
* @return mixed[]
*/
protected function casts(): array
{
return \array_merge_recursive(parent::casts(), [
'failed_at' => \DateTimeInterface::class,
]);
}

/**
* @return mixed[]
*/
protected function arrayFields(): array
{
return \array_merge(parent::arrayFields(), [
'failed_at',
'failure_stage',
'failure_reason',
]);
}

/**
* @return \DateTimeInterface
*/
public function getFailedAt(): \DateTimeInterface
{
return $this->failedAt;
}

/**
* @return string
*/
public function getFailureStage(): string
{
return $this->failureStage;
}

/**
* @return string|null
*/
public function getFailureReason(): ?string
{
return $this->failureReason ?? null;
}
}
69 changes: 69 additions & 0 deletions src/Entities/Payment/PaymentRetrieved/PaymentFailure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace TrueLayer\Entities\Payment\PaymentRetrieved;

abstract class PaymentFailure extends _PaymentWithAuthorizationConfig
{
/**
* @var \DateTimeInterface
*/
protected \DateTimeInterface $failedAt;

/**
* @var string
*/
protected string $failureStage;

/**
* @var string
*/
protected string $failureReason;

/**
* @return mixed[]
*/
protected function casts(): array
{
return \array_merge_recursive(parent::casts(), [
'failed_at' => \DateTimeInterface::class,
]);
}

/**
* @return mixed[]
*/
protected function arrayFields(): array
{
return \array_merge(parent::arrayFields(), [
'failed_at',
'failure_stage',
'failure_reason',
]);
}

/**
* @return \DateTimeInterface
*/
public function getFailedAt(): \DateTimeInterface
{
return $this->failedAt;
}

/**
* @return string
*/
public function getFailureStage(): string
{
return $this->failureStage;
}

/**
* @return string|null
*/
public function getFailureReason(): ?string
{
return $this->failureReason ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@

namespace TrueLayer\Interfaces\Payment\AuthorizationFlow\Action;

use TrueLayer\Interfaces\ArrayableInterface;

interface ActionInterface extends ArrayableInterface
interface ActionInterface extends \TrueLayer\Interfaces\Payment\AuthorizationFlow\ActionInterface
{
/**
* @return string
*/
public function getType(): string;

}
4 changes: 4 additions & 0 deletions src/Interfaces/Payment/AuthorizationFlow/ActionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

interface ActionInterface extends ArrayableInterface
{
/**
* @return string
*/
public function getType(): string;
}
9 changes: 9 additions & 0 deletions src/Interfaces/Payment/PaymentAttemptFailedInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace TrueLayer\Interfaces\Payment;

interface PaymentAttemptFailedInterface extends PaymentFailureInterface
{
}
Loading

0 comments on commit a04aaf7

Please sign in to comment.