From eafdefec42ecd96c40e917f1c37eb4e052e41903 Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Fri, 11 Apr 2025 10:04:52 +0200 Subject: [PATCH 1/5] Add refund strategy enum --- src/Gateway/RefundStrategy.php | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/Gateway/RefundStrategy.php diff --git a/src/Gateway/RefundStrategy.php b/src/Gateway/RefundStrategy.php new file mode 100644 index 0000000..be478ff --- /dev/null +++ b/src/Gateway/RefundStrategy.php @@ -0,0 +1,9 @@ + Date: Fri, 11 Apr 2025 10:18:43 +0200 Subject: [PATCH 2/5] Add refund strategy property to checkout --- src/Entity/Gateway/Checkout.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Entity/Gateway/Checkout.php b/src/Entity/Gateway/Checkout.php index 3d55a71..88823dc 100644 --- a/src/Entity/Gateway/Checkout.php +++ b/src/Entity/Gateway/Checkout.php @@ -8,6 +8,7 @@ use App\Entity\Trait\TimestampedCreationEntity; use App\Entity\Trait\TimestampedUpdationEntity; use App\Gateway\CheckoutStatus; use App\Gateway\Link; +use App\Gateway\RefundStrategy; use App\Gateway\Tracking; use App\Mapping\Provider\EntityMapProvider; use App\Repository\Gateway\CheckoutRepository; @@ -67,6 +68,12 @@ class Checkout #[ORM\OneToMany(mappedBy: 'checkout', targetEntity: Charge::class, cascade: ['persist'])] private Collection $charges; + /** + * The strategy to refund the payment. + */ + #[ORM\Column(enumType: RefundStrategy::class)] + private ?RefundStrategy $refundStrategy = null; + /** * The address to where the user must be redirected to. */ @@ -180,6 +187,18 @@ class Checkout return $this; } + public function getRefundStrategy(): ?RefundStrategy + { + return $this->refundStrategy; + } + + public function setRefundStrategy(?RefundStrategy $refundStrategy): static + { + $this->refundStrategy = $refundStrategy; + + return $this; + } + public function getReturnUrl(): ?string { return $this->returnUrl; From bbcc7d331abbe6b539bd3c8e75c2e2e4d1afb712 Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Fri, 11 Apr 2025 10:27:18 +0200 Subject: [PATCH 3/5] Add refund method to gateway interface --- src/Gateway/GatewayInterface.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Gateway/GatewayInterface.php b/src/Gateway/GatewayInterface.php index 7e736af..751032f 100644 --- a/src/Gateway/GatewayInterface.php +++ b/src/Gateway/GatewayInterface.php @@ -64,4 +64,12 @@ interface GatewayInterface * @return Response A Response object to send back to the gateway */ public function handleWebhook(Request $request): Response; + + /** + * Process a partial refund based on failed project charges in a checkout. + * The method should use the refund strategy defined in the Checkout. + * + * @param Checkout $checkout the checkout containing refund strategy and charges + */ + public function processRefund(Checkout $checkout): void; } From 39e5c48ed5c2d487cfdb1fcf5a604f3a2014599f Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Fri, 11 Apr 2025 12:10:38 +0200 Subject: [PATCH 4/5] Implement abstract process refund --- src/Gateway/AbstractGateway.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Gateway/AbstractGateway.php b/src/Gateway/AbstractGateway.php index 22f214a..53b00ba 100644 --- a/src/Gateway/AbstractGateway.php +++ b/src/Gateway/AbstractGateway.php @@ -71,4 +71,12 @@ abstract class AbstractGateway implements GatewayInterface return $checkout; } + + public function processRefund(Checkout $checkout): void + { + throw new \LogicException(sprintf( + 'The refund operation is not implemented for the %s gateway.', + static::getName() + )); + } } From 1e397ecd8d6b9d0df3e092c85d7f62e8a3a2bbbf Mon Sep 17 00:00:00 2001 From: cmorenov1402 Date: Fri, 11 Apr 2025 12:12:48 +0200 Subject: [PATCH 5/5] Create not implemented refund method in wallet gateway --- src/Gateway/Wallet/WalletGateway.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Gateway/Wallet/WalletGateway.php b/src/Gateway/Wallet/WalletGateway.php index 02f4c1f..767d29e 100644 --- a/src/Gateway/Wallet/WalletGateway.php +++ b/src/Gateway/Wallet/WalletGateway.php @@ -83,4 +83,12 @@ class WalletGateway implements GatewayInterface return $total; } + + public function processRefund(Checkout $checkout): void + { + throw new \LogicException(sprintf( + 'The refund operation is not implemented for the %s gateway.', + static::getName() + )); + } }