Merge pull request #106 from goteo/feat/gv4-089-add-checkout-refund-flag

GV4-089 Add Checkout Refund Flag
This commit is contained in:
2025-04-14 14:17:38 +02:00
committed by GitHub
5 changed files with 52 additions and 0 deletions
+19
View File
@@ -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;
+8
View File
@@ -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()
));
}
}
+8
View File
@@ -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;
}
+9
View File
@@ -0,0 +1,9 @@
<?php
namespace App\Gateway;
enum RefundStrategy: string
{
case ToPaymentMethod = 'to_payment_method';
case ToWallet = 'to_wallet';
}
+8
View File
@@ -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()
));
}
}