Merge pull request #106 from goteo/feat/gv4-089-add-checkout-refund-flag
GV4-089 Add Checkout Refund Flag
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Gateway;
|
||||
|
||||
enum RefundStrategy: string
|
||||
{
|
||||
case ToPaymentMethod = 'to_payment_method';
|
||||
case ToWallet = 'to_wallet';
|
||||
}
|
||||
@@ -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()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user