Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| PaymentResult | |
100.00% |
5 / 5 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| pending | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| redirect | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| paid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| failed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Services\Payment; |
| 4 | |
| 5 | use App\Enums\PaymentStatus; |
| 6 | |
| 7 | /** |
| 8 | * What a driver hands back from charge()/verify()/refund() — never the raw |
| 9 | * provider response. `redirectUrl` is set when the shopper needs to be sent |
| 10 | * off-site (SSLCommerz/Stripe/PayPal-style); null means the driver decided |
| 11 | * the outcome itself with nothing further to show (COD). |
| 12 | */ |
| 13 | final class PaymentResult |
| 14 | { |
| 15 | public function __construct( |
| 16 | public readonly PaymentStatus $status, |
| 17 | public readonly ?string $redirectUrl = null, |
| 18 | public readonly ?string $transactionId = null, |
| 19 | public readonly ?string $message = null, |
| 20 | /** @var array<string, mixed> raw provider fields worth keeping, e.g. for the payment log */ |
| 21 | public readonly array $meta = [], |
| 22 | ) {} |
| 23 | |
| 24 | public static function pending(?string $message = null): self |
| 25 | { |
| 26 | return new self(PaymentStatus::Pending, message: $message); |
| 27 | } |
| 28 | |
| 29 | public static function redirect(string $url, ?string $transactionId = null): self |
| 30 | { |
| 31 | return new self(PaymentStatus::Processing, redirectUrl: $url, transactionId: $transactionId); |
| 32 | } |
| 33 | |
| 34 | public static function paid(string $transactionId, array $meta = []): self |
| 35 | { |
| 36 | return new self(PaymentStatus::Paid, transactionId: $transactionId, meta: $meta); |
| 37 | } |
| 38 | |
| 39 | public static function failed(string $message, array $meta = []): self |
| 40 | { |
| 41 | return new self(PaymentStatus::Failed, message: $message, meta: $meta); |
| 42 | } |
| 43 | } |