64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Data;
|
|
|
|
use App\Contracts\OutputDataTransferObject;
|
|
use App\Enums\PaymentModes;
|
|
|
|
final readonly class PaymentResponseDTO implements OutputDataTransferObject
|
|
{
|
|
public function __construct(
|
|
public bool $isSuccess,
|
|
public int $amount,
|
|
public string $currency,
|
|
public PaymentModes $method,
|
|
public ?string $transactionId = null,
|
|
public ?string $errorMessage = null,
|
|
public ?string $redirectUrl = null,
|
|
) {}
|
|
|
|
public static function success(
|
|
string $transactionId,
|
|
int $amount,
|
|
string $currency,
|
|
PaymentModes $method,
|
|
?string $redirectUrl = null
|
|
): self {
|
|
return new self(
|
|
isSuccess: true,
|
|
amount: $amount,
|
|
currency: $currency,
|
|
method: $method,
|
|
transactionId: $transactionId,
|
|
redirectUrl: $redirectUrl,
|
|
);
|
|
}
|
|
|
|
public static function failure(int $amount, string $currency, PaymentModes $method, string $errorMessage): self
|
|
{
|
|
return new self(
|
|
isSuccess: false,
|
|
amount: $amount,
|
|
currency: $currency,
|
|
method: $method,
|
|
errorMessage: $errorMessage,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'isSuccess' => $this->isSuccess,
|
|
'transactionId' => $this->transactionId,
|
|
'amount' => $this->amount,
|
|
'currency' => $this->currency,
|
|
'method' => $this->method,
|
|
'redirectUrl' => $this->redirectUrl,
|
|
'errorMessage' => $this->errorMessage,
|
|
];
|
|
}
|
|
}
|