app/Plugin/AmazonPayV2/AmazonPayEvent.php line 553

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 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 Eccube\Service\OrderHelper;
  16. use Eccube\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.         goto aVoZ4;
  43.         hmafY:
  44.         $this->amazonRequestService $amazonRequestService;
  45.         goto qGpsx;
  46.         roPbp:
  47.         $this->eccubeConfig $eccubeConfig;
  48.         goto nKZ7S;
  49.         SQPlW:
  50.         $this->container $container;
  51.         goto WxAU0;
  52.         VKgeO:
  53.         $this->paymentRepository $paymentRepository;
  54.         goto HRaQz;
  55.         WxAU0:
  56.         $this->orderHelper $orderHelper;
  57.         goto aiXmP;
  58.         aiXmP:
  59.         $this->cartService $cartService;
  60.         goto hmafY;
  61.         sLLW4:
  62.         $this->session $session;
  63.         goto hYte7;
  64.         pqIVu:
  65.         $this->paymentOptionRepository $paymentOptionRepository;
  66.         goto k8smY;
  67.         VLD8C:
  68.         $this->configRepository $configRepository;
  69.         goto SQPlW;
  70.         hYte7:
  71.         $this->tokenStorage $tokenStorage;
  72.         goto roPbp;
  73.         aVoZ4:
  74.         $this->requestStack $requestStack;
  75.         goto sLLW4;
  76.         qGpsx:
  77.         $this->deliveryRepository $deliveryRepository;
  78.         goto pqIVu;
  79.         HRaQz:
  80.         $this->pluginRepository $pluginRepository;
  81.         goto VLD8C;
  82.         nKZ7S:
  83.         $this->router $router;
  84.         goto VKgeO;
  85.         k8smY:
  86.     }
  87.     public static function getSubscribedEvents()
  88.     {
  89.         return [
  90.             EccubeEvents::FRONT_CART_BUYSTEP_COMPLETE => 'amazon_cart_buystep'
  91.             'Cart/index.twig' => 'cart'
  92.             'Shopping/amz_index.twig' => 'amazon_pay_shopping'
  93.             // 'Mypage/login.twig' => 'mypage_login', 
  94.             'Shopping/amz_confirm.twig' => 'amazon_pay_shopping_confirm'
  95.             'LandingPage/index.twig' => 'lp_amazon_login'
  96.         ];
  97.     }
  98.     public function cart(TemplateEvent $event)
  99.     {
  100.         goto oHfyb;
  101.         f4S9l:
  102.         return;
  103.         goto MGINf;
  104.         kmRPH:
  105.         if (!($Config->getUseCartButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
  106.             goto RGUKj;
  107.         }
  108.         goto f4S9l;
  109.         Zgged:
  110.         BUV21:
  111.         goto j92EP;
  112.         c3v82:
  113.         goto n6C_z;
  114.         goto SwFTt;
  115.         yG2CA:
  116.         foreach ($parameters['Carts'] as $Cart) {
  117.             goto bFs97;
  118.             qXqv9:
  119.             $signature $this->amazonRequestService->signaturePayload($payload);
  120.             goto K50mn;
  121.             nOelm:
  122.             wuOVV:
  123.             goto V9Rt1;
  124.             bFs97:
  125.             $cartKey $Cart->getCartKey();
  126.             goto NA6lH;
  127.             C5JCl:
  128.             $parameters['cart'][$cartKey]['signature'] = $signature;
  129.             goto nOelm;
  130.             K50mn:
  131.             $parameters['cart'][$cartKey]['payload'] = $payload;
  132.             goto C5JCl;
  133.             NA6lH:
  134.             $payload $this->amazonRequestService->createCheckoutSessionPayload($Cart->getCartKey());
  135.             goto qXqv9;
  136.             V9Rt1:
  137.         }
  138.         goto MrTmV;
  139.         HmXUF:
  140.         $AmazonSaleTypes = [];
  141.         goto QWNDI;
  142.         AMMqf:
  143.         $event->setParameters($parameters);
  144.         goto mY_Dt;
  145.         j92EP:
  146.         $Config $this->configRepository->get();
  147.         goto kmRPH;
  148.         SwFTt:
  149.         igeDA:
  150.         goto Mmxol;
  151.         HSbyT:
  152.         n6C_z:
  153.         goto AMMqf;
  154.         rutP5:
  155.         $event->addSnippet('@AmazonPayV2/default/Cart/button.twig');
  156.         goto nKr0E;
  157.         OZYak:
  158.         $parameters['AmazonPayV2Config'] = $Config;
  159.         goto Sq8AH;
  160.         Sfdza:
  161.         $Payment $this->paymentRepository->findOneBy(['method_class' => AmazonPay::class]);
  162.         goto yB4uQ;
  163.         Sq8AH:
  164.         if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  165.             goto igeDA;
  166.         }
  167.         goto lzlWd;
  168.         MGINf:
  169.         RGUKj:
  170.         goto Sfdza;
  171.         lzlWd:
  172.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  173.         goto c3v82;
  174.         JD855:
  175.         if (!($Config->getCartButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
  176.             goto koxCA;
  177.         }
  178.         goto rutP5;
  179.         MrTmV:
  180.         H_6pS:
  181.         goto OZYak;
  182.         nKr0E:
  183.         koxCA:
  184.         goto tzB4D;
  185.         mY_Dt:
  186.         $event->addSnippet('@AmazonPayV2/default/Cart/amazon_pay_js.twig');
  187.         goto JD855;
  188.         U1u0T:
  189.         return;
  190.         goto Zgged;
  191.         oHfyb:
  192.         $parameters $event->getParameters();
  193.         goto cLVu6;
  194.         ppGFB:
  195.         pOcXa:
  196.         goto gLoLj;
  197.         cLVu6:
  198.         if (!empty($parameters['Carts'])) {
  199.             goto BUV21;
  200.         }
  201.         goto U1u0T;
  202.         yB4uQ:
  203.         $AmazonDeliveries $this->paymentOptionRepository->findBy(['payment_id' => $Payment->getId()]);
  204.         goto HmXUF;
  205.         Mmxol:
  206.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  207.         goto HSbyT;
  208.         gLoLj:
  209.         $parameters['AmazonSaleTypes'] = $AmazonSaleTypes;
  210.         goto yG2CA;
  211.         QWNDI:
  212.         foreach ($AmazonDeliveries as $AmazonDelivery) {
  213.             goto JXvCt;
  214.             FX_In:
  215.             xa8Rr:
  216.             goto ARRQg;
  217.             JXvCt:
  218.             $Delivery $this->deliveryRepository->findOneBy(['id' => $AmazonDelivery->getDelivery()->getId()]);
  219.             goto GTwJU;
  220.             GTwJU:
  221.             $AmazonSaleTypes[] = $Delivery->getSaleType()->getId();
  222.             goto FX_In;
  223.             ARRQg:
  224.         }
  225.         goto ppGFB;
  226.         tzB4D:
  227.     }
  228.     public function amazon_cart_buystep(EventArgs $event)
  229.     {
  230.         goto PlrsM;
  231.         Yq8pk:
  232.         $this->cartService->setPreOrderId(null);
  233.         goto HFF8t;
  234.         trH7S:
  235.         m3bML:
  236.         goto Dti8n;
  237.         f6UKN:
  238.         $this->session->remove($this->sessionAmazonProfileKey);
  239.         goto Yq8pk;
  240.         HFF8t:
  241.         $this->cartService->save();
  242.         goto trH7S;
  243.         PlrsM:
  244.         if (!($this->orderHelper->getNonmember() && $this->session->get($this->sessionAmazonProfileKey))) {
  245.             goto m3bML;
  246.         }
  247.         goto MkSv4;
  248.         MkSv4:
  249.         $this->session->remove(OrderHelper::SESSION_NON_MEMBER);
  250.         goto f6UKN;
  251.         Dti8n:
  252.     }
  253.     public function amazon_pay_shopping(TemplateEvent $event)
  254.     {
  255.         goto oYvK6;
  256.         W2hdE:
  257.         exit;
  258.         goto CyOIF;
  259.         Pndg9:
  260.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  261.         goto A6AZM;
  262.         C1inr:
  263.         $parameters['useMailMagazine'] = $useMailMagazine;
  264.         goto JE4_8;
  265.         fEE4R:
  266.         $event->addSnippet('@AmazonPayV2/default/Shopping/widgets.twig');
  267.         goto d5P2v;
  268.         sPhn2:
  269.         if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4''enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4''enabled' => true])) {
  270.             goto cTDPC;
  271.         }
  272.         goto OdOe9;
  273.         fOiBV:
  274.         $parameters['AmazonPayV2Config'] = $Config;
  275.         goto sPhn2;
  276.         CyOIF:
  277.         ebgpY:
  278.         goto Hejjy;
  279.         vYeJa:
  280.         goto yFk83;
  281.         goto GJqZ7;
  282.         GJqZ7:
  283.         cTDPC:
  284.         goto Rxknz;
  285.         OdOe9:
  286.         $useMailMagazine false;
  287.         goto vYeJa;
  288.         JE4_8:
  289.         if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  290.             goto eU5dp;
  291.         }
  292.         goto aQ0VV;
  293.         AM9ez:
  294.         goto J8r8P;
  295.         goto miotL;
  296.         Iz036:
  297.         $parameters $event->getParameters();
  298.         goto v7CCd;
  299.         Rxknz:
  300.         $useMailMagazine true;
  301.         goto tm34k;
  302.         jVZli:
  303.         X5DOk:
  304.         goto ysqHh;
  305.         v7CCd:
  306.         $parameters['amazonCheckoutSessionId'] = $amazonCheckoutSessionId;
  307.         goto fOiBV;
  308.         ysqHh:
  309.         $Config $this->configRepository->get();
  310.         goto fEE4R;
  311.         Hejjy:
  312.         return;
  313.         goto jVZli;
  314.         DYYIw:
  315.         $parameters $event->getParameters();
  316.         goto jGwvD;
  317.         cm7PT:
  318.         $Order $parameters['Order'];
  319.         goto AhkWS;
  320.         miotL:
  321.         eU5dp:
  322.         goto Pndg9;
  323.         MU1mx:
  324.         $referer $request->headers->get('referer');
  325.         goto cm7PT;
  326.         d5P2v:
  327.         $event->addSnippet('@AmazonPayV2/default/Shopping/customer_regist_v2.twig');
  328.         goto LxFxK;
  329.         tm34k:
  330.         yFk83:
  331.         goto C1inr;
  332.         A6AZM:
  333.         J8r8P:
  334.         goto LqlkU;
  335.         aQ0VV:
  336.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  337.         goto AM9ez;
  338.         oYvK6:
  339.         $request $this->requestStack->getMasterRequest();
  340.         goto OoZ9Z;
  341.         AhkWS:
  342.         $Payment $Order->getPayment();
  343.         goto lELcs;
  344.         LxFxK:
  345.         $amazonCheckoutSessionId $this->session->get($this->sessionAmazonCheckoutSessionIdKey);
  346.         goto Iz036;
  347.         lELcs:
  348.         if (!($Payment && $Payment->getMethodClass() === AmazonPay::class && preg_match('/shopping_coupon/'$referer))) {
  349.             goto ebgpY;
  350.         }
  351.         goto hQLcd;
  352.         OoZ9Z:
  353.         $uri $request->getUri();
  354.         goto DYYIw;
  355.         jGwvD:
  356.         if (!(preg_match('/shopping\\/amazon_pay/'$uri) == false)) {
  357.             goto X5DOk;
  358.         }
  359.         goto MU1mx;
  360.         LqlkU:
  361.         $event->setParameters($parameters);
  362.         goto sY5v2;
  363.         hQLcd:
  364.         header("Location:" $this->container->get('router')->generate('amazon_pay_shopping'));
  365.         goto W2hdE;
  366.         sY5v2:
  367.     }
  368.     public function amazon_pay_shopping_confirm(TemplateEvent $event)
  369.     {
  370.         goto fpDxz;
  371.         GmkSt:
  372.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  373.         goto IXbCJ;
  374.         wn79J:
  375.         nlxOx:
  376.         goto DQFft;
  377.         Ar0TF:
  378.         $useMailMagazine false;
  379.         goto bPh2u;
  380.         h44fK:
  381.         $useMailMagazine true;
  382.         goto wn79J;
  383.         pZbV2:
  384.         if (!(preg_match('/shopping\\/amazon_pay/'$uri) == false)) {
  385.             goto tKvHv;
  386.         }
  387.         goto a8m0b;
  388.         AR2AE:
  389.         if ($this->pluginRepository->findOneBy(['code' => 'MailMagazine4''enabled' => true]) || $this->pluginRepository->findOneBy(['code' => 'PostCarrier4''enabled' => true])) {
  390.             goto UqmZa;
  391.         }
  392.         goto Ar0TF;
  393.         fpDxz:
  394.         $request $this->requestStack->getMasterRequest();
  395.         goto dZqB4;
  396.         IXbCJ:
  397.         H_2UE:
  398.         goto jS74I;
  399.         a8m0b:
  400.         return;
  401.         goto UVDaL;
  402.         HJ561:
  403.         goto H_2UE;
  404.         goto ZDsny;
  405.         jS74I:
  406.         $event->setParameters($parameters);
  407.         goto zqfdT;
  408.         iWixA:
  409.         $event->addSnippet('@AmazonPayV2/default/Shopping/confirm_customer_regist_v2.twig');
  410.         goto gQJEG;
  411.         ZDsny:
  412.         yrSPZ:
  413.         goto GmkSt;
  414.         qWT9X:
  415.         $event->addSnippet('@AmazonPayV2/default/Shopping/confirm_widgets.twig');
  416.         goto iWixA;
  417.         gQJEG:
  418.         $parameters $event->getParameters();
  419.         goto FWwKq;
  420.         UVDaL:
  421.         tKvHv:
  422.         goto jSXkH;
  423.         FWwKq:
  424.         $parameters['AmazonPayV2Config'] = $Config;
  425.         goto AR2AE;
  426.         jSXkH:
  427.         $Config $this->configRepository->get();
  428.         goto qWT9X;
  429.         kLxYX:
  430.         if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  431.             goto yrSPZ;
  432.         }
  433.         goto v49eQ;
  434.         o92pp:
  435.         UqmZa:
  436.         goto h44fK;
  437.         bPh2u:
  438.         goto nlxOx;
  439.         goto o92pp;
  440.         DQFft:
  441.         $parameters['useMailMagazine'] = $useMailMagazine;
  442.         goto kLxYX;
  443.         v49eQ:
  444.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  445.         goto HJ561;
  446.         dZqB4:
  447.         $uri $request->getUri();
  448.         goto pZbV2;
  449.         zqfdT:
  450.     }
  451.     public function mypage_login(TemplateEvent $event)
  452.     {
  453.         // dump(123);die;
  454.         goto L7ja5;
  455.         nkKV8:
  456.         return;
  457.         goto NOGAg;
  458.         L7ja5:
  459.         $Config $this->configRepository->get();
  460.         goto RV3v6;
  461.         e9oUD:
  462.         if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  463.             goto REKAO;
  464.         }
  465.         goto OLu4n;
  466.         NOGAg:
  467.         jND4F:
  468.         goto VkPBA;
  469.         fuKL0:
  470.         $this->session->set($this->sessionAmazonLoginStateKey$state);
  471.         goto qEOvQ;
  472.         Cycer:
  473.         $payload $this->amazonRequestService->createSigninPayload($returnUrl);
  474.         goto b9GsZ;
  475.         LNTbW:
  476.         $returnUrl $this->router->generate('login_with_amazon', ['state' => $state], UrlGeneratorInterface::ABSOLUTE_URL);
  477.         goto ClV9B;
  478.         RV3v6:
  479.         if (!($Config->getUseMypageLoginButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off'])) {
  480.             goto jND4F;
  481.         }
  482.         goto nkKV8;
  483.         B59MK:
  484.         $event->addSnippet('@AmazonPayV2/default/Mypage/amazon_login_js.twig');
  485.         goto IDPg5;
  486.         VkPBA:
  487.         $state $this->session->get($this->sessionAmazonLoginStateKey);
  488.         goto HHk2h;
  489.         XoeoE:
  490.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  491.         goto JGY10;
  492.         Cp_BX:
  493.         $parameters['payload'] = $payload;
  494.         goto Dz1t1;
  495.         C0xtI:
  496.         goto vwt6_;
  497.         goto tWgTU;
  498.         ClV9B:
  499.         $parameters $event->getParameters();
  500.         goto Cycer;
  501.         HHk2h:
  502.         if ($state) {
  503.             goto RepgZ;
  504.         }
  505.         goto tZCZi;
  506.         OLu4n:
  507.         $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  508.         goto C0xtI;
  509.         yXIPD:
  510.         if (!($Config->getMypageLoginButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto'])) {
  511.             goto FaeWr;
  512.         }
  513.         goto XgZza;
  514.         HPcyD:
  515.         $parameters['AmazonPayV2Config'] = $Config;
  516.         goto e9oUD;
  517.         b9GsZ:
  518.         $signature $this->amazonRequestService->signaturePayload($payload);
  519.         goto Cp_BX;
  520.         tZCZi:
  521.         $state bin2hex(Random::string(16));
  522.         goto fuKL0;
  523.         qEOvQ:
  524.         RepgZ:
  525.         goto LNTbW;
  526.         rIokg:
  527.         $event->setParameters($parameters);
  528.         goto yXIPD;
  529.         XgZza:
  530.         $event->addSnippet('@AmazonPayV2/default/Mypage/login_page_button.twig');
  531.         goto oismC;
  532.         JGY10:
  533.         vwt6_:
  534.         goto rIokg;
  535.         tWgTU:
  536.         REKAO:
  537.         goto XoeoE;
  538.         MYaqt:
  539.         $parameters['buttonColor'] = $Config->getMypageLoginButtonColor();
  540.         goto HPcyD;
  541.         oismC:
  542.         FaeWr:
  543.         goto B59MK;
  544.         Dz1t1:
  545.         $parameters['signature'] = $signature;
  546.         goto MYaqt;
  547.         IDPg5:
  548.     }
  549.     public function lp_amazon_login(TemplateEvent $event)
  550.     {
  551.         $Config $this->configRepository->get();
  552.         if ($Config->getUseMypageLoginButton() == $this->eccubeConfig['amazon_pay_v2']['toggle']['off']) {
  553.             return;
  554.         }
  555.         $state $this->session->get($this->sessionAmazonLoginStateKey);
  556.         if (!$state) {
  557.             $state bin2hex(Random::string(16));
  558.             $this->session->set($this->sessionAmazonLoginStateKey$state);
  559.         }
  560.         $returnUrl $this->router->generate('login_with_amazon', ['state' => $state'isLp' => 1], UrlGeneratorInterface::ABSOLUTE_URL);
  561.         $parameters $event->getParameters();
  562.         $payload $this->amazonRequestService->createSigninPayload($returnUrl);
  563.         $signature $this->amazonRequestService->signaturePayload($payload);
  564.         $parameters['payload'] = $payload;
  565.         $parameters['signature'] = $signature;
  566.         $parameters['buttonColor'] = $Config->getMypageLoginButtonColor();
  567.         $parameters['AmazonPayV2Config'] = $Config;
  568.         if ($Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
  569.             $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
  570.         } else {
  571.             $parameters['AmazonPayV2Api'] = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
  572.         }
  573.         $event->setParameters($parameters);
  574.         if ($Config->getMypageLoginButtonPlace() == $this->eccubeConfig['amazon_pay_v2']['button_place']['auto']) {
  575.             $event->addSnippet('LandingPage/login_lp_amazon_button.twig');
  576.         }
  577.         $event->addSnippet('LandingPage/lp_amazon_login_js.twig');
  578.     }
  579. }