Add refund strategy property to checkout api resource
This commit is contained in:
@@ -5,9 +5,11 @@ namespace App\ApiResource\Gateway;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Accounting\AccountingApiResource;
|
||||
use App\Dto\CheckoutUpdationDto;
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use App\Gateway\CheckoutStatus;
|
||||
use App\Gateway\Link;
|
||||
use App\Gateway\RefundStrategy;
|
||||
use App\Gateway\Tracking;
|
||||
use App\Mapping\Transformer\GatewayNameMapTransformer;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
@@ -26,10 +28,13 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
processor: CheckoutStateProcessor::class,
|
||||
)]
|
||||
#[API\GetCollection(
|
||||
security: "is_granted('IS_AUTHENTICATED_FULLY')"
|
||||
security: 'is_granted("IS_AUTHENTICATED_FULLY")'
|
||||
)]
|
||||
#[API\Post()]
|
||||
#[API\Get()]
|
||||
#[API\Patch(
|
||||
input: CheckoutUpdationDto::class,
|
||||
)]
|
||||
class CheckoutApiResource
|
||||
{
|
||||
#[API\ApiProperty(writable: false, identifier: true)]
|
||||
@@ -67,6 +72,14 @@ class CheckoutApiResource
|
||||
#[Assert\Url()]
|
||||
public string $returnUrl;
|
||||
|
||||
/**
|
||||
* The strategy chosen by the User to decide where the money will go to
|
||||
* in the event that one Charge needs to be returned.
|
||||
*/
|
||||
#[MapTo(Checkout::class, property: 'refundStrategy')]
|
||||
#[MapFrom(Checkout::class, property: 'refundStrategy')]
|
||||
public RefundStrategy $refund = RefundStrategy::ToWallet;
|
||||
|
||||
/**
|
||||
* The status of this Checkout, as confirmed by the Gateway.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use App\Gateway\RefundStrategy;
|
||||
use AutoMapper\Attribute\MapTo;
|
||||
|
||||
class CheckoutUpdationDto
|
||||
{
|
||||
#[API\ApiProperty(identifier: true, writable: false)]
|
||||
public int $id;
|
||||
|
||||
/**
|
||||
* The strategy chosen by the User to decide where the money will go to
|
||||
* in the event that one Charge needs to be returned.
|
||||
*/
|
||||
#[MapTo(Checkout::class, property: 'refundStrategy')]
|
||||
public RefundStrategy $refund;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use ApiPlatform\Doctrine\Common\State\PersistProcessor;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\ApiResource\Gateway\CheckoutApiResource;
|
||||
use App\Dto\CheckoutUpdationDto;
|
||||
use App\Entity\Gateway\Checkout;
|
||||
use App\Gateway\GatewayLocator;
|
||||
use App\Mapping\AutoMapper;
|
||||
@@ -21,17 +22,23 @@ class CheckoutStateProcessor implements ProcessorInterface
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param CheckoutApiResource $data
|
||||
* @param CheckoutApiResource|CheckoutUpdationDto $data
|
||||
*
|
||||
* @return Checkout
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
|
||||
{
|
||||
if ($data instanceof CheckoutUpdationDto) {
|
||||
$data = $this->autoMapper->map($uriVariables, $data);
|
||||
}
|
||||
|
||||
$entity = $this->autoMapper->map($data, Checkout::class);
|
||||
$entity = $this->innerProcessor->process($entity, $operation, $uriVariables, $context);
|
||||
|
||||
$entity = $this->gatewayLocator->get($data->gateway->name)->process($entity);
|
||||
$entity = $this->innerProcessor->process($entity, $operation, $uriVariables, $context);
|
||||
if ($data instanceof CheckoutApiResource) {
|
||||
$entity = $this->gatewayLocator->get($data->gateway->name)->process($entity);
|
||||
$entity = $this->innerProcessor->process($entity, $operation, $uriVariables, $context);
|
||||
}
|
||||
|
||||
return $this->autoMapper->map($entity, CheckoutApiResource::class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user