-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from SzymonKostrubiec/op-283
OP-283 Add PayU error handling, updatede and run ECS
- Loading branch information
Showing
20 changed files
with
345 additions
and
60 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
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
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,68 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusPayUPlugin\EventListener; | ||
|
||
use BitBag\SyliusPayUPlugin\Exception\PayUResponseException; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\RequestStack; | ||
use Symfony\Component\HttpKernel\Event\ExceptionEvent; | ||
use Symfony\Component\Routing\RouterInterface; | ||
|
||
final class PayUResponseExceptionEventListener | ||
{ | ||
private RouterInterface $router; | ||
|
||
private RequestStack $requestStack; | ||
|
||
private LoggerInterface $logger; | ||
|
||
public function __construct( | ||
RouterInterface $router, | ||
RequestStack $requestStack, | ||
LoggerInterface $logger, | ||
) { | ||
$this->router = $router; | ||
$this->requestStack = $requestStack; | ||
$this->logger = $logger; | ||
} | ||
|
||
public function onPayuOpenException(ExceptionEvent $event) | ||
{ | ||
$exception = $event->getThrowable(); | ||
|
||
if ($exception instanceof PayUResponseException) { | ||
$message = PayUResponseException::getTranslationByMessage($exception->getMessage()); | ||
$order = $exception->getOrder(); | ||
|
||
$this->logError($exception); | ||
$this->requestStack->getSession()->getBag('flashes')->add('error', $message); | ||
|
||
$route = empty($order['tokenValue']) | ||
? $this->router->generate('sylius_shop_cart_summary') | ||
: $this->router->generate('sylius_shop_order_show', ['tokenValue' => $order['tokenValue']]); | ||
|
||
$response = new RedirectResponse($route); | ||
$event->setResponse($response); | ||
} | ||
} | ||
|
||
public function logError(\Exception $exception): void | ||
{ | ||
$message = sprintf( | ||
'%s %s', | ||
'[PayU] Error while placing order', | ||
$exception->getMessage(), | ||
); | ||
|
||
$this->logger->error($message); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file was created by developers working at BitBag | ||
* Do you need more information about us and what we do? Visit our https://bitbag.io website! | ||
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusPayUPlugin\Exception; | ||
|
||
use Exception; | ||
use Payum\Core\Exception\Http\HttpException; | ||
use Symfony\Component\HttpKernel\Event\ExceptionEvent; | ||
|
||
final class PayUResponseException extends Exception | ||
{ | ||
private array $order; | ||
|
||
public function __construct( | ||
string $message, | ||
int $code, | ||
?array $order = [], | ||
?Exception $previous = null, | ||
) { | ||
$this->order = $order; | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
public function getOrder(): array | ||
{ | ||
return $this->order; | ||
} | ||
|
||
public static function getTranslationByMessage(?string $message): string | ||
{ | ||
switch ($message) { | ||
case 'ERROR_INCONSISTENT_CURRENCIES': | ||
return 'bitbag.payu_plugin.payu_exception.currencies'; | ||
default: | ||
return 'bitbag.payu_plugin.payu_exception.default'; | ||
} | ||
} | ||
} |
Oops, something went wrong.