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; 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() + )); + } } 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; } 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 @@ +