<?php
/* __________________________________________________
| Obfuscated by YAK Pro - Php Obfuscator 2.0.3 |
| on 2021-09-17 16:10:28 |
| GitHub: https://github.com/pk-fr/yakpro-po |
|__________________________________________________|
*/
namespace Customize\Plugin\AmazonPayV2;
use Eccube\Event\TemplateEvent;
use Eccube\Event\EventArgs;
use Eccube\Event\EccubeEvents;
use Eccube\Common\EccubeConfig;
use Eccube\Repository\PaymentRepository;
use Eccube\Repository\PluginRepository;
use Customize\Service\OrderHelper;
use Customize\Service\CartService;
use Plugin\AmazonPayV2\Repository\ConfigRepository;
use Plugin\AmazonPayV2\Service\AmazonRequestService;
use Plugin\AmazonPayV2\Service\Method\AmazonPay;
use Plugin\AmazonPayV2\phpseclib\Crypt\Random;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Eccube\Repository\DeliveryRepository;
use Eccube\Repository\PaymentOptionRepository;
class AmazonPayEvent implements EventSubscriberInterface
{
private $sessionAmazonProfileKey = 'amazon_pay_v2.profile';
private $sessionAmazonCheckoutSessionIdKey = 'amazon_pay_v2.checkout_session_id';
private $sessionAmazonLoginStateKey = 'amazon_pay_v2.amazon_login_state';
protected $eccubeConfig;
private $router;
protected $configRepository;
protected $amazonRequestService;
protected $deliveryRepository;
protected $paymentOptionRepository;
public function __construct(RequestStack $requestStack, SessionInterface $session, TokenStorageInterface $tokenStorage, EccubeConfig $eccubeConfig, UrlGeneratorInterface $router, PaymentRepository $paymentRepository, PluginRepository $pluginRepository, ConfigRepository $configRepository, ContainerInterface $container, OrderHelper $orderHelper, CartService $cartService, AmazonRequestService $amazonRequestService, DeliveryRepository $deliveryRepository, PaymentOptionRepository $paymentOptionRepository)
{
$this->requestStack = $requestStack;
$this->session = $session;
$this->tokenStorage = $tokenStorage;
$this->eccubeConfig = $eccubeConfig;
$this->router = $router;
$this->paymentRepository = $paymentRepository;
$this->pluginRepository = $pluginRepository;
$this->configRepository = $configRepository;
$this->container = $container;
$this->orderHelper = $orderHelper;
$this->cartService = $cartService;
$this->amazonRequestService = $amazonRequestService;
$this->deliveryRepository = $deliveryRepository;
$this->paymentOptionRepository = $paymentOptionRepository;
}
public static function getSubscribedEvents()
{
return [
EccubeEvents::FRONT_CART_BUYSTEP_COMPLETE => 'amazon_cart_buystep',
'Cart/index.twig' => 'cart',
'Shopping/index.twig' => 'amazon_pay_shopping',
'Mypage/login.twig' => 'mypage_login',
'Shopping/confirm.twig' => 'amazon_pay_shopping_confirm'
];
}
public function cart(TemplateEvent $event)
{
return $this->initAmazonPay($event);
}
public function amazon_cart_buystep(EventArgs $event)
{
if (!($this->orderHelper->getNonmember() && $this->session->get($this->sessionAmazonProfileKey))) {
goto m3bML;
}
$this->session->remove(OrderHelper::SESSION_NON_MEMBER);
$this->session->remove($this->sessionAmazonProfileKey);
$this->cartService->setPreOrderId(null);
$this->cartService->save();
m3bML:
}
public function amazon_pay_shopping(TemplateEvent $event)
{
$this->initAmazonPay($event);
$request = $this->requestStack->getMasterRequest();
$uri = $request->getUri();
$parameters = $event->getParameters();
if (!(preg_match('/shopping\\/amazon_pay/', $uri) == false)) {
$Config = $this->configRepository->get();
$event->addSnippet('@AmazonPayV2/default/Shopping/widgets.twig');
$event->addSnippet('@AmazonPayV2/default/Shopping/customer_regist_v2.twig');
$amazonCheckoutSessionId = $this->session->get($this->sessionAmazonCheckoutSessionIdKey);
$parameters = $event->getParameters();
$parameters['amazonCheckoutSessionId'] = $amazonCheckoutSessionId;
$parameters['AmazonPayV2Config'] = $Config;
if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4', 'enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4', 'enabled' => true])) {
$useMailMagazine = true;
goto tm34k;
}
$useMailMagazine = false;
tm34k:
$parameters['useMailMagazine'] = $useMailMagazine;
if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
goto A6AZM;
}
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
A6AZM:
$event->setParameters($parameters);
// [PHPDeobfuscator] Implied return
return;
}
$referer = $request->headers->get('referer');
$Order = $parameters['Order'];
$Payment = $Order->getPayment();
if (!($Payment && $Payment->getMethodClass() === AmazonPay::class && preg_match('/shopping_coupon/', $referer))) {
return;
}
header("Location:" . $this->container->get('router')->generate('amazon_pay_shopping'));
exit;
}
public function amazon_pay_shopping_confirm(TemplateEvent $event)
{
$request = $this->requestStack->getMasterRequest();
$uri = $request->getUri();
if (!(preg_match('/shopping\\/amazon_pay/', $uri) == false)) {
$Config = $this->configRepository->get();
$event->addSnippet('@AmazonPayV2/default/Shopping/confirm_widgets.twig');
$event->addSnippet('@AmazonPayV2/default/Shopping/confirm_customer_regist_v2.twig');
$parameters = $event->getParameters();
$parameters['AmazonPayV2Config'] = $Config;
if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4', 'enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4', 'enabled' => true])) {
$useMailMagazine = true;
goto wn79J;
}
$useMailMagazine = false;
wn79J:
$parameters['useMailMagazine'] = $useMailMagazine;
if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
goto IXbCJ;
}
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
IXbCJ:
$event->setParameters($parameters);
// [PHPDeobfuscator] Implied return
return;
}
return;
}
public function mypage_login(TemplateEvent $event)
{
$Config = $this->configRepository->get();
if (!($Config->getUseMypageLoginButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
$state = $this->session->get($this->sessionAmazonLoginStateKey);
if ($state) {
goto RepgZ;
}
$state = bin2hex(Random::string(16));
$this->session->set($this->sessionAmazonLoginStateKey, $state);
RepgZ:
$returnUrl = $this->router->generate('login_with_amazon', ['state' => $state], UrlGeneratorInterface::ABSOLUTE_URL);
$parameters = $event->getParameters();
$payload = $this->amazonRequestService->createSigninPayload($returnUrl);
$signature = $this->amazonRequestService->signaturePayload($payload);
$parameters['payload'] = $payload;
$parameters['signature'] = $signature;
$parameters['buttonColor'] = $Config->getMypageLoginButtonColor();
$parameters['AmazonPayV2Config'] = $Config;
if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
goto JGY10;
}
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
JGY10:
$event->setParameters($parameters);
if (!($Config->getMypageLoginButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
goto FaeWr;
}
$event->addSnippet('@AmazonPayV2/default/Mypage/login_page_button.twig');
FaeWr:
$event->addSnippet('@AmazonPayV2/default/Mypage/amazon_login_js.twig');
// [PHPDeobfuscator] Implied return
return;
}
return;
}
private function initAmazonPay($event)
{
$parameters = $event->getParameters();
if (!empty($parameters['Carts'])) {
$Config = $this->configRepository->get();
if (!($Config->getUseCartButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
$Payment = $this->paymentRepository->findOneBy(['method_class' => AmazonPay::class]);
$AmazonDeliveries = $this->paymentOptionRepository->findBy(['payment_id' => $Payment->getId()]);
$AmazonSaleTypes = [];
foreach ($AmazonDeliveries as $AmazonDelivery) {
$Delivery = $this->deliveryRepository->findOneBy(['id' => $AmazonDelivery->getDelivery()->getId()]);
$AmazonSaleTypes[] = $Delivery->getSaleType()->getId();
}
$parameters['AmazonSaleTypes'] = $AmazonSaleTypes;
foreach ($parameters['Carts'] as $Cart) {
$cartKey = $Cart->getCartKey();
$payload = $this->amazonRequestService->createCheckoutSessionPayload($Cart->getCartKey());
$signature = $this->amazonRequestService->signaturePayload($payload);
$parameters['cart'][$cartKey]['payload'] = $payload;
$parameters['cart'][$cartKey]['signature'] = $signature;
}
$parameters['AmazonPayV2Config'] = $Config;
if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
goto HSbyT;
}
$parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
HSbyT:
$event->setParameters($parameters);
$event->addSnippet('@AmazonPayV2/default/Cart/amazon_pay_js.twig');
if (!($Config->getCartButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
goto koxCA;
}
$event->addSnippet('@AmazonPayV2/default/Cart/button.twig');
koxCA:
// [PHPDeobfuscator] Implied return
return;
}
return;
}
}
}