app/Plugin/VeriTrans4G2/Controller/PaymentController.php line 94

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright (c) 2018 VeriTrans Inc., a Digital Garage company. All rights reserved.
  4.  * http://www.veritrans.co.jp/
  5.  */
  6. namespace Plugin\VeriTrans4G2\Controller;
  7. use Doctrine\DBAL\Exception\DriverException;
  8. use Doctrine\DBAL\Exception\LockWaitTimeoutException;
  9. use Plugin\VeriTrans4G2\Controller\AbstractVt4gController;
  10. use Eccube\Service\CartService;
  11. use Eccube\Service\OrderHelper;
  12. use Eccube\Repository\OrderRepository;
  13. use Eccube\Repository\Master\OrderStatusRepository;
  14. use Plugin\VeriTrans4G2\Entity\Vt4gOrderPayment;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  20. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  21. /**
  22.  * 決済関連コントローラー
  23.  */
  24. class PaymentController extends AbstractVt4gController
  25. {
  26.     /**
  27.      * コンテナ
  28.      */
  29.     protected $container;
  30.     /**
  31.      * エンティティーマネージャー
  32.      */
  33.     protected $em;
  34.     /**
  35.      * VT用固定値配列
  36.      */
  37.     protected $vt4gConst;
  38.     /**
  39.      * 汎用処理用ユーティリティ
  40.      */
  41.     protected $util;
  42.     /**
  43.      * @var OrderRepository
  44.      */
  45.     protected $orderRepository;
  46.     /**
  47.      * @var OrderStatusRepository
  48.      */
  49.     protected $orderStatusRepository;
  50.     /**
  51.      * @var CartService
  52.      */
  53.     protected $cartService;
  54.     /**
  55.      * コンストラクタ
  56.      * @param ContainerInterface $container
  57.      * @return void
  58.      */
  59.     public function __construct(
  60.         ContainerInterface $container,
  61.         OrderRepository $orderRepository,
  62.         OrderStatusRepository $orderStatusRepository,
  63.         CartService $cartService
  64.     )
  65.     {
  66.         $this->container $container;
  67.         $mdkService $this->container->get('vt4g_plugin.service.vt4g_mdk');
  68.         $mdkService->checkMdk();
  69.         $this->em $container->get('doctrine.orm.entity_manager');
  70.         $this->vt4gConst $container->getParameter('vt4g_plugin.const');
  71.         $this->util $container->get('vt4g_plugin.service.util');
  72.         $this->orderRepository $orderRepository;
  73.         $this->orderStatusRepository $orderStatusRepository;
  74.         $this->cartService $cartService;
  75.     }
  76.     /**
  77.      * 購入フロー決済画面
  78.      *
  79.      * @Route("/shopping/vt4g_payment", name="vt4g_shopping_payment")
  80.      * @param  Request $request リクエストデータ
  81.      * @return object           ビューレスポンス|レダイレクトレスポンス
  82.      */
  83.     public function index(Request $requestCartService $cartServiceOrderRepository $orderRepository)
  84.     {
  85.         $mode $request->get('mode');
  86.         $memo01 null;
  87.         if (!empty($request->get('OrderId'))) {
  88.             $memo01 $request->get('OrderId');
  89.         } elseif (!empty($request->get('orderId'))) {
  90.             $memo01 $request->get('orderId');
  91.         }
  92.         if (!empty($memo01)) {
  93.             $orderPayment $this->em->getRepository(Vt4gOrderPayment::class)->findOneBy(['memo01' => $memo01]);
  94.             //取引IDが登録されていない場合、エラー画面へ遷移
  95.             if (!$orderPayment instanceof Vt4gOrderPayment) {
  96.                 return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse();
  97.             }
  98.             try {
  99.                 list($order$orderPayment) = $this->container->get('vt4g_plugin.service.payment_base')->getLockedOrder($orderPayment->getOrderId());
  100.             } catch (LockWaitTimeoutException $e) {
  101.                 return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse(trans('vt4g_plugin.payment.shopping.lock_timeout'));
  102.             } catch (DriverException $e) {
  103.                 return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse(trans('vt4g_plugin.payment.shopping.lock_timeout'));
  104.             }
  105.             $memo10 unserialize($orderPayment->getMemo10());
  106.             if (!array_key_exists('orderCompleteFlg'$memo10) || $memo10['orderCompleteFlg']) {
  107.                 return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $order->getId()]);
  108.             }
  109.         } elseif (!empty($cartService->getPreOrderId())) {
  110.             $order $orderRepository->findOneBy(['pre_order_id' => $cartService->getPreOrderId()]);
  111.         } else {
  112.             $order null;
  113.         }
  114.         // 決済の入力チェック
  115.         $result $this->container->get('vt4g_plugin.service.payment_base')->checkPaymentData($cartService$order);
  116.         if ($result !== true) {
  117.             return $result;
  118.         }
  119.         $payment $order->getPayment();
  120.         $payId   $this->util->getPayId($payment->getId());
  121.         $payCode $this->util->getPayCode($payId);
  122.         $payload = [
  123.             'paymentType' => $payCode,
  124.             'mode'        => $mode,
  125.             'order'       => $order,
  126.             'paymentInfo' => $this->util->getPaymentMethodInfo($payment->getId()),
  127.             'user'        => $this->getUser(),
  128.             'orderPayment' => $orderPayment ?? new Vt4gOrderPayment,
  129.         ];
  130.         $method "exec{$payCode}Process";
  131.         return $this->$method($request$payload);
  132.     }
  133.     /**
  134.      * 購入フロー決済完了画面
  135.      *
  136.      * @Route("/shopping/vt4g_payment/complete", name="vt4g_shopping_payment_complete")
  137.      * @param  Request $request リクエストデータ
  138.      * @return object           リダイレクトレスポンス
  139.      */
  140.     public function complete(Request $request)
  141.     {
  142.         $orderId $request->get('no');
  143.         $order $this->getOrderById($orderId);
  144.         // 注文が存在しない もしくは ログインユーザと注文者が一致しない場合
  145.         if (!$order || $this->getUser() != $order->getCustomer()) {
  146.             throw new NotFoundHttpException();
  147.         }
  148.         $orderPayment $this->util->getOrderPayment($order->getId());
  149.         if (!$orderPayment instanceof Vt4gOrderPayment) {
  150.             return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse();
  151.         }
  152.         //ネットバンク決済を使用している時のみ、注文/決済ステータスを変更する。
  153.         $payId $orderPayment->getMemo03();
  154.         if($payId == $this->vt4gConst['VT4G_PAYTYPEID_BANK']){
  155.             $bank $this->container->get('vt4g_plugin.service.payment_bank');
  156.             $bank->changePayStatus($order$orderPayment);
  157.         }
  158.         // 完了画面を表示するため、受注IDをセッションに保持する
  159.         $this->session->set(OrderHelper::SESSION_ORDER_ID$order->getId());
  160.         return $this->redirectToRoute('shopping_complete');
  161.     }
  162.     /**
  163.      * 購入フロー決済 戻る処理
  164.      *
  165.      * @Route("/shopping/vt4g_payment/back", name="vt4g_shopping_payment_back")
  166.      * @param  Request $request リクエストデータ
  167.      * @return object           リダイレクトレスポンス
  168.      */
  169.     public function back(Request $request)
  170.     {
  171.         $orderId $request->get('no');
  172.         $order $this->getOrderById($orderId);
  173.         // 注文が存在しない もしくは ログインユーザと注文者が一致しない場合
  174.         if (!$order || $this->getUser() != $order->getCustomer()) {
  175.             throw new NotFoundHttpException();
  176.         }
  177.         return $this->redirectToRoute('shopping');
  178.     }
  179.     /**
  180.      * クレジットカード決済処理
  181.      *
  182.      * @param  Request $request リクエストデータ
  183.      * @param  array   $payload 決済処理に使用するデータ
  184.      * @return object           リダイレクトレスポンス|ビューレスポンス
  185.      */
  186.     private function execCreditProcess($request$payload)
  187.     {
  188.         $credit $this->container->get('vt4g_plugin.service.payment_credit');
  189.         $result false;
  190.         $execPaymentFlg false;
  191.         $error = [
  192.             'payment' => '',
  193.             'credit'  => ''
  194.         ];
  195.         // 入力フォーム送信時
  196.         if ($request->getMethod() === 'POST' && $payload['mode'] !== 'comp') {
  197.             $execPaymentFlg true;
  198.             // POST用リクエストパラメータをsessionで指定した値に変更
  199.             if ($this->container->get('session')->has('vt4g_shopping_request')) {
  200.                 $vt4gShoppingRequest $this->container->get('session')->get('vt4g_shopping_request');
  201.                 $this->container->get('session')->remove('vt4g_shopping_request');
  202.                 $payload['mode'] = $vt4gShoppingRequest['mode'];
  203.                 switch ($payload['mode']) {
  204.                     case 'token':   // MDKトークン利用
  205.                     case 'retrade'// 再取引
  206.                     case 'account'// ベリトランス会員ID決済
  207.                         $this->execIsTokenValid($credit$payload);
  208.                         $result $credit->commitNormalPayment($vt4gShoppingRequest$payload$error);
  209.                         break;
  210.                     default:
  211.                         return $credit->makeErrorResponse();
  212.                 }
  213.             } else {
  214.                 $error['payment'] = trans('vt4g_plugin.payment.shopping.required.error');
  215.                 $result false;
  216.             };
  217.         }
  218.         if ($payload['mode'] === 'comp') {
  219.             $execPaymentFlg true;
  220.             // 本人認証リダイレクト
  221.             $result $credit->commitMpiPayment($request$payload$error);
  222.         }
  223.         if ($result) {
  224.             return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  225.         }
  226.         // 入力フォーム上にエラー表示の場合はロールバックを行わない
  227.         if ($execPaymentFlg && empty($error['credit'])) {
  228.             // ロールバック
  229.             $credit->rollback($payload['order']);
  230.         }
  231.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  232.             'paymentType'       => $payload['paymentType'],
  233.             'error'             => $error,
  234.             'orderNo'           => $payload['order']->getId(),
  235.             'title'             => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_10'],
  236.             'tplIsLoading'      => (empty($error['payment']) && empty($error['credit'])),
  237.             'loadingImage'      => $this->util->getLoadingImage()
  238.         ]);
  239.     }
  240.     /**
  241.      * ATM決済処理
  242.      *
  243.      * @param  request $request リクエストデータ
  244.      * @param  array   $payload 決済処理に使用するデータ
  245.      * @return object           リダイレクトレスポンス|ビューレスポンス
  246.      */
  247.     private function execATMProcess($request$payload)
  248.     {
  249.         $atm $this->container->get('vt4g_plugin.service.payment_atm');
  250.         $error = [
  251.             'payment' => '',
  252.         ];
  253.         if ('POST' === $request->getMethod() && $payload['mode'] == "next") {
  254.             $this->execIsTokenValid($atm$payload);
  255.             $result $atm->atmCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  256.             if ($result){
  257.                 return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  258.             }
  259.             // ロールバック
  260.             $atm->rollback($payload['order']);
  261.         }
  262.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  263.             'paymentType'  => $payload['paymentType'],
  264.             'error'        => $error,
  265.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_31'],
  266.             'orderNo'      => $payload['order']->getId(),
  267.             'tplIsLoading' => empty($error['payment']),
  268.             'loadingImage' => $this->util->getLoadingImage()
  269.         ]);
  270.     }
  271.     /**
  272.      * ネットバンク決済処理
  273.      *
  274.      * @param  request $request リクエストデータ
  275.      * @param  array   $payload 決済処理に使用するデータ
  276.      * @return object           リダイレクトレスポンス|ビューレスポンス
  277.      */
  278.     public function execBankProcess($request$payload)
  279.     {
  280.         $bank $this->container->get('vt4g_plugin.service.payment_bank');
  281.         $error = [
  282.             'payment' => '',
  283.         ];
  284.         // POST用リクエストパラメータ
  285.         $result $bank->bankCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  286.         if ($result == false){
  287.             // ロールバック
  288.             $bank->rollback($payload['order']);
  289.         }
  290.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  291.             'paymentType'  => $payload['paymentType'],
  292.             'error'        => $error,
  293.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_30'],
  294.             'orderNo'      => $payload['order']->getId(),
  295.             'paymentInfo'  => $payload['paymentInfo'],
  296.             'tplIsLoading' => empty($error['payment']),
  297.             'loadingImage' => $this->util->getLoadingImage(),
  298.             'requestParam' => $result,
  299.         ]);
  300.     }
  301.     /**
  302.      * コンビニ決済処理
  303.      *
  304.      * @param  Request $request リクエストデータ
  305.      * @param  array   $payload 決済処理に使用するデータ
  306.      * @return object           リダイレクトレスポンス|ビューレスポンス
  307.      */
  308.     private function execCVSProcess($request$payload)
  309.     {
  310.         $cvs $this->container->get('vt4g_plugin.service.payment_cvs');
  311.         $error = [
  312.             'payment' => '',
  313.         ];
  314.         // 入力フォーム送信時
  315.         if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
  316.             $this->execIsTokenValid($cvs$payload);
  317.             // POST用リクエストパラメータをsessionで指定した値に変更
  318.             if ($this->container->get('session')->has('vt4g_shopping_request')) {
  319.                 $vt4gCvsForm $this->container->get('session')->get('vt4g_shopping_request');
  320.                 $this->container->get('session')->remove('vt4g_shopping_request');
  321.                 $request->request->set('payment_cvs',$vt4gCvsForm);
  322.                 $result $cvs->cvsCommit($payload['order'], $payload['orderPayment'], $request->request$payload['paymentInfo'], $error);
  323.             } else {
  324.                 $error['payment'] = trans('vt4g_plugin.payment.shopping.required.error');
  325.                 $result false;
  326.             }
  327.             if ($result !== false){
  328.                 return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  329.             } else {
  330.                 // ロールバック
  331.                 $cvs->rollback($payload['order']);
  332.             }
  333.         }
  334.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  335.             'paymentType'  => $payload['paymentType'],
  336.             'error'        => $error,
  337.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_20'],
  338.             'orderNo'      => $payload['order']->getId(),
  339.             'tplIsLoading' => empty($error['payment']),
  340.             'loadingImage' => $this->util->getLoadingImage()
  341.         ]);
  342.     }
  343.     /**
  344.      * Alipay決済処理
  345.      *
  346.      * @param  Request $request リクエストデータ
  347.      * @param  array   $payload 決済処理に使用するデータ
  348.      * @return object           リダイレクトレスポンス|ビューレスポンス
  349.      */
  350.     private function execAlipayProcess($request$payload)
  351.     {
  352.         $alipay $this->container->get('vt4g_plugin.service.payment_alipay');
  353.         $error = [
  354.             'payment' => '',
  355.         ];
  356.         $requestHtml ='';
  357.         if ($request->getMethod() === 'POST') {
  358.             if ($payload['mode'] == 'next') {
  359.                 $this->execIsTokenValid($alipay$payload);
  360.                 // リダイレクト用HTML取得
  361.                 $result $alipay->alipayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  362.                 if ($result !== false) {
  363.                     $requestHtml $result;
  364.                 }else{
  365.                     // ロールバック
  366.                     $alipay->rollback($payload['order']);
  367.                 }
  368.             } else {
  369.                 // 戻り完了処理
  370.                 $result $alipay->alipayComplete($request$payload['order'], $payload['orderPayment'], $error);
  371.                 if ($payload['mode'] == 'success' && $result !== false) {
  372.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  373.                 }
  374.                 // ロールバック
  375.                 $alipay->rollback($payload['order']);
  376.             }
  377.         }
  378.         if ($requestHtml) {
  379.             return new Response(
  380.                 $requestHtml,
  381.                 Response::HTTP_OK,
  382.                 [
  383.                     'Cache-Control' => 'no-store, no-cache',
  384.                     'Pragma' => 'no-cache',
  385.                     'Expires' => '0',
  386.                     'Content-Type' => 'text/html; charset=UTF-8'
  387.                 ]
  388.             );
  389.         } else {
  390.             return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  391.                 'paymentType'  => $payload['paymentType'],
  392.                 'error'        => $error,
  393.                 'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_50'],
  394.                 'orderNo'      => $payload['order']->getId(),
  395.                 'paymentInfo'  => $payload['paymentInfo'],
  396.                 'loadingImage' => $this->util->getLoadingImage(),
  397.                 'tplIsLoading' => empty($error['payment']),
  398.             ]);
  399.         }
  400.     }
  401.     /**
  402.      * 銀聯ネット決済処理
  403.      *
  404.      * @param  Request $request リクエストデータ
  405.      * @param  array   $payload 決済処理に使用するデータ
  406.      * @return object           リダイレクトレスポンス|ビューレスポンス
  407.      */
  408.     private function execUPOPProcess($request$payload)
  409.     {
  410.         $upop $this->container->get('vt4g_plugin.service.payment_upop');
  411.         $error = [
  412.             'payment' => '',
  413.         ];
  414.         $requestHtml '';
  415.         if ($request->getMethod() === 'POST') {
  416.             if ($payload['mode'] == "next") {
  417.                 $this->execIsTokenValid($upop$payload);
  418.                 $result $upop->upopCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  419.                 if ($result !== false) {
  420.                     $requestHtml $result;
  421.                 } else {
  422.                     $upop->rollback($payload['order']);
  423.                 }
  424.             }
  425.             // 銀聯ネットから戻った場合
  426.             if ($payload['mode'] == "complete") {
  427.                 $result $upop->upopComplete($request$payload['order'], $payload['orderPayment'], $error);
  428.                 if ($result){
  429.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  430.                 }else{
  431.                     $upop->rollback($payload['order']);
  432.                 }
  433.             }
  434.         }
  435.         if ($requestHtml) {
  436.             return new Response(
  437.                 $requestHtml,
  438.                 Response::HTTP_OK,
  439.                 [
  440.                     'Cache-Control' => 'no-store, no-cache',
  441.                     'Pragma' => 'no-cache',
  442.                     'Expires' => '0',
  443.                     'Content-Type' => 'text/html; charset=UTF-8'
  444.                 ]
  445.             );
  446.         } else {
  447.             // POST用リクエストパラメータ
  448.             return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  449.                 'paymentType'  => $payload['paymentType'],
  450.                 'error'        => $error,
  451.                 'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_40'],
  452.                 'orderNo'      => $payload['order']->getId(),
  453.                 'tplIsLoading' => empty($error['payment']),
  454.                 'loadingImage' => $this->util->getLoadingImage(),
  455.             ]);
  456.         }
  457.     }
  458.     /**
  459.      * 楽天ペイ処理
  460.      *
  461.      * @param  Request $request リクエストデータ
  462.      * @param  array   $payload 決済処理に使用するデータ
  463.      * @return object           リダイレクトレスポンス|ビューレスポンス
  464.      */
  465.     private function execRakutenProcess($request$payload)
  466.     {
  467.         $rakuten $this->container->get('vt4g_plugin.service.payment_rakuten');
  468.         $error   = [
  469.             'payment' => '',
  470.         ];
  471.         $requestHtml '';
  472.         if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
  473.             $this->execIsTokenValid($rakuten$payload);
  474.             $result $rakuten->rakutenCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  475.             if ($result !== false) {
  476.                 $requestHtml $result;
  477.             } else {
  478.                 $rakuten->rollback($payload['order']);
  479.             }
  480.         }
  481.         if ($request->getMethod() === 'GET') {
  482.             // 楽天から成功で戻った場合
  483.             if ($payload['mode'] == "success") {
  484.                 $result $rakuten->rakutenComplete($request$payload['order'], $payload['orderPayment'], $error);
  485.                 if ($result){
  486.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  487.                 }else{
  488.                     $rakuten->rollback($payload['order']);
  489.                 }
  490.             // 楽天からエラーで戻った場合
  491.             }elseif ($payload['mode'] == "error") {
  492.                 // エラー画面用のメッセージを設定してロールバック
  493.                 $rakuten->getResponse($request$payload['order'], $error);
  494.                 $rakuten->rollback($payload['order']);
  495.             }
  496.         }
  497.         if ($requestHtml) {
  498.             return new Response(
  499.                 $requestHtml,
  500.                 Response::HTTP_OK,
  501.                 [
  502.                     'Cache-Control' => 'no-store, no-cache',
  503.                     'Pragma' => 'no-cache',
  504.                     'Expires' => '0',
  505.                     'Content-Type' => 'text/html; charset=UTF-8'
  506.                 ]
  507.             );
  508.         } else {
  509.             return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  510.                 'paymentType'  => $payload['paymentType'],
  511.                 'error'        => $error,
  512.                 'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_60'],
  513.                 'orderNo'      => $payload['order']->getId(),
  514.                 'tplIsLoading' => empty($error['payment']),
  515.                 'loadingImage' => $this->util->getLoadingImage(),
  516.             ]);
  517.         }
  518.     }
  519.     /**
  520.      * 楽天ペイV2処理
  521.      *
  522.      * @param  Request $request リクエストデータ
  523.      * @param  array   $payload 決済処理に使用するデータ
  524.      * @return object           リダイレクトレスポンス|ビューレスポンス
  525.      */
  526.     private function execRakutenv2Process($request$payload)
  527.     {
  528.         $rakutenV2 $this->container->get('vt4g_plugin.service.payment_rakuten_v2');
  529.         $error   = [
  530.             'payment' => '',
  531.         ];
  532.         $requestHtml '';
  533.         if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
  534.             $this->execIsTokenValid($rakutenV2$payload);
  535.             $result $rakutenV2->rakutenV2Commit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  536.             if ($result !== false) {
  537.                 $requestHtml $result;
  538.             } else {
  539.                 $rakutenV2->rollback($payload['order']);
  540.             }
  541.         }
  542.         if ($request->getMethod() === 'GET') {
  543.             // 楽天から成功で戻った場合
  544.             if ($payload['mode'] == "success") {
  545.                 $result $rakutenV2->rakutenV2Complete($request$payload['order'], $payload['orderPayment'], $error);
  546.                 if ($result){
  547.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  548.                 }else{
  549.                     $rakutenV2->rollback($payload['order']);
  550.                 }
  551.             // 楽天からエラーで戻った場合
  552.             }elseif ($payload['mode'] == "error") {
  553.                 // エラー画面用のメッセージを設定してロールバック
  554.                 $rakutenV2->getResponse($request$payload['order'], $error);
  555.                 $rakutenV2->rollback($payload['order']);
  556.             }
  557.         }
  558.         if ($requestHtml) {
  559.             return new Response(
  560.                 $requestHtml,
  561.                 Response::HTTP_OK,
  562.                 [
  563.                     'Cache-Control' => 'no-store, no-cache',
  564.                     'Pragma' => 'no-cache',
  565.                     'Expires' => '0',
  566.                     'Content-Type' => 'text/html; charset=UTF-8'
  567.                 ]
  568.             );
  569.         } else {
  570.             return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  571.                 'paymentType'  => $payload['paymentType'],
  572.                 'error'        => $error,
  573.                 'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_63'],
  574.                 'orderNo'      => $payload['order']->getId(),
  575.                 'tplIsLoading' => empty($error['payment']),
  576.                 'loadingImage' => $this->util->getLoadingImage(),
  577.             ]);
  578.         }
  579.     }
  580.     /**
  581.      * リクルートかんたん支払い処理
  582.      *
  583.      * @param  Request $request リクエストデータ
  584.      * @param  array   $payload 決済処理に使用するデータ
  585.      * @return object           リダイレクトレスポンス|ビューレスポンス
  586.      */
  587.     private function execRecruitProcess($request$payload)
  588.     {
  589.         $recruit $this->container->get('vt4g_plugin.service.payment_recruit');
  590.         $error   = [
  591.             'payment' => '',
  592.         ];
  593.         if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
  594.             $this->execIsTokenValid($recruit$payload);
  595.             $result $recruit->recruitCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  596.             if ($result !== false) {
  597.                 // リクルートの画面にリダイレクト
  598.                 return $this->redirect($result);
  599.             } else {
  600.                 $recruit->rollback($payload['order']);
  601.             }
  602.         }
  603.         if ($request->getMethod() === 'GET') {
  604.             // リクルートから成功で戻った場合
  605.             if ($payload['mode'] == "success") {
  606.                 $result $recruit->recruitComplete($request$payload['order'], $payload['orderPayment'], $error);
  607.                 if ($result){
  608.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  609.                 }else{
  610.                     $recruit->rollback($payload['order']);
  611.                 }
  612.             // リクルートからエラーで戻った場合
  613.             }elseif ($payload['mode'] == "error") {
  614.                 // エラー画面用のメッセージを設定してロールバック
  615.                 $recruit->getResponse($request$payload['order'], $error);
  616.                 $recruit->rollback($payload['order']);
  617.             }
  618.         }
  619.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  620.             'paymentType'  => $payload['paymentType'],
  621.             'error'        => $error,
  622.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_61'],
  623.             'orderNo'      => $payload['order']->getId(),
  624.             'tplIsLoading' => empty($error['payment']),
  625.             'loadingImage' => $this->util->getLoadingImage(),
  626.         ]);
  627.     }
  628.     /**
  629.      * LINE Pay処理
  630.      *
  631.      * @param  Request $request リクエストデータ
  632.      * @param  array   $payload 決済処理に使用するデータ
  633.      * @return object           リダイレクトレスポンス|ビューレスポンス
  634.      */
  635.     private function execLINEPayProcess($request$payload)
  636.     {
  637.         $line $this->container->get('vt4g_plugin.service.payment_linepay');
  638.         $error   = [
  639.             'payment' => '',
  640.         ];
  641.         if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
  642.             $this->execIsTokenValid($line$payload);
  643.             $result $line->linepayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  644.             if ($result !== false) {
  645.                 // LINEの画面にリダイレクト
  646.                 return $this->redirect($result);
  647.             } else {
  648.                 $line->rollback($payload['order']);
  649.             }
  650.         }
  651.         if ($request->getMethod() === 'GET') {
  652.             // LINEから成功で戻った場合
  653.             if ($payload['mode'] == "success") {
  654.                 $result $line->linepayComplete($request$payload['order'], $payload['orderPayment'], $error);
  655.                 if ($result){
  656.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  657.                 }else{
  658.                     $line->rollback($payload['order']);
  659.                 }
  660.             // LINEからエラーで戻った場合
  661.             } elseif ($payload['mode'] == "error") {
  662.                 // エラー画面用のメッセージを設定してロールバック
  663.                 $line->getResponse($request$payload['order'], $error);
  664.                 $line->rollback($payload['order']);
  665.             // LINEからキャンセルで戻った場合
  666.             } elseif ($payload['mode'] == "cancel") {
  667.                 // レスポンスをログに出力、ロールバックしてご注文手続き画面へ
  668.                 $line->getResponse($request$payload['order'], $error);
  669.                 $line->rollback($payload['order']);
  670.                 return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
  671.             }
  672.         }
  673.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  674.             'paymentType'  => $payload['paymentType'],
  675.             'error'        => $error,
  676.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_62'],
  677.             'orderNo'      => $payload['order']->getId(),
  678.             'tplIsLoading' => empty($error['payment']),
  679.             'loadingImage' => $this->util->getLoadingImage(),
  680.         ]);
  681.     }
  682.     /**
  683.      * PayPal決済処理
  684.      *
  685.      * @param  Request $request リクエストデータ
  686.      * @param  array   $payload 決済処理に使用するデータ
  687.      * @return object           リダイレクトレスポンス|ビューレスポンス
  688.      */
  689.     private function execPayPalProcess($request$payload)
  690.     {
  691.         $paypal $this->container->get('vt4g_plugin.service.payment_paypal');
  692.         $error = [
  693.             'payment' => '',
  694.         ];
  695.         if ($request->getMethod() === 'POST' && $payload['mode'] == 'next') {
  696.             $this->execIsTokenValid($paypal$payload);
  697.             $result $paypal->PayPalCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  698.             if ($result !== false) {
  699.                 return $this->redirect($result);
  700.             } else {
  701.                 // ロールバック
  702.                 $paypal->rollback($payload['order']);
  703.             }
  704.         }
  705.         if ($request->getMethod() === 'GET') {
  706.             // paypalから成功で戻った場合
  707.             if($payload['mode'] == 'exec') {
  708.                 $result $paypal->PayPalComplete($request$payload['order'], $payload['orderPayment'], $error);
  709.                 if ($result !== false) {
  710.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  711.                 }else{
  712.                     // ロールバック
  713.                     $paypal->rollback($payload['order']);
  714.                 }
  715.             // paypalからキャンセルで戻った場合
  716.             } elseif($payload['mode'] == 'back') {
  717.                 $paypal->rollback($payload['order']);
  718.                 return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
  719.             }
  720.         }
  721.         // POST用リクエストパラメータ
  722.         return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  723.             'paymentType'  => $payload['paymentType'],
  724.             'error'        => $error,
  725.             'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_70'],
  726.             'orderNo'      => $payload['order']->getId(),
  727.             'paymentInfo'  => $payload['paymentInfo'],
  728.             'tplIsLoading' => empty($error['payment']),
  729.             'loadingImage' => $this->util->getLoadingImage()
  730.         ]);
  731.     }
  732.     /**
  733.      * PayPay処理
  734.      *
  735.      * @param  Request $request リクエストデータ
  736.      * @param  array   $payload 決済処理に使用するデータ
  737.      * @return object           リダイレクトレスポンス|ビューレスポンス
  738.      */
  739.     private function execPayPayProcess($request$payload)
  740.     {
  741.         $paypay $this->container->get('vt4g_plugin.service.payment_paypay');
  742.         $error = [
  743.             'payment' => '',
  744.         ];
  745.         $requestHtml '';
  746.         if ($request->getMethod() === 'POST') {
  747.             if ($payload['mode'] == "next") {
  748.                 $this->execIsTokenValid($paypay$payload);
  749.                 $result $paypay->PayPayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
  750.                 if ($result !== false) {
  751.                     $requestHtml $result;
  752.                 } else {
  753.                     $paypay->rollback($payload['order']);
  754.                 }
  755.             }
  756.         }
  757.         if ($request->getMethod() === 'GET'){
  758.             // PayPayから成功で戻った場合
  759.             if ($payload['mode'] == "success") {
  760.                 $result $paypay->PayPayComplete($request$payload['order'], $payload['orderPayment'], $error);
  761.                 if ($result){
  762.                     return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
  763.                 }else{
  764.                     $paypay->rollback($payload['order']);
  765.                 }
  766.             // PayPayからエラーで戻った場合
  767.             } elseif ($payload['mode'] == "error") {
  768.                 // エラー画面用のメッセージを設定してロールバック
  769.                 $paypay->getResponse($request$payload['order'], $error);
  770.                 $paypay->rollback($payload['order']);
  771.             // PayPayからキャンセルで戻った場合
  772.             } elseif ($payload['mode'] == "cancel") {
  773.                 // レスポンスをログに出力、ロールバックしてご注文手続き画面へ
  774.                 $paypay->getResponse($request$payload['order'], $error);
  775.                 $paypay->rollback($payload['order']);
  776.                 return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
  777.             }
  778.         }
  779.         if ($requestHtml) {
  780.             return new Response(
  781.                 $requestHtml,
  782.                 Response::HTTP_OK,
  783.                 [
  784.                     'Cache-Control' => 'no-store, no-cache',
  785.                     'Pragma' => 'no-cache',
  786.                     'Expires' => '0',
  787.                     'Content-Type' => 'text/html; charset=Shift_JIS',
  788.                 ]
  789.             );
  790.         } else {
  791.             // POST用リクエストパラメータ
  792.             return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
  793.                 'paymentType'  => $payload['paymentType'],
  794.                 'error'        => $error,
  795.                 'title'        => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_80'],
  796.                 'orderNo'      => $payload['order']->getId(),
  797.                 'tplIsLoading' => empty($error['payment']),
  798.                 'loadingImage' => $this->util->getLoadingImage(),
  799.             ]);
  800.         }
  801.     }
  802.     /**
  803.      * 注文IDから受注データを取得
  804.      *
  805.      * @param  integer $orderId 注文ID
  806.      * @return \Eccube\Entity\Order            Orderクラスインスタンス
  807.      */
  808.     private function getOrderById($orderId)
  809.     {
  810.         return $this->orderRepository->findOneBy([
  811.             'id' => $orderId
  812.         ]);
  813.     }
  814.     /**
  815.      * isTokenValidを実行し、例外が発生している場合はポイント等のロールバックを行う。
  816.      *
  817.      * @param  object  $paymentService   各支払のサービスクラス
  818.      * @param  array   $payload          決済処理に使用するデータ
  819.      *
  820.      * @throws AccessDeniedHttpException isTokenValidでトークンが有効ではないと判定された場合
  821.      */
  822.     private function execIsTokenValid($paymentService$payload)
  823.     {
  824.         try {
  825.             //CSRFチェック
  826.             $this->isTokenValid();
  827.         } catch (AccessDeniedHttpException $e) {
  828.             //ロールバックとエラー画面への遷移
  829.             $paymentService->rollback($payload['order']);
  830.             throw new AccessDeniedHttpException($e->getMessage());
  831.         }
  832.     }
  833. }