-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cancel action to return from Pagolight and ensure the cancel of t…
…he payment
- Loading branch information
Showing
6 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; | ||
|
||
return static function (RoutingConfigurator $routes): void { | ||
$routes->import('@PayumBundle/Resources/config/routing/cancel.xml'); | ||
|
||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusPagolightPlugin\Payum\Action; | ||
|
||
use Payum\Core\Action\ActionInterface; | ||
use Payum\Core\Exception\RequestNotSupportedException; | ||
use Payum\Core\Request\Cancel; | ||
use Sylius\Component\Core\Model\PaymentInterface as SyliusPaymentInterface; | ||
use Webgriffe\SyliusPagolightPlugin\Client\PaymentState; | ||
use Webgriffe\SyliusPagolightPlugin\PaymentDetailsHelper; | ||
use Webmozart\Assert\Assert; | ||
|
||
/** | ||
* @psalm-type PaymentDetails array{contract_uuid: string, redirect_url: string, created_at: string, expire_at: string, status?: string} | ||
*/ | ||
final class CancelAction implements ActionInterface | ||
{ | ||
/** | ||
* @param Cancel|mixed $request | ||
*/ | ||
public function execute($request): void | ||
{ | ||
RequestNotSupportedException::assertSupports($this, $request); | ||
Assert::isInstanceOf($request, Cancel::class); | ||
|
||
$payment = $request->getModel(); | ||
Assert::isInstanceOf($payment, SyliusPaymentInterface::class); | ||
|
||
/** @var PaymentDetails $paymentDetails */ | ||
$paymentDetails = $payment->getDetails(); | ||
PaymentDetailsHelper::assertPaymentDetailsAreValid($paymentDetails); | ||
|
||
$paymentDetails = PaymentDetailsHelper::addPaymentStatus( | ||
$paymentDetails, | ||
PaymentState::CANCELLED, | ||
); | ||
$payment->setDetails($paymentDetails); | ||
} | ||
|
||
public function supports($request): bool | ||
{ | ||
return $request instanceof Cancel && | ||
$request->getModel() instanceof SyliusPaymentInterface | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
tests/Application/config/routes/webgriffe_sylius_pagolight_plugin.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
webgriffe_sylius_pagolight_plugin: | ||
resource: "@WebgriffeSyliusPagolightPlugin/config/shop_routing.php" |