app/Plugin/SlnPayment42/SlnPaymentEvent.php line 584

Open in your IDE?
  1. <?php
  2. namespace Plugin\SlnPayment42;
  3. use Eccube\Common\Constant;
  4. use Eccube\Common\EccubeConfig;
  5. use Eccube\Repository\PaymentRepository;
  6. use Eccube\Repository\Master\OrderStatusRepository;
  7. use Eccube\Event\TemplateEvent;
  8. use Eccube\Event\EventArgs;
  9. use Eccube\Event\EccubeEvents;
  10. use Eccube\Entity\Customer;
  11. use Eccube\Entity\Master\CustomerStatus;
  12. use Eccube\Entity\Master\OrderStatus;
  13. use Eccube\Exception\ShoppingException;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\DependencyInjection\ContainerInterface;
  17. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  18. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  19. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpFoundation\RedirectResponse;
  22. use Symfony\Component\HttpFoundation\Session\Session;
  23. use Symfony\Component\DomCrawler\Crawler;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  26. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  27. use Plugin\SlnPayment42\Repository\MemCardIdRepository;
  28. use Plugin\SlnPayment42\Repository\OrderPaymentHistoryRepository;
  29. use Plugin\SlnPayment42\Repository\OrderPaymentStatusRepository;
  30. use Plugin\SlnPayment42\Repository\PluginConfigRepository;
  31. use Plugin\SlnPayment42\Service\Method\CreditCard;
  32. use Plugin\SlnPayment42\Service\Method\RegisteredCreditCard;
  33. use Plugin\SlnPayment42\Service\Method\MethodUtils;
  34. use Plugin\SlnPayment42\Service\SlnMailService;
  35. use Plugin\SlnPayment42\Service\BasicItem;
  36. use Plugin\SlnPayment42\Service\Util;
  37. use Plugin\SlnPayment42\Service\SlnAction\Cvs;
  38. use Plugin\SlnPayment42\Service\SlnAction\Credit;
  39. use Plugin\SlnPayment42\Exception\SlnShoppingException;
  40. use Plugin\SlnPayment42\Service\SlnAction\Mem;
  41. use Plugin\SlnPayment42\Repository\SlnAgreementRepository;
  42. class SlnPaymentEvent implements EventSubscriberInterface
  43. {
  44.     /**
  45.      * @var ContainerInterface
  46.      */
  47.     private $container;
  48.     
  49.     /**
  50.      * @var EntityManagerInterface
  51.      */
  52.     private $entityManager;
  53.     
  54.     /**
  55.      * @var AuthorizationCheckerInterface
  56.      */
  57.     protected $authorizationChecker;
  58.     /**
  59.      * @var EccubeConfig
  60.      */
  61.     private $eccubeConfig;
  62.     /**
  63.      * @var EventDispatcherInterface
  64.      */
  65.     private $eventDispatcher;
  66.     /**
  67.      * @var PaymentRepository
  68.      */
  69.     private $paymentRepository;
  70.     /**
  71.      * @var OrderStatusRepository
  72.      */
  73.     private $orderStatusRepository;
  74.     /**
  75.      * @var SlnMailService
  76.      */
  77.     private $mailService;
  78.     /**
  79.      * @var BasicItem
  80.      */
  81.     private $basicItem;
  82.     /**
  83.      * @var Util
  84.      */
  85.     private $util;
  86.     /**
  87.      * @var MemCardIdRepository
  88.      */
  89.     private $memCardIdRepository;
  90.     /**
  91.      * @var OrderPaymentHistoryRepository
  92.      */
  93.     private $orderPaymentHistoryRepository;
  94.     /**
  95.      * @var OrderPaymentStatusRepository
  96.      */
  97.     private $orderPaymentStatusRepository;
  98.     /**
  99.      * @var PluginConfigRepository
  100.      */
  101.     private $configRepository;
  102.     /**
  103.      * @var Mem
  104.      */
  105.     private $mem;
  106.     /**
  107.      * @var SlnAgreementRepository
  108.      */
  109.     private $SlnAgreementRepository;
  110.     public function __construct(
  111.         ContainerInterface $container,
  112.         EntityManagerInterface $entityManager,
  113.         AuthorizationCheckerInterface $authorizationChecker,
  114.         EccubeConfig $eccubeConfig,
  115.         EventDispatcherInterface $eventDispatcher,
  116.         PaymentRepository $paymentRepository,
  117.         OrderStatusRepository $orderStatusRepository,
  118.         SlnMailService $mailService,
  119.         BasicItem $basicItem,
  120.         Util $util,
  121.         MemCardIdRepository $memCardIdRepository,
  122.         OrderPaymentStatusRepository $orderPaymentStatusRepository,
  123.         OrderPaymentHistoryRepository $orderPaymentHistoryRepository,
  124.         PluginConfigRepository $configRepository,
  125.         Mem $mem,
  126.         Credit $credit,
  127.         Cvs $cvs,
  128.         SlnAgreementRepository $SlnAgreementRepository
  129.     ) {
  130.         $this->container $container;
  131.         $this->entityManager $entityManager;
  132.         $this->authorizationChecker $authorizationChecker;
  133.         $this->eccubeConfig $eccubeConfig;
  134.         $this->eventDispatcher $eventDispatcher;
  135.         $this->paymentRepository $paymentRepository;
  136.         $this->orderStatusRepository $orderStatusRepository;
  137.         $this->mailService $mailService;
  138.         $this->basicItem $basicItem;
  139.         $this->util $util;
  140.         $this->memCardIdRepository $memCardIdRepository;
  141.         $this->orderPaymentStatusRepository $orderPaymentStatusRepository;
  142.         $this->orderPaymentHistoryRepository $orderPaymentHistoryRepository;
  143.         $this->configRepository $configRepository;
  144.         $this->mem $mem;
  145.         $this->credit $credit;
  146.         $this->cvs $cvs;
  147.         $this->slnAgreementRepository $SlnAgreementRepository;
  148.     }
  149.     /**
  150.      * リッスンしたいサブスクライバのイベント名の配列を返します。
  151.      * 配列のキーはイベント名、値は以下のどれかをしてします。
  152.      * - 呼び出すメソッド名
  153.      * - 呼び出すメソッド名と優先度の配列
  154.      * - 呼び出すメソッド名と優先度の配列の配列
  155.      * 優先度を省略した場合は0
  156.      *
  157.      * 例:
  158.      * - array('eventName' => 'methodName')
  159.      * - array('eventName' => array('methodName', $priority))
  160.      * - array('eventName' => array(array('methodName1', $priority), array('methodName2')))
  161.      *
  162.      * {@inheritdoc}
  163.      */
  164.     public static function getSubscribedEvents()
  165.     {
  166.         return [
  167.             '@admin/Order/index.twig' => 'onAdminOrderIndexTwig',
  168.             EccubeEvents::ADMIN_ORDER_INDEX_INITIALIZE => 'onAdminOrderIndexInitialize',
  169.             EccubeEvents::ADMIN_ORDER_INDEX_SEARCH => 'onAdminOrderIndexSearch',
  170.             '@admin/Order/edit.twig' => 'onAdminOrderEditTwig',
  171.             EccubeEvents::ADMIN_ORDER_EDIT_INDEX_INITIALIZE => 'onAdminOrderEditIndexInitialize',
  172.             'Cart/index.twig' => 'onCartIndexTwig',
  173.             'Shopping/confirm.twig' => 'onShoppingConfirmTwig',
  174.             'Mypage/index.twig' => 'onMypageTwig',
  175.             'Mypage/history.twig' => 'onMypageTwig',
  176.             'Mypage/favorite.twig' => 'onMypageTwig',
  177.             'Mypage/change.twig' => 'onMypageTwig',
  178.             'Mypage/change_complete.twig' => 'onMypageTwig',
  179.             'Mypage/delivery.twig' => 'onMypageTwig',
  180.             'Mypage/delivery_edit.twig' => 'onMypageTwig',
  181.             'Mypage/withdraw.twig' => 'onMypageTwig',
  182.             '@SlnRegular4/Mypage/regular_order.twig' => 'onMypageTwig',
  183.             '@SlnRegular4/Mypage/regular_history.twig' => 'onMypageTwig',
  184.             '@SlnPayment42/sln_edit_card.twig' => 'onMypageTwig',
  185.             EccubeEvents::FRONT_CART_BUYSTEP_INITIALIZE => 'onFrontCartBuystepInitialize',
  186.             'Shopping/index.twig' => 'onShoppingIndexTwig',
  187.             'sln.service.regular.nextorder.complete' => 'onSlnServiceRegularNextorderComplete',
  188.             'sln.service.regular.mypage_history.change_payids' => 'onSlnServiceRegularMypageHistoryChangePayids',
  189.             EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_INITIALIZE => 'onAdminCustomerEditIndexInitialize',
  190.             EccubeEvents::ADMIN_CUSTOMER_DELETE_COMPLETE => 'onAdminCustomerDeleteComplete',
  191.             EccubeEvents::FRONT_MYPAGE_WITHDRAW_INDEX_COMPLETE => 'onFrontMypageWithdrawComplete',
  192.         ];
  193.     }
  194.     /**
  195.      * 受注一覧 - 検索画面介入
  196.      */
  197.     public function onAdminOrderIndexTwig(TemplateEvent $event) {
  198.         $pData $event->getParameters();
  199.         $viewPayStatus = array();
  200.         if ($pData['pagination']) {
  201.             $orderIds = array();
  202.             foreach ($pData['pagination'] as $order) {
  203.                 $orderIds[] = $order->getId();
  204.             }
  205.             if (count($orderIds)) {
  206.                 $payStatuses $this->orderPaymentStatusRepository->findBy(array('id' => $orderIds));
  207.                 if (count($payStatuses)) {
  208.                     foreach ($payStatuses as $payStatus) {
  209.                         $viewPayStatus[$payStatus->getId()] = $payStatus;
  210.                     }
  211.                 }
  212.             }
  213.         }
  214.         $pData['viewPayStatus'] = $viewPayStatus;
  215.         $pData['pay_status'] = array_flip($this->container->getParameter('arrPayStatusNames'));
  216.         $token $this->container->get('security.csrf.token_manager')->getToken(Constant::TOKEN_NAME)->getValue();
  217.         $pData["pay_token"] = $token;
  218.         $event->setParameters($pData);
  219.         $event->addSnippet('@SlnPayment42/admin/order_index.twig');
  220.     }
  221.     /**
  222.      * 受注一覧 - 検索項目追加
  223.      */
  224.     public function onAdminOrderIndexInitialize(EventArgs $event)
  225.     {
  226.         $arrPayStatusNames $this->container->getParameter('arrPayStatusNames');
  227.         $builder $event->getArgument('builder');
  228.         $builder->add('sln_pay_status'ChoiceType::class, [
  229.             'label' => '決済状況',
  230.             'choices' => $arrPayStatusNames,
  231.             'expanded' => true,
  232.             'multiple' => true,
  233.         ]);
  234.     }
  235.     /**
  236.      * 受注一覧 - 検索実行
  237.      */
  238.     public function onAdminOrderIndexSearch(EventArgs $event)
  239.     {
  240.         $searchData $event->getArgument('searchData');
  241.         $qb $event->getArgument('qb');
  242.         $pyStatus $searchData['sln_pay_status'];
  243.         if (count($pyStatus)) {
  244.             $qb2 $this->entityManager->createQueryBuilder();
  245.             $qb2->select('s')
  246.                 ->from('\Plugin\SlnPayment42\Entity\OrderPaymentStatus''sln_status')
  247.                 ->andWhere('o.id = sln_status.id')
  248.                 ->andWhere($qb2->expr()->in('sln_status.paymentStatus'$pyStatus));
  249.             $qb->andWhere($qb->expr()->exists($qb2->getDQL()));
  250.         }
  251.     }
  252.     /**
  253.      * 受注登録編集 - 画面介入
  254.      */
  255.     public function onAdminOrderEditTwig(TemplateEvent $event)
  256.     {
  257.         $pData $event->getParameters();
  258.         $Order $pData['Order'];
  259.         if (MethodUtils::isSlnPaymentMethodByOrder($Order)) {
  260.             //決済情報をとる
  261.             $paymentStatus $this->orderPaymentStatusRepository->getStatus($Order);
  262.             //決済ステータスを表示する
  263.             if ($paymentStatus) {
  264.                 $pData['payStatusId'] = $paymentStatus->getPaymentStatus();
  265.                 
  266.                 $payStatus $this->orderPaymentStatusRepository->getPayStatusName($paymentStatus->getPaymentStatus());
  267.                 if (empty($payStatus)) {
  268.                     // ステータス発見できず
  269.                     return;
  270.                 }
  271.                 $pData['payStatus'] = $payStatus;
  272.                 
  273.                 $pData['payAmount'] = $paymentStatus->getAmount();
  274.                 
  275.                 $pData['isCard'] = true;
  276.                 $agreementStatus $this->slnAgreementRepository->getAgreementStatus($Order);
  277.                 //個人情報同意状況を表示する
  278.                 if ($agreementStatus == 1) {
  279.                     $pData['agreement'] = "同意します";
  280.                 } else {
  281.                     $pData['agreement'] = "";
  282.                 }
  283.             
  284.                 if (MethodUtils::isCvsMethod($Order->getPayment()->getMethodClass())) {
  285.                     // コンビニ支払い
  286.                     $pData['isCard'] = false;
  287.                     
  288.                     $cvsName "";
  289.                     
  290.                     if ($paymentStatus->getPayee()) {
  291.                         //支払い先
  292.                         $arrCvsCd $this->basicItem->getCvsCd();
  293.                     
  294.                         $cvsName $arrCvsCd[$paymentStatus->getPayee()];
  295.                         if (!$cvsName) {
  296.                             $cvsName $paymentStatus->getPayee();
  297.                         }
  298.                     
  299.                         $pData['payCvsName'] = $cvsName;
  300.                     }
  301.                     
  302.                     $FreeAreaHistory $this->orderPaymentHistoryRepository
  303.                                             ->findOneBy(
  304.                                                 array('orderId' => $Order->getId(),
  305.                                                     'operateId' => array('2Add''2Chg'),
  306.                                                     'sendFlg' => 1,
  307.                                                     'requestFlg' => 0,
  308.                                                     'responseCd' => 'OK',
  309.                                                 ),
  310.                                                 array('id' => 'DESC')
  311.                                             );
  312.                     if ($FreeAreaHistory) {
  313.                         $FreeAreabody $FreeAreaHistory->getBody();
  314.                         $FreeAreadata json_decode($FreeAreabody1);
  315.                     
  316.                         //コンビニ支払いリンクをとる
  317.                         $pData['payLink'] = $this->configRepository->getConfig()->getCreditConnectionPlace3() . sprintf("?code=%s&rkbn=2"$FreeAreadata['FreeArea']);
  318.                     }
  319.                 }
  320.                 //通信ログをとる
  321.                 $pData['payHistorys'] = $this->orderPaymentHistoryRepository->findBy(array('orderId' => $Order->getId()));
  322.             }
  323.         }
  324.         $event->setParameters($pData);
  325.         $event->addSnippet('@SlnPayment42/admin/order_edit.twig');
  326.     }
  327.     /**
  328.      * redirectToRouteのレスポンスを取得する
  329.      */
  330.     public function redirectToRouteResponse($route$params = array()) {
  331.         $router $this->container->get('router');
  332.         return new RedirectResponse($router->generate($route$params), 302);
  333.     }
  334.     /**
  335.      * 受注登録編集 - 初期化
  336.      */
  337.     public function onAdminOrderEditIndexInitialize(EventArgs $event) {
  338.         $request $event->getRequest();
  339.         if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) {
  340.             
  341.             $Order $event->getArgument('TargetOrder');
  342.             $orderId $Order->getId();
  343.             
  344.             if (!$orderId) {
  345.                 return ;
  346.             }
  347.             
  348.             $history $this->orderPaymentHistoryRepository
  349.                 ->findOneBy(
  350.                     array('orderId' => $orderId,
  351.                         'operateId' => array('2Add''1Auth''1Gathering''1ReAuth'),
  352.                         'sendFlg' => 1,
  353.                         'requestFlg' => 0
  354.                     ),
  355.                     array('id' => 'DESC')
  356.                 );
  357.             
  358.             if (!$history) {
  359.                 return ;
  360.             }
  361.             
  362.             $mode $request->get('mode');
  363.             if (!$mode || substr($mode03) != "sln" || $request->getMethod() != "POST") {
  364.                 return ;
  365.             }
  366.             
  367.             $cvs $this->cvs;
  368.             $card $this->credit;
  369.             
  370.             try {
  371.                 //決済に関するボタン操作
  372.                 switch ($mode) {
  373.                     case 'sln_cvs_ref'://結果照会
  374.                         $ref $cvs->Ref($Order$this->configRepository->getConfig(), $history);
  375.                         if (!is_null($ref->getAmount())) {//回答する場合
  376.                             if ($Order->getPaymentTotal() == $ref->getAmount()) {//支払い情報を確認
  377.             
  378.                                 //決済ステータスを変更する
  379.                                 $this->orderPaymentStatusRepository->paySuccess($Order$ref->getCvsCd());
  380.             
  381.                                 //受注ステータスを更新する
  382.                                 $Order->setOrderStatus($this->orderStatusRepository->find(OrderStatus::PAID));
  383.                                 $Order->setPaymentDate(new \DateTime());
  384.                                 $this->entityManager->persist($Order);
  385.                                 $this->entityManager->flush();
  386.                                 
  387.                                 $this->util->addSuccess($request'admin.common.save_complete''admin');
  388.                                 return;
  389.                             } else {
  390.                                 throw new SlnException("受注金額と決済金額が一致していません。");
  391.                             }
  392.                         }
  393.                         break;
  394.                     case "sln_cvs_chg"://決済金額変更
  395.                         $cvs->Chg($Order$this->configRepository->getConfig(), $history);
  396.                         $this->orderPaymentStatusRepository->requestSuccess($Order$Order->getPaymentTotal());
  397.                         //決済金額情報を変更する
  398.                         $this->orderPaymentStatusRepository->change($Order$Order->getPaymentTotal());
  399.                         $this->util->addSuccess($request'決済金額を変更しました''admin');
  400.                         return;
  401.                     case "sln_cvs_del":
  402.                         //決済削除
  403.                         $cvs->Del($Order$this->configRepository->getConfig(), $history);
  404.                         
  405.                         $this->orderPaymentStatusRepository->cancel($Order);
  406.                         $this->util->addSuccess($request'決済を削除しました。''admin');
  407.                         return;
  408.                     case "sln_cvs_add":
  409.                         list($link$add) = $cvs->Add($Order$this->configRepository->getConfig(), '');
  410.                         //決済ステータスを変更する
  411.                         $this->orderPaymentStatusRepository
  412.                                 ->requestSuccess($Order$add->getContent()->getAmount());
  413.                     
  414.                         //決済金額情報を変更する
  415.                         $this->orderPaymentStatusRepository->change($Order$add->getContent()->getAmount());
  416.                                 
  417.                         //受注ステータスを更新する
  418.                         $Order->setOrderStatus($this->orderStatusRepository->find(OrderStatus::NEW));
  419.                         $this->entityManager->persist($Order);
  420.                         $this->entityManager->flush();
  421.                     
  422.                         $this->util->addSuccess($request'再決済を行いました''admin');
  423.                         return;
  424.                     case "sln_card_commit":
  425.                         $card->Capture($Order$this->configRepository->getConfig(), $history);
  426.                         
  427.                         //決済ステータスを変更する
  428.                         $this->orderPaymentStatusRepository->commit($Order$Order->getPaymentTotal());
  429.                         $this->util->addSuccess($request'売上確定処理を実行しました''admin');
  430.                         return;
  431.                     case "sln_card_cancel":
  432.                         $card->Delete($Order$this->configRepository->getConfig(), $history);
  433.                         
  434.                         //決済ステータスを変更する
  435.                         $this->orderPaymentStatusRepository->void($Order);
  436.                         $this->util->addSuccess($request'取消(返品)処理が完了しました''admin');
  437.                         return;
  438.                     case "sln_card_change":
  439.                         $card->Change($Order$this->configRepository->getConfig(), $history);
  440.                     
  441.                         //決済金額情報を変更する
  442.                         $this->orderPaymentStatusRepository->change($Order$Order->getPaymentTotal());
  443.                         $this->util->addSuccess($request'決済金額変更処理を実行しました''admin');
  444.                         return;
  445.                     case "sln_card_reauth":
  446.                         
  447.                         /* @var $kaiinHistory \Plugin\SlnPayment42\Entity\PlgSlnOrderPaymentHistory */
  448.                         $kaiinHistory $this->orderPaymentHistoryRepository
  449.                                             ->findOneBy(
  450.                                                 array('orderId' => $Order->getId(),
  451.                                                     'operateId' => array('1Auth''1Gathering'),
  452.                                                 ),
  453.                                                 array('id' => 'ASC')
  454.                                             );
  455.                         
  456.                         $card->ReAuth($Order$this->configRepository->getConfig(), $history);
  457.                         
  458.                         if ($kaiinHistory->getOperateId() == '1Gathering') {
  459.                             //再オーソリ
  460.                             $this->orderPaymentStatusRepository->capture($Order$Order->getPaymentTotal());
  461.                         } else {
  462.                             //再オーソリ
  463.                             $this->orderPaymentStatusRepository->auth($Order$Order->getPaymentTotal());
  464.                         }
  465.                         $this->util->addSuccess($request'再オーソリの取得処理を実行しました''admin');
  466.                         return;
  467.                     default:
  468.                         throw new SlnException("ボタン例外処理。");
  469.                         break;
  470.                 }
  471.             } catch (SlnShoppingException $e) {
  472.                 log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  473.                 if (substr($mode44) == 'card') {
  474.                     $this->util->addCardNotice(sprintf("card order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine()));
  475.                 } else {
  476.                     $this->util->addCvsNotice(sprintf("cvs order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine()));
  477.                 }
  478.                 $this->util->addErrorLog($e->getSlnErrorName() . $e->getSlnErrorDetail() . 'order_id:' $Order->getId() . " " $e->getFile() . $e->getLine());
  479.                 $this->ErrMss $e->getSlnErrorDetail();
  480.                 $this->util->addWarning($request$this->ErrMss'admin');
  481.             } catch (SlnException $e) {
  482.                 log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  483.                 if (substr($mode44) == 'card') {
  484.                     $log sprintf("card order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  485.                     $this->util->addCardNotice($log);
  486.                 } else {
  487.                     $log sprintf("cvs order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  488.                     $this->util->addCvsNotice($log);
  489.                 }
  490.                 $this->util->addErrorLog($log);
  491.                 $this->ErrMss $e->getMessage();
  492.                 $this->util->addWarning($request$this->ErrMss'admin');
  493.             } catch (\Exception $e) {
  494.                 log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  495.                 if (substr($mode44) == 'card') {
  496.                     $log sprintf("card order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  497.                     $this->util->addCardNotice($log);
  498.                 } else {
  499.                     $log sprintf("cvs order edit error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  500.                     $this->util->addCvsNotice($log);
  501.                 }
  502.                 $this->util->addErrorLog($log);
  503.                 throw new \Exception($e->getMessage() . " " $e->getFile() . $e->getLine());
  504.             }
  505.         }
  506.     }
  507.     public function onCartIndexTwig(TemplateEvent $event) {
  508.         $isQuick $this->configRepository->getConfig()->getQuickAccounts();
  509.         if ($isQuick == 1) {
  510.             $event->addSnippet('@SlnPayment42/sln_cart_quick_pay.twig'true);
  511.         }
  512.     }
  513.     /**
  514.      * 注文ボタンの文字列を変更する
  515.      */
  516.     public function onShoppingConfirmTwig(TemplateEvent $event) {
  517.         // 注文ボタンタイトルを変更する
  518.         $Order $event->getParameter('Order');
  519.         if ($Order) {
  520.             $methodClass $Order->getPayment()->getMethodClass();
  521.             if (MethodUtils::isSlnPaymentMethodByOrder($Order)){
  522.                 $event->addSnippet('@SlnPayment42/sln_shopping_confirm.twig');
  523.             }
  524.         }
  525.         //3Dセキュア判定
  526.         $isThreedPay $this->configRepository->getConfig()->getThreedPay();
  527.         $event->setParameter('Is3DPay'$isThreedPay == 1);
  528.         
  529.         //クレジットカード決済判定
  530.         $methodClass $Order->getPayment()->getMethodClass();
  531.         $isCcCard MethodUtils::isCreditCardMethod($methodClass);
  532.         $event->setParameter('IsCcCard'$isCcCard);
  533.         
  534.     }
  535.     public function onMypageTwig(TemplateEvent $event) {
  536.         $event->addSnippet('@SlnPayment42/sln_mypage_add_item.twig');
  537.     }
  538.     public function onFrontCartBuystepInitialize(EventArgs $event) {
  539.         $session $event->getRequest()->getSession();
  540.         $session->remove('eccube.sln.pay.slClink');
  541.         if (array_key_exists('slClink'$_GET) && $_GET['slClink'] == 1) {
  542.             $session->set('eccube.sln.pay.slClink'1);
  543.         }
  544.     }
  545.     /**
  546.      * ご注文手続き画面介入
  547.      */
  548.     public function onShoppingIndexTwig(TemplateEvent $event) {
  549.         $slClink false;
  550.         $isCreditCardRegistered false;
  551.         $isEnabledQuickPay false;
  552.         // クイック決済選択判定
  553.         $session = new Session();
  554.         if ($session->get('eccube.sln.pay.slClink') == 1) {
  555.             $session->remove('eccube.sln.pay.slClink');
  556.             $slClink true;
  557.         }
  558.         // クレジットカード登録判定
  559.         try {
  560.             $Customer $event->getParameter('Order')->getCustomer();
  561.             if ($Customer != null) {
  562.                 $ReMemRef $this->mem->MemRef($Customer$this->configRepository->getConfig());
  563.                 if ($ReMemRef->getContent()->getKaiinStatus() == 0) {
  564.                     $isCreditCardRegistered true;
  565.                 }
  566.             }
  567.         } catch(\Exception $e) {
  568.             log_info($e->getMessage());
  569.         }
  570.         // クイック決済選択時かつクレジットカード登録済みの場合は登録済み
  571.         if ($slClink && $isCreditCardRegistered) {
  572.             $isEnabledQuickPay true;
  573.         }
  574.         // クレジットカード決済ID取得
  575.         $ccPayId 0;
  576.         $payment $this->paymentRepository->findOneBy(['method_class' => CreditCard::class]);
  577.         if ($payment) {
  578.             $ccPayId $payment->getId();
  579.         }
  580.         // 登録済みクレジットカード決済ID取得
  581.         $rcPayId 0;
  582.         $payment $this->paymentRepository->findOneBy(['method_class' => RegisteredCreditCard::class]);
  583.         if ($payment) {
  584.             $rcPayId $payment->getId();
  585.         }
  586.         $event->setParameter('slClink'$slClink);
  587.         $event->setParameter('isEnabledQuickPay'$isEnabledQuickPay);
  588.         $event->setParameter('isCreditCardRegistered'$isCreditCardRegistered);
  589.         $event->setParameter('ccPayId'$ccPayId);
  590.         $event->setParameter('rcPayId'$rcPayId);
  591.         
  592.         $event->addSnippet('@SlnPayment42/sln_shopping_quick_pay.twig');
  593.     }
  594.     /**
  595.      * 定期受注により受注変換完了時
  596.      * @param EventArgs $event
  597.      * @throws \Exception
  598.      */
  599.     public function onSlnServiceRegularNextorderComplete(EventArgs $event)
  600.     {
  601.         /* @var $Order \Plugin\SlnRegular4\Entity\SlnRegularOrder */
  602.         $Order $event->getArgument('Order');
  603.         
  604.         //プラグイン決済方法判断
  605.         $methodClass $Order->getPayment()->getMethodClass();
  606.         if (!MethodUtils::isSlnPaymentMethod($methodClass)) {
  607.             return;
  608.         }
  609.         
  610.         $event->setArgument('isSendMail'false);
  611.         
  612.         $cvs $this->cvs;
  613.         
  614.         // トランザクション制御
  615.         $em $this->entityManager;
  616.         
  617.         $reUrl "";
  618.         
  619.         try {
  620.             
  621.             if (MethodUtils::isCvsMethod($methodClass)) {
  622.                 //決済状況を記録する
  623.                 $this->orderPaymentStatusRepository->unsettled($Order);
  624.                 
  625.                 //通信処理を行う
  626.                 list($reUrl$add) = $cvs->Add(
  627.                     $Order,
  628.                     $this->configRepository->getConfig(),
  629.                     $event->getRequest()->getSchemeAndHttpHost() . $this->util->generateUrl('shopping_complete'));
  630.                 
  631.                 $this->orderPaymentStatusRepository->requestSuccess($Order$add->getContent()->getAmount());
  632.             } else {
  633.                 
  634.                 $method $em->getRepository('\Plugin\SlnRegular4\Entity\SlnRegularPluginConfig')->getConfig()->getNextCreditMethod();
  635.                 
  636.                 //決済状況を記録する
  637.                 $this->orderPaymentStatusRepository->unsettled($Order);
  638.                 
  639.                 $master = new \Plugin\SlnPayment42\Service\SlnContent\Credit\Master();
  640.                 $card $this->credit;
  641.                 
  642.                 list($KaiinId$KaiinPass) = $this->util->getNewKaiin($this->memCardIdRepository$Order->getCustomer(), $this->eccubeConfig->get('eccube_auth_magic'));
  643.                 $master->setKaiinId($KaiinId);
  644.                 $master->setKaiinPass($KaiinPass);
  645.                 
  646.                 $master->setPayType("01");
  647.                 
  648.                 if ($method == 1) {
  649.                     $card->Auth($Order$this->configRepository->getConfig(), $master);
  650.                     $this->orderPaymentStatusRepository->auth($Order$master->getAmount());
  651.                 } else {
  652.                     $card->Gathering($Order$this->configRepository->getConfig(), $master);
  653.                     $this->orderPaymentStatusRepository->capture($Order$master->getAmount());
  654.                 }
  655.             }
  656.         
  657.         } catch (SlnShoppingException $e) {
  658.             log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  659.         
  660.             if (MethodUtils::isCvsMethod($methodClass)) {
  661.                 $log sprintf("cvs shopping error:%s order_id(%s)"$e->getSlnErrorCode() . '|' $e->getSlnErrorName() . '|' $e->getSlnErrorDetail(), $Order->getId());
  662.                 $this->util->addCvsNotice($log);
  663.             } else {
  664.                 $log sprintf("card shopping error:%s order_id(%s)"$e->getSlnErrorCode() . '|' $e->getSlnErrorName() . '|' $e->getSlnErrorDetail(), $Order->getId());
  665.                 $this->util->addCardNotice($log);
  666.             }
  667.             
  668.             if ($e->checkSystemError()) {
  669.                 $this->util->addErrorLog($e->getSlnErrorName() . $e->getSlnErrorDetail() . 'order_id:' $Order->getId() . " " $e->getFile() . $e->getLine());
  670.             }
  671.         
  672.             $this->orderPaymentStatusRepository->fail($Order);
  673.             $event->setArgument('errorMess'sprintf('受注id:(%s) 決済処理が失敗しました(%s)'$Order->getId(), $log));
  674.             
  675.             return ;
  676.         
  677.         } catch (ShoppingException $e) {
  678.             log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  679.         
  680.             if (MethodUtils::isCvsMethod($methodClass)) {
  681.                 $log sprintf("cvs shopping error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  682.                 $this->util->addCvsNotice($log);
  683.             } else {
  684.                 $log sprintf("card shopping error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  685.                 $this->util->addCardNotice($log);
  686.             }
  687.             
  688.             $this->util->addErrorLog($log);
  689.             
  690.             $this->orderPaymentStatusRepository->fail($Order);
  691.             $event->setArgument('errorMess'sprintf('受注id:(%s) 決済処理失敗しました.(%s)'$Order->getId(), $log));
  692.             
  693.             return ;
  694.         } catch (\Exception $e) {
  695.             log_error(__FILE__ '(' __LINE__ ') ' $e->getMessage());
  696.         
  697.             if (MethodUtils::isCvsMethod($Order->getPayment()->getMethodClass())) {
  698.                 $log sprintf("cvs shopping error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  699.                 $this->util->addCvsNotice($log);
  700.             } else {
  701.                 $log sprintf("card shopping error:%s order_id(%s)"$e->getMessage(), $Order->getId() . " " $e->getFile() . $e->getLine());
  702.                 $this->util->addCardNotice($log);
  703.             }
  704.             
  705.             $this->util->addErrorLog($log);
  706.             
  707.             $this->orderPaymentStatusRepository->fail($Order);
  708.             
  709.             throw new \Exception($e->getMessage());
  710.         }
  711.         
  712.         $event->setArgument('errorMess'null);
  713.         // メール送信
  714.         $this->mailService->sendOrderMail($Order$reUrl);
  715.     }
  716.     
  717.     /**
  718.      * 定期受注プラグインより支払い方法変更可能かの通知
  719.      */
  720.     public function onSlnServiceRegularMypageHistoryChangePayids(EventArgs $EventArgs)
  721.     {
  722.         $changePayIds $EventArgs->getArgument('changePayIds');
  723.         $cardType $this->paymentRepository->findOneBy(['method_class' => CreditCard::class]);
  724.         $cardRegistType $this->paymentRepository->findOneBy(['method_class' => RegisteredCreditCard::class]);
  725.         $changePayIds[] = $cardType->getId();
  726.         $changePayIds[] = $cardRegistType->getId();
  727.         $EventArgs->setArgument('changePayIds'$changePayIds);
  728.     }
  729.     /**
  730.      * 会員退会時にe-SCOTT会員無効化処理(Admin/CustomerEditController)
  731.      */
  732.     public function onAdminCustomerEditIndexInitialize(EventArgs $event)
  733.     {
  734.         $form $event->getArgument("builder")->getForm();
  735.         $oldStatusId $form->getData()
  736.             ->getStatus()
  737.             ->getId();
  738.         
  739.         // 削除完了時に実行
  740.         $this->eventDispatcher->addListener(EccubeEvents::ADMIN_CUSTOMER_EDIT_INDEX_COMPLETE, function (EventArgs $event) use ($oldStatusId) {
  741.             $config $this->configRepository->getConfig();
  742.             $user $event->getArgument("Customer");
  743.             $form $event->getArgument("form");
  744.             $newStatusId $form->getData()
  745.                 ->getStatus()
  746.                 ->getId();
  747.             
  748.             if ($oldStatusId != $newStatusId && $newStatusId == CustomerStatus::WITHDRAWING) {
  749.                 try {
  750.                     // 会員無効化のみで会員削除はしない
  751.                     $this->mem->MemInval($user$config);
  752.                 } catch (\Exception $e) {
  753.                     // エラーが発生しても正常にEC-CUBE会員退会処理を完了させるためキャッチ
  754.                 }
  755.             }
  756.         });
  757.     }
  758.     
  759.     /**
  760.      * 会員退会時にe-SCOTT会員無効化処理(Admin/CustomerController)
  761.      */
  762.     public function onAdminCustomerDeleteComplete(EventArgs $event){
  763.         //削除失敗時は処理を実行しない
  764.         if ($this->entityManager->isOpen()) {
  765.             $config $this->configRepository->getConfig();
  766.             $id $event->getRequest()->attributes->get("id");
  767.             
  768.             // 物理削除したIDをもつエンティティを再現
  769.             $user = new Customer();
  770.             $user->setPropertiesFromArray(["id" => $id]);
  771.             
  772.             try {
  773.                 // 会員無効化のみで会員削除はしない
  774.                 $this->mem->MemInval($user$config);
  775.             } catch (\Exception $e) {
  776.                 // エラーが発生しても正常にEC-CUBE会員退会処理を完了させるためキャッチ
  777.             }
  778.         }
  779.     }
  780.     
  781.     /**
  782.      * 会員退会時にe-SCOTT会員無効化処理(Mypage/WithdrawController)
  783.      */
  784.     public function onFrontMypageWithdrawComplete(EventArgs $event){
  785.         //削除失敗時は処理を実行しない
  786.         if ($this->entityManager->isOpen()) {
  787.             $config $this->configRepository->getConfig();
  788.             $user $this->container->get('security.token_storage')->getToken()->getUser();
  789.             
  790.             try {
  791.                 // 会員無効化のみで会員削除はしない
  792.                 $this->mem->MemInval($user$config);
  793.             } catch (\Exception $e) {
  794.                 // エラーが発生しても正常にEC-CUBE会員退会処理を完了させるためキャッチ
  795.             }
  796.         }
  797.     }
  798. }