-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extended the experimental transaction handling classes
- Loading branch information
1 parent
cd20a40
commit fe5a072
Showing
3 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Contains the NoTransaction class. | ||
* | ||
* @copyright Copyright (c) 2024 Vanilo UG | ||
* @author Attila Fulop | ||
* @license MIT | ||
* @since 2024-06-04 | ||
* | ||
*/ | ||
|
||
namespace Vanilo\Payment\Responses; | ||
|
||
use Vanilo\Payment\Contracts\Payment; | ||
use Vanilo\Payment\Contracts\TransactionNotCreated; | ||
use Vanilo\Payment\Models\PaymentProxy; | ||
|
||
final class NoTransaction implements TransactionNotCreated | ||
{ | ||
private readonly string $paymentId; | ||
private ?Payment $payment = null; | ||
|
||
private ?string $reason = null; | ||
|
||
private bool $shouldBeRetried = false; | ||
|
||
public mixed $details = null; | ||
|
||
public function __construct( | ||
Payment|string $payment, | ||
) { | ||
if ($payment instanceof Payment) { | ||
$this->paymentId = $payment->getPaymentId(); | ||
$this->payment = $payment; | ||
} else { | ||
$this->paymentId = $payment; | ||
} | ||
} | ||
|
||
public static function create(Payment|string $payment, ?string $reason, bool $shouldBeRetried = false): self | ||
{ | ||
$instance = new self($payment); | ||
$instance->reason = $reason; | ||
$instance->shouldBeRetried = $shouldBeRetried; | ||
|
||
return $instance; | ||
} | ||
|
||
public function getPaymentId(): string | ||
{ | ||
return $this->paymentId; | ||
} | ||
|
||
public function getPayment(): Payment | ||
{ | ||
if (null === $this->payment) { | ||
$this->payment = PaymentProxy::find($this->paymentId); | ||
} | ||
|
||
return $this->payment; | ||
} | ||
|
||
public function reason(): ?string | ||
{ | ||
return $this->reason; | ||
} | ||
|
||
public function shouldBeRetried(): bool | ||
{ | ||
return $this->shouldBeRetried; | ||
} | ||
|
||
public function getDetails() | ||
{ | ||
return $this->details; | ||
} | ||
} |