ekart/backend/app/Data/Payment/PaymentResponseDTO.php
2026-03-25 17:17:35 +05:30

64 lines
1.7 KiB
PHP

<?php
namespace App\Data\Payment;
use App\Contracts\OutputDataTransferObject;
use App\Enums\Payment\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,
];
}
}