diff --git a/Changelog.md b/Changelog.md index d2473bc..7834607 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,8 @@ ##### 2024-XX-YY - Changed the offline payment gateway's icon from a circle to a plug+x +- [EXPERIMENTAL] Added the supportsRetry, allowsRefund, canBeRetried and getRetryRequest methods to the TransactionHandler interface +- [EXPERIMENTAL] Added the `NoTransaction` DTO ## 4.0.0 ##### 2024-04-25 diff --git a/Contracts/TransactionHandler.php b/Contracts/TransactionHandler.php index a7e4b76..d029d60 100644 --- a/Contracts/TransactionHandler.php +++ b/Contracts/TransactionHandler.php @@ -19,7 +19,16 @@ */ interface TransactionHandler { + /** @todo Move this to the Gateway in v5 along with all future supports methods */ public function supportsRefunds(): bool; + public function supportsRetry(): bool; + + public function allowsRefund(Payment $payment): bool; + public function issueRefund(Payment $payment, float $amount, array $options = []): Transaction|TransactionNotCreated; + + public function canBeRetried(Payment $payment): bool; + + public function getRetryRequest(Payment $payment, array $options = []): PaymentRequest|TransactionNotCreated; } diff --git a/Responses/NoTransaction.php b/Responses/NoTransaction.php new file mode 100644 index 0000000..878e8dd --- /dev/null +++ b/Responses/NoTransaction.php @@ -0,0 +1,80 @@ +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; + } +}