app/Customize/Plugin/AmazonPayV2/AmazonPayEvent.php line 162

Open in your IDE?
  1. <?php
  2. /*   __________________________________________________
  3.     |  Obfuscated by YAK Pro - Php Obfuscator  2.0.3   |
  4.     |              on 2021-09-17 16:10:28              |
  5.     |    GitHub: https://github.com/pk-fr/yakpro-po    |
  6.     |__________________________________________________|
  7. */
  8. namespace Customize\Plugin\AmazonPayV2;
  9. use Eccube\Event\TemplateEvent;
  10. use Eccube\Event\EventArgs;
  11. use Eccube\Event\EccubeEvents;
  12. use Eccube\Common\EccubeConfig;
  13. use Eccube\Repository\PaymentRepository;
  14. use Eccube\Repository\PluginRepository;
  15. use Customize\Service\OrderHelper;
  16. use Customize\Service\CartService;
  17. use Plugin\AmazonPayV2\Repository\ConfigRepository;
  18. use Plugin\AmazonPayV2\Service\AmazonRequestService;
  19. use Plugin\AmazonPayV2\Service\Method\AmazonPay;
  20. use Plugin\AmazonPayV2\phpseclib\Crypt\Random;
  21. use Symfony\Component\DependencyInjection\ContainerInterface;
  22. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  23. use Symfony\Component\HttpFoundation\RequestStack;
  24. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  25. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. use Eccube\Repository\DeliveryRepository;
  28. use Eccube\Repository\PaymentOptionRepository;
  29. class AmazonPayEvent implements EventSubscriberInterface
  30. {
  31.     private $sessionAmazonProfileKey 'amazon_pay_v2.profile';
  32.     private $sessionAmazonCheckoutSessionIdKey 'amazon_pay_v2.checkout_session_id';
  33.     private $sessionAmazonLoginStateKey 'amazon_pay_v2.amazon_login_state';
  34.     protected $eccubeConfig;
  35.     private $router;
  36.     protected $configRepository;
  37.     protected $amazonRequestService;
  38.     protected $deliveryRepository;
  39.     protected $paymentOptionRepository;
  40.     public function __construct(RequestStack $requestStackSessionInterface $sessionTokenStorageInterface $tokenStorageEccubeConfig $eccubeConfigUrlGeneratorInterface $routerPaymentRepository $paymentRepositoryPluginRepository $pluginRepositoryConfigRepository $configRepositoryContainerInterface $containerOrderHelper $orderHelperCartService $cartServiceAmazonRequestService $amazonRequestServiceDeliveryRepository $deliveryRepositoryPaymentOptionRepository $paymentOptionRepository)
  41.     {
  42.         $this->requestStack $requestStack;
  43.         $this->session $session;
  44.         $this->tokenStorage $tokenStorage;
  45.         $this->eccubeConfig $eccubeConfig;
  46.         $this->router $router;
  47.         $this->paymentRepository $paymentRepository;
  48.         $this->pluginRepository $pluginRepository;
  49.         $this->configRepository $configRepository;
  50.         $this->container $container;
  51.         $this->orderHelper $orderHelper;
  52.         $this->cartService $cartService;
  53.         $this->amazonRequestService $amazonRequestService;
  54.         $this->deliveryRepository $deliveryRepository;
  55.         $this->paymentOptionRepository $paymentOptionRepository;
  56.     }
  57.     public static function getSubscribedEvents()
  58.     {
  59.         return [
  60.             EccubeEvents::FRONT_CART_BUYSTEP_COMPLETE => 'amazon_cart_buystep',
  61.             'Cart/index.twig' => 'cart',
  62.             'Shopping/index.twig' => 'amazon_pay_shopping',
  63.             'Mypage/login.twig' => 'mypage_login',
  64.             'Shopping/confirm.twig' => 'amazon_pay_shopping_confirm'
  65.         ];
  66.     }
  67.     public function cart(TemplateEvent $event)
  68.     {
  69.         return $this->initAmazonPay($event);
  70.     }
  71.     public function amazon_cart_buystep(EventArgs $event)
  72.     {
  73.         if (!($this->orderHelper->getNonmember() && $this->session->get($this->sessionAmazonProfileKey))) {
  74.             goto m3bML;
  75.         }
  76.         $this->session->remove(OrderHelper::SESSION_NON_MEMBER);
  77.         $this->session->remove($this->sessionAmazonProfileKey);
  78.         $this->cartService->setPreOrderId(null);
  79.         $this->cartService->save();
  80.         m3bML:
  81.     }
  82.     public function amazon_pay_shopping(TemplateEvent $event)
  83.     {
  84.         $this->initAmazonPay($event);
  85.         $request $this->requestStack->getMasterRequest();
  86.         $uri $request->getUri();
  87.         $parameters $event->getParameters();
  88.         if (!(preg_match('/shopping\\/amazon_pay/'$uri) == false)) {
  89.             $Config $this->configRepository->get();
  90.             $event->addSnippet('@AmazonPayV2/default/Shopping/widgets.twig');
  91.             $event->addSnippet('@AmazonPayV2/default/Shopping/customer_regist_v2.twig');
  92.             $amazonCheckoutSessionId $this->session->get($this->sessionAmazonCheckoutSessionIdKey);
  93.             $parameters $event->getParameters();
  94.             $parameters['amazonCheckoutSessionId'] = $amazonCheckoutSessionId;
  95.             $parameters['AmazonPayV2Config'] = $Config;
  96.             if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4''enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4''enabled' => true])) {
  97.                 $useMailMagazine true;
  98.                 goto tm34k;
  99.             }
  100.             $useMailMagazine false;
  101.             tm34k:
  102.             $parameters['useMailMagazine'] = $useMailMagazine;
  103.             if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  104.                 $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  105.                 goto A6AZM;
  106.             }
  107.             $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  108.             A6AZM:
  109.             $event->setParameters($parameters);
  110.             // [PHPDeobfuscator] Implied return
  111.             return;
  112.         }
  113.         $referer $request->headers->get('referer');
  114.         $Order $parameters['Order'];
  115.         $Payment $Order->getPayment();
  116.         if (!($Payment && $Payment->getMethodClass() === AmazonPay::class && preg_match('/shopping_coupon/'$referer))) {
  117.             return;
  118.         }
  119.         header("Location:" $this->container->get('router')->generate('amazon_pay_shopping'));
  120.         exit;
  121.     }
  122.     public function amazon_pay_shopping_confirm(TemplateEvent $event)
  123.     {
  124.         $request $this->requestStack->getMasterRequest();
  125.         $uri $request->getUri();
  126.         if (!(preg_match('/shopping\\/amazon_pay/'$uri) == false)) {
  127.             $Config $this->configRepository->get();
  128.             $event->addSnippet('@AmazonPayV2/default/Shopping/confirm_widgets.twig');
  129.             $event->addSnippet('@AmazonPayV2/default/Shopping/confirm_customer_regist_v2.twig');
  130.             $parameters $event->getParameters();
  131.             $parameters['AmazonPayV2Config'] = $Config;
  132.             if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4''enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4''enabled' => true])) {
  133.                 $useMailMagazine true;
  134.                 goto wn79J;
  135.             }
  136.             $useMailMagazine false;
  137.             wn79J:
  138.             $parameters['useMailMagazine'] = $useMailMagazine;
  139.             if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  140.                 $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  141.                 goto IXbCJ;
  142.             }
  143.             $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  144.             IXbCJ:
  145.             $event->setParameters($parameters);
  146.             // [PHPDeobfuscator] Implied return
  147.             return;
  148.         }
  149.         return;
  150.     }
  151.     public function mypage_login(TemplateEvent $event)
  152.     {
  153.         $Config $this->configRepository->get();
  154.         if (!($Config->getUseMypageLoginButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
  155.             $state $this->session->get($this->sessionAmazonLoginStateKey);
  156.             if ($state) {
  157.                 goto RepgZ;
  158.             }
  159.             $state bin2hex(Random::string(16));
  160.             $this->session->set($this->sessionAmazonLoginStateKey$state);
  161.             RepgZ:
  162.             $returnUrl $this->router->generate('login_with_amazon', ['state' => $state], UrlGeneratorInterface::ABSOLUTE_URL);
  163.             $parameters $event->getParameters();
  164.             $payload $this->amazonRequestService->createSigninPayload($returnUrl);
  165.             $signature $this->amazonRequestService->signaturePayload($payload);
  166.             $parameters['payload'] = $payload;
  167.             $parameters['signature'] = $signature;
  168.             $parameters['buttonColor'] = $Config->getMypageLoginButtonColor();
  169.             $parameters['AmazonPayV2Config'] = $Config;
  170.             if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  171.                 $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  172.                 goto JGY10;
  173.             }
  174.             $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  175.             JGY10:
  176.             $event->setParameters($parameters);
  177.             if (!($Config->getMypageLoginButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
  178.                 goto FaeWr;
  179.             }
  180.             $event->addSnippet('@AmazonPayV2/default/Mypage/login_page_button.twig');
  181.             FaeWr:
  182.             $event->addSnippet('@AmazonPayV2/default/Mypage/amazon_login_js.twig');
  183.             // [PHPDeobfuscator] Implied return
  184.             return;
  185.         }
  186.         return;
  187.     }
  188.     private function initAmazonPay($event)
  189.     {
  190.         $parameters $event->getParameters();
  191.         if (!empty($parameters['Carts'])) {
  192.             $Config $this->configRepository->get();
  193.             if (!($Config->getUseCartButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
  194.                 $Payment $this->paymentRepository->findOneBy(['method_class' => AmazonPay::class]);
  195.                 $AmazonDeliveries $this->paymentOptionRepository->findBy(['payment_id' => $Payment->getId()]);
  196.                 $AmazonSaleTypes = [];
  197.                 foreach ($AmazonDeliveries as $AmazonDelivery) {
  198.                     $Delivery $this->deliveryRepository->findOneBy(['id' => $AmazonDelivery->getDelivery()->getId()]);
  199.                     $AmazonSaleTypes[] = $Delivery->getSaleType()->getId();
  200.                 }
  201.                 $parameters['AmazonSaleTypes'] = $AmazonSaleTypes;
  202.                 foreach ($parameters['Carts'] as $Cart) {
  203.                     $cartKey $Cart->getCartKey();
  204.                     $payload $this->amazonRequestService->createCheckoutSessionPayload($Cart->getCartKey());
  205.                     $signature $this->amazonRequestService->signaturePayload($payload);
  206.                     $parameters['cart'][$cartKey]['payload'] = $payload;
  207.                     $parameters['cart'][$cartKey]['signature'] = $signature;
  208.                 }
  209.                 $parameters['AmazonPayV2Config'] = $Config;
  210.                 if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  211.                     $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  212.                     goto HSbyT;
  213.                 }
  214.                 $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  215.                 HSbyT:
  216.                 $event->setParameters($parameters);
  217.                 $event->addSnippet('@AmazonPayV2/default/Cart/amazon_pay_js.twig');
  218.                 if (!($Config->getCartButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
  219.                     goto koxCA;
  220.                 }
  221.                 $event->addSnippet('@AmazonPayV2/default/Cart/button.twig');
  222.                 koxCA:
  223.                 // [PHPDeobfuscator] Implied return
  224.                 return;
  225.             }
  226.             return;
  227.         }
  228.     }
  229. }