app/Plugin/GmoPaymentGateway42/Service/PaymentHelper.php line 182

Open in your IDE?
  1. <?php
  2. /*
  3.  * Copyright(c) 2022 GMO Payment Gateway, Inc. All rights reserved.
  4.  * http://www.gmo-pg.com/
  5.  */
  6. namespace Plugin\GmoPaymentGateway42\Service;
  7. use GuzzleHttp\Client;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Eccube\Common\EccubeConfig;
  10. use Eccube\Entity\Master\OrderStatus;
  11. use Eccube\Entity\Order;
  12. use Eccube\Entity\Payment;
  13. use Eccube\Entity\Customer;
  14. use Eccube\Repository\Master\OrderStatusRepository;
  15. use Eccube\Repository\BaseInfoRepository;
  16. use Eccube\Repository\CustomerRepository;
  17. use Eccube\Repository\OrderRepository;
  18. use Eccube\Repository\PaymentRepository;
  19. use Eccube\Service\MailService;
  20. use Eccube\Service\PluginService;
  21. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  22. use Plugin\GmoPaymentGateway42\Entity\GmoConfig;
  23. use Plugin\GmoPaymentGateway42\Entity\GmoOrderPayment;
  24. use Plugin\GmoPaymentGateway42\Repository\GmoConfigRepository;
  25. use Plugin\GmoPaymentGateway42\Repository\GmoOrderPaymentRepository;
  26. use Plugin\GmoPaymentGateway42\Repository\GmoPaymentMethodRepository;
  27. use Plugin\GmoPaymentGateway42\Repository\GmoMemberRepository;
  28. use Plugin\GmoPaymentGateway42\Service\Method\Cvs;
  29. use Plugin\GmoPaymentGateway42\Service\Method\PayEasyAtm;
  30. use Plugin\GmoPaymentGateway42\Service\Method\PayEasyNet;
  31. use Plugin\GmoPaymentGateway42\Util\ErrorUtil;
  32. use Plugin\GmoPaymentGateway42\Util\PaymentUtil;
  33. use Symfony\Component\DependencyInjection\ContainerInterface;
  34. use Symfony\Component\Mailer\MailerInterface;
  35. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  36. /**
  37.  * 決済共通処理を行うクラス
  38.  */
  39. abstract class PaymentHelper
  40. {
  41.     /**
  42.      * @var ContainerInterface
  43.      */
  44.     protected $container;
  45.     /**
  46.      * @var Symfony\Component\Mailer\MailerInterface
  47.      */
  48.     protected $mailer;
  49.     /**
  50.      * @var \Twig_Environment
  51.      */
  52.     protected $twig;
  53.     /**
  54.      * @var EccubeConfig
  55.      */
  56.     protected $eccubeConfig;
  57.     /**
  58.      * @var EntityManagerInterface
  59.      */
  60.     protected $entityManager;
  61.     /**
  62.      * @var OrderRepository
  63.      */
  64.     protected $orderRepository;
  65.     /**
  66.      * @var OrderStatusRepository
  67.      */
  68.     protected $orderStatusRepository;
  69.     /**
  70.      * @var CustomerRepository
  71.      */
  72.     protected $customerRepository;
  73.     /**
  74.      * @var PaymentRepository
  75.      */
  76.     protected $paymentRepository;
  77.     /**
  78.      * @var MailService
  79.      */
  80.     protected $mailService;
  81.     /**
  82.      * @var PurchaseFlow
  83.      */
  84.     protected $purchaseFlow;
  85.     /**
  86.      * @var Plugin\GmoPaymentGateway42\Repository\GmoConfigRepository
  87.      */
  88.     protected $gmoConfigRepository;
  89.     /**
  90.      * @var Plugin\GmoPaymentGateway42\Repository\GmoOrderPaymentRepository
  91.      */
  92.     protected $gmoOrderPaymentRepository;
  93.     /**
  94.      * @var Plugin\GmoPaymentGateway42\Repository\GmoPaymentMethodRepository
  95.      */
  96.     protected $gmoPaymentMethodRepository;
  97.     /**
  98.      * @var Plugin\GmoPaymentGateway42\Repository\GmoMemberRepository
  99.      */
  100.     protected $gmoMemberRepository;
  101.     /**
  102.      * プラグインコンフィグ(composer.json)
  103.      * @var array
  104.      */
  105.     protected $pluginConfig;
  106.     /**
  107.      * @var BaseInfo
  108.      */
  109.     protected $BaseInfo;
  110.     /**
  111.      * @var Plugin\GmoPaymentGateway42\Entity\GmoConfig
  112.      */
  113.     protected $GmoConfig;
  114.     /**
  115.      * @var array Plugin\GmoPaymentGateway42\Entity\GmoPaymentMethod#Memo05
  116.      */
  117.     protected $gmoPaymentMethodConfig;
  118.     /**
  119.      * @var Plugin\GmoPaymentGateway42\Util\ErrorUtil
  120.      */
  121.     protected $errorUtil;
  122.     /**
  123.      * @var array エラー配列
  124.      */
  125.     protected $error = [];
  126.     /**
  127.      * @var array GMO-PG インタフェース送信結果配列
  128.      */
  129.     protected $results null;
  130.     /**
  131.      * @var Plugin\GmoPaymentGateway42\Service\FraudDetector
  132.      */
  133.     protected $fraudDetector;
  134.     /**
  135.      * PaymentHelper constructor.
  136.      *
  137.      * @param ContainerInterface $container
  138.      * @param MailerInterface $mailer
  139.      * @param \Twig_Environment $twig
  140.      * @param EccubeConfig $eccubeConfig
  141.      * @param EntityManagerInterface $entityManager
  142.      * @param PluginService $pluginService
  143.      * @param OrderRepository $orderRepository
  144.      * @param OrderStatusRepository $orderStatusRepository
  145.      * @param BaseInfoRepository $baseInfoRepository
  146.      * @param CustomerRepository $customerRepository
  147.      * @param PaymentRepository $paymentRepository
  148.      * @param MailService $mailService
  149.      * @param PurchaseFlow $shoppingPurchaseFlow
  150.      * @param GmoConfigRepository $gmoConfigRepository
  151.      * @param GmoMemberRepository $gmoMemberRepository
  152.      * @param ErrorUtil $errorUtil
  153.      * @param FraudDetector $fraudDetector
  154.      */
  155.     public function __construct(
  156.         ContainerInterface $container,
  157.         MailerInterface $mailer,
  158.         \Twig_Environment $twig,
  159.         EccubeConfig $eccubeConfig,
  160.         EntityManagerInterface $entityManager,
  161.         PluginService $pluginService,
  162.         OrderRepository $orderRepository,
  163.         OrderStatusRepository $orderStatusRepository,
  164.         BaseInfoRepository $baseInfoRepository,
  165.         CustomerRepository $customerRepository,
  166.         PaymentRepository $paymentRepository,
  167.         MailService $mailService,
  168.         PurchaseFlow $shoppingPurchaseFlow,
  169.         GmoConfigRepository $gmoConfigRepository,
  170.         GmoOrderPaymentRepository $gmoOrderPaymentRepository,
  171.         GmoPaymentMethodRepository $gmoPaymentMethodRepository,
  172.         GmoMemberRepository $gmoMemberRepository,
  173.         ErrorUtil $errorUtil,
  174.         FraudDetector $fraudDetector
  175.     ) {
  176.         $this->container $container;
  177.         $this->mailer $mailer;
  178.         $this->twig $twig;
  179.         $this->eccubeConfig $eccubeConfig;
  180.         $this->entityManager $entityManager;
  181.         $this->orderRepository $orderRepository;
  182.         $this->orderStatusRepository $orderStatusRepository;
  183.         $this->customerRepository $customerRepository;
  184.         $this->paymentRepository $paymentRepository;
  185.         $this->mailService $mailService;
  186.         $this->purchaseFlow $shoppingPurchaseFlow;
  187.         $this->gmoConfigRepository $gmoConfigRepository;
  188.         $this->gmoOrderPaymentRepository $gmoOrderPaymentRepository;
  189.         $this->gmoPaymentMethodRepository $gmoPaymentMethodRepository;
  190.         $this->gmoMemberRepository $gmoMemberRepository;
  191.         $this->errorUtil $errorUtil;
  192.         $this->fraudDetector $fraudDetector;
  193.         // プラグインコンフィグ(composer.json)を取得
  194.         $dir $pluginService->calcPluginDir(PaymentUtil::PLUGIN_CODE);
  195.         $this->pluginConfig $pluginService->readConfig($dir);
  196.         // 店舗設定を取得
  197.         $this->BaseInfo $baseInfoRepository->get();
  198.         // GMO-PG プラグイン設定を取得
  199.         $this->GmoConfig $this->gmoConfigRepository->get();
  200.         // GMO-PG 支払方法別の設定を取得
  201.         $this->gmoPaymentMethodConfig $this->getGmoPaymentMethodConfig();
  202.     }
  203.     /**
  204.      * GMO-PG 支払方法別のクラス名称を取得する(継承先の支払別Helperで実装)
  205.      *
  206.      * @return string 支払方法別のクラス名称
  207.      */
  208.     abstract protected function getGmoPaymentMethodClass();
  209.     /**
  210.      * GMO-PG 支払方法別の設定を取得する
  211.      *
  212.      * @return array 支払方法別の設定配列
  213.      */
  214.     protected function getGmoPaymentMethodConfig()
  215.     {
  216.         $className $this->getGmoPaymentMethodClass();
  217.         if (is_null($className)) {
  218.             return [];
  219.         }
  220.         return $this->gmoPaymentMethodRepository
  221.             ->getGmoPaymentMethodConfig($className);
  222.     }
  223.     /**
  224.      * 顧客に GMO-PG 情報を付加する
  225.      *
  226.      * @param Eccube\Entity\Customer $Customer
  227.      * @return Eccube\Entity\Customer
  228.      */
  229.     public function prepareGmoInfoForCustomer(Customer $Customer null)
  230.     {
  231.         if (is_null($Customer)) {
  232.             return $Customer;
  233.         }
  234.         PaymentUtil::logInfo
  235.             ('prepareGmoInfoForCustomer customer_id = ' $Customer->getId());
  236.         $GmoMember $this->gmoMemberRepository
  237.             ->findOneBy(['customer_id' => $Customer->getId()]);
  238.         $Customer->setGmoMember($GmoMember);
  239.         return $Customer;
  240.     }
  241.     /**
  242.      * 注文に GMO-PG 情報を付加する
  243.      *
  244.      * @param Eccube\Entity\Order $Order
  245.      * @return Eccube\Entity\Order
  246.      */
  247.     public function prepareGmoInfoForOrder(Order $Order)
  248.     {
  249.         if (is_null($Order)) {
  250.             return $Order;
  251.         }
  252.         PaymentUtil::logInfo
  253.             ('prepareGmoInfoForOrder order_id = ' $Order->getId());
  254.         // 注文の追加情報
  255.         $GmoOrderPayment $this->gmoOrderPaymentRepository
  256.             ->findOneBy(['order_id' => $Order->getId()]);
  257.         if (is_null($GmoOrderPayment)) {
  258.             // なければ生成する
  259.             $order_id $Order->getId();
  260.             $GmoOrderPayment = new GmoOrderPayment();
  261.             $GmoOrderPayment->setOrderId($order_id);
  262.             $this->entityManager->persist($GmoOrderPayment);
  263.             $this->entityManager->flush($GmoOrderPayment);
  264.             PaymentUtil::logInfo
  265.                 ("Create GmoOrderPayment order_id = " $order_id);
  266.         }
  267.         $Order->setGmoOrderPayment($GmoOrderPayment);
  268.         // 決済画面の入力値をセット
  269.         $GmoPaymentInput $GmoOrderPayment->getGmoPaymentInput();
  270.         $Order->setGmoPaymentInput($GmoPaymentInput);
  271.         PaymentUtil::logInfo($GmoPaymentInput->getArrayData(), [
  272.             'Pass',
  273.             'Token',
  274.             'card_name'
  275.         ]);
  276.         // 支払方法の追加情報
  277.         $Payment $Order->getPayment();
  278.         if (!is_null($Payment)) {
  279.             $GmoPaymentMethod $this->gmoPaymentMethodRepository
  280.                 ->findOneBy(['payment_id' => $Payment->getId()]);
  281.             $Order->setGmoPaymentMethod($GmoPaymentMethod);
  282.             $GmoOrderPayment->setMemo03($Payment->getMethodClass());
  283.             $this->entityManager->persist($GmoOrderPayment);
  284.             $this->entityManager->flush($GmoOrderPayment);
  285.         }
  286.         // 顧客の追加情報
  287.         $this->prepareGmoInfoForCustomer($Order->getCustomer());
  288.         return $Order;
  289.     }
  290.     /**
  291.      * 支払方法の一致確認を行う
  292.      *
  293.      * @param Order $Order
  294.      * @return boolean true: 一致、false: 不一致
  295.      */
  296.     public function isMatchPayment(Order $Order)
  297.     {
  298.         $methodClass $this->getGmoPaymentMethodClass();
  299.         $order_id $Order->getId();
  300.         $Payment $Order->getPayment();
  301.         if (!$Payment) {
  302.             PaymentUtil::logError("order_id: " $order_id ", " .
  303.                                   "Payment is null, " .
  304.                                   "method_class: " $methodClass);
  305.             return false;
  306.         }
  307.         $payment_id $Payment->getId();
  308.         $method_class $Payment->getMethodClass();
  309.         PaymentUtil::logInfo
  310.             ("order_id: " $order_id ", " .
  311.              "payment_id: " $payment_id ", " .
  312.              "method_class: " $method_class " | " $methodClass);
  313.         if ($method_class !== $methodClass) {
  314.             PaymentUtil::logError(trans('gmo_payment_gateway.' .
  315.                                         'shopping.com.mismatch.payment'));
  316.             return false;
  317.         }
  318.         return true;
  319.     }
  320.     /**
  321.      * GMO-PG インタフェース送信データを生成し取得する
  322.      *
  323.      * @param array $paramNames パラメータ名配列
  324.      * @param array $sourceData ソースデータ配列
  325.      * @param Order $Order 受注Entity
  326.      * @param Customer $Customer 顧客Entity
  327.      * @return array 送信データ配列
  328.      */
  329.     protected function getIfSendData
  330.         (array $paramNames, array $sourceData,
  331.          Order $Order nullCustomer $Customer null)
  332.     {
  333.         $results = [];
  334.         $paymentLogData = [];
  335.         if (!is_null($Order)) {
  336.             $GmoOrderPayment $Order->getGmoOrderPayment();
  337.             $paymentLogData $GmoOrderPayment->getPaymentLogData();
  338.         }
  339.         foreach ($paramNames as $paramName) {
  340.             PaymentUtil::logInfo('getIfSendData::$paramName ' $paramName);
  341.             $function "getIf" $paramName;
  342.             if (is_callable([$this$function])) {
  343.                 $r $this->$function($sourceData$Order$Customer);
  344.                 if ($r !== null) {
  345.                     $results[$paramName] = $r;
  346.                 }
  347.             } else {
  348.                 if (isset($sourceData[$paramName])) {
  349.                     $results[$paramName] = $sourceData[$paramName];
  350.                 } elseif (isset($paymentLogData[$paramName])) {
  351.                     $results[$paramName] = $paymentLogData[$paramName];
  352.                 } elseif (isset($this->gmoPaymentMethodConfig[$paramName])) {
  353.                     $results[$paramName] =
  354.                         $this->gmoPaymentMethodConfig[$paramName];
  355.                 } elseif (method_exists($this->GmoConfig,
  356.                                         "get" $paramName)) {
  357.                     $method "get" $paramName;
  358.                     $results[$paramName] = $this->GmoConfig->$method();
  359.                 } elseif (isset($this->results[0][$paramName])) {
  360.                     $results[$paramName] = $this->results[0][$paramName];
  361.                 }
  362.             }
  363.         }
  364.         return $results;
  365.     }
  366.         
  367.     /**
  368.      * ショップID
  369.      */
  370.     private function getIfShopID
  371.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  372.     {
  373.         return $this->GmoConfig->getShopId();
  374.     }
  375.     /**
  376.      * ショップパスワード
  377.      */
  378.     private function getIfShopPass
  379.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  380.     {
  381.         return $this->GmoConfig->getShopPass();
  382.     }
  383.     /**
  384.      * サイトID
  385.      */
  386.     private function getIfSiteID
  387.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  388.     {
  389.         return $this->GmoConfig->getSiteId();
  390.     }
  391.     /**
  392.      * サイトパスワード
  393.      */
  394.     private function getIfSitePass
  395.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  396.     {
  397.         return $this->GmoConfig->getSitePass();
  398.     }
  399.     /**
  400.      * 加盟店自由項目3
  401.      *
  402.      * ※この部分の表記などについて修正・削除等、一切の変更は絶対に
  403.      * 行わないで下さい。問題発生時の調査や解決などに支障が出るため、
  404.      * 変更された場合はサポート等が出来ない場合がございます。
  405.      */
  406.     private function getIfClientField3
  407.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  408.     {
  409.         // Get composer.json plugin version
  410.         return 'EC-CUBE4.2(' $this->pluginConfig['version'] . ')';
  411.     }
  412.     /**
  413.      * キャンセル金額
  414.      */
  415.     private function getIfCancelAmount
  416.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  417.     {
  418.         $GmoOrderPayment $Order->getGmoOrderPayment();
  419.         $paymentLogData $GmoOrderPayment->getPaymentLogData();
  420.         $cancelAmount $Order->getDecPaymentTotal();
  421.         if (isset($sourceData['CancelAmount'])) {
  422.             $cancelAmount $sourceData['CancelAmount'];
  423.         } else if (isset($paymentLogData['Amount'])) {
  424.             $cancelAmount $paymentLogData['Amount'];
  425.         }
  426.         return $cancelAmount;
  427.     }
  428.     /**
  429.      * 利用金額
  430.      */
  431.     private function getIfAmount
  432.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  433.     {
  434.         return $Order->getDecPaymentTotal();
  435.     }
  436.     /**
  437.      * 初回課金利用金額
  438.      */
  439.     private function getIfFirstAmount
  440.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  441.     {
  442.         return $Order->getDecPaymentTotal();
  443.     }
  444.     /**
  445.      * 3Dセキュア表示店舗名
  446.      */
  447.     private function getIfTdTenantName
  448.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  449.     {
  450.         $tenantName $this->gmoPaymentMethodConfig['TdTenantName'];
  451.         return PaymentUtil::convTdTenantName($tenantName);
  452.     }
  453.     /**
  454.      * 有効期限
  455.      */
  456.     private function getIfExpire
  457.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  458.     {
  459.         return $sourceData['expire_year'] . $sourceData['expire_month'];
  460.     }
  461.     /**
  462.      * 支払方法
  463.      */
  464.     private function getIfMethod
  465.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  466.     {
  467.         if (strpos($sourceData['Method'], '-') !== false) {
  468.             list($id$num) = explode('-'$sourceData['Method']);
  469.             return $id;
  470.         }
  471.         return $sourceData['Method'];
  472.     }
  473.     /**
  474.      * 支払回数
  475.      */
  476.     private function getIfPayTimes
  477.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  478.     {
  479.         if (isset($sourceData['PayTimes']) && $sourceData['PayTimes'] > 0) {
  480.             return $sourceData['PayTimes'];
  481.         }
  482.         if (strpos($sourceData['Method'], '-') === false) {
  483.             return null;
  484.         }
  485.         list($id$num) = explode('-'$sourceData['Method']);
  486.         if ($num <= 0) {
  487.             return null;
  488.         }
  489.         return $num;
  490.     }
  491.     /**
  492.      * セキュリティコード
  493.      */
  494.     private function getIfSecurityCode
  495.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  496.     {
  497.         if (isset($sourceData['security_code']) &&
  498.             !empty($sourceData['security_code'])) {
  499.             return $sourceData['security_code'];
  500.         }
  501.         return null;
  502.     }
  503.     /**
  504.      * 加盟店自由項目返却フラグ
  505.      */
  506.     private function getIfClientFieldFlag
  507.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  508.     {
  509.         return '1';
  510.     }
  511.     /**
  512.      * 本人認証サービス利用フラグ
  513.      */
  514.     private function getIfTdFlag
  515.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  516.     {
  517.         if (isset($sourceData['TdFlag'])) {
  518.             return $sourceData['TdFlag'];
  519.         }
  520.         return $this->gmoPaymentMethodConfig['TdFlag'];
  521.     }
  522.     /**
  523.      * HTTP_ACCEPT
  524.      */
  525.     private function getIfHttpAccept
  526.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  527.     {
  528.         if (!isset($_SERVER['HTTP_ACCEPT'])) {
  529.             return null;
  530.         }
  531.         return $_SERVER['HTTP_ACCEPT'];
  532.     }
  533.     /**
  534.      * HTTP_USER_AGENT
  535.      */
  536.     private function getIfHttpUserAgent
  537.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  538.     {
  539.         if (!isset($_SERVER['HTTP_USER_AGENT'])) {
  540.             return null;
  541.         }
  542.         return $_SERVER['HTTP_USER_AGENT'];
  543.     }
  544.     /**
  545.      * 使用端末情報
  546.      */
  547.     private function getIfDeviceCategory
  548.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  549.     {
  550.         return '0';
  551.     }
  552.     /**
  553.      * 会員名
  554.      */
  555.     private function getIfMemberName
  556.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  557.     {
  558.         if (is_null($Order) && is_null($Customer)) {
  559.             return null;
  560.         }
  561.         if (!is_null($Order) && is_null($Order->getCustomer())) {
  562.             return null;
  563.         }
  564.         if (is_null($Order)) {
  565.             if (!is_null($Customer->getSecretKey())) {
  566.                 return $Customer->getSecretKey();
  567.             } else if (!is_null($Customer->getId()) &&
  568.                        $Customer->getId() !== '0') {
  569.                 $readCustomer $this->customerRepository->findOneBy([
  570.                     'id' => $Customer->getId(),
  571.                     'del_flg' => 0,
  572.                 ]);
  573.                 if (!is_null($readCustomer)) {
  574.                     return $readCustomer->getSecretKey();
  575.                 }
  576.             }
  577.             return null;
  578.         }
  579.         if (!is_null($Order->getCustomer()->getSecretKey())) {
  580.             return $Order->getCustomer()->getSecretKey();
  581.         } else if (!is_null($Order->getCustomer()->getId()) &&
  582.                    $Order->getCustomer()->getId() !== '0') {
  583.             $readCustomer $this->customerRepository->findOneBy([
  584.                 'id' => $Order->getCustomer()->getId(),
  585.                 'del_flg' => 0,
  586.             ]);
  587.             if (!is_null($readCustomer)) {
  588.                 return $readCustomer->getSecretKey();
  589.             }
  590.         }
  591.         return null;
  592.     }
  593.     /**
  594.      * 氏名
  595.      */
  596.     private function getIfCustomerName
  597.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  598.     {
  599.         return PaymentUtil::convCVSText($Order->getName01() .
  600.                                         $Order->getName02());
  601.     }
  602.     /**
  603.      * フリガナ
  604.      */
  605.     private function getIfCustomerKana
  606.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  607.     {
  608.         return PaymentUtil::convCVSText($Order->getKana01() .
  609.                                         $Order->getKana02());
  610.     }
  611.     /**
  612.      * 電話番号
  613.      */
  614.     private function getIfTelNo
  615.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  616.     {
  617.         return $Order->getPhoneNumber();
  618.     }
  619.     /**
  620.      * 結果通知先メールアドレス
  621.      */
  622.     private function getIfMailAddress
  623.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  624.     {
  625.         $mail null;
  626.         $config $this->gmoPaymentMethodConfig;
  627.         $Payment null;
  628.         if (is_null($Order) || is_null($Payment $Order->getPayment())) {
  629.             return $mail;
  630.         }
  631.         switch ($Payment->getMethodClass()) {
  632.         case Cvs::class:
  633.             // コンビニ
  634.             $code $sourceData['Convenience'];
  635.             if ($config['enable_mail'] == "1" &&
  636.                 in_array($code$config['enable_cvs_mails'])) {
  637.                 $mail $Order->getEmail();
  638.             }
  639.             break;
  640.         case PayEasyAtm::class:
  641.         case PayEasyNet::class:
  642.             // ペイジー
  643.             if ($config['enable_mail'] == "1") {
  644.                 $mail $Order->getEmail();
  645.                 if (!empty($sourceData['MailAddress'])) {
  646.                     $mail $sourceData['MailAddress'];
  647.                 }
  648.             }
  649.             break;
  650.         default:
  651.             break;
  652.         }
  653.         return $mail;
  654.     }
  655.     /**
  656.      * 加盟店メールアドレス
  657.      */
  658.     private function getIfShopMailAddress
  659.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  660.     {
  661.         return $this->BaseInfo->getEmail01();
  662.     }
  663.     /**
  664.      * 予約番号
  665.      */
  666.     private function getIfReserveNo
  667.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  668.     {
  669.         return $Order->getId();
  670.     }
  671.     /**
  672.      * 会員番号
  673.      */
  674.     private function getIfMemberNo
  675.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  676.     {
  677.         $customerId null;
  678.         if (!is_null($Order) && !is_null($Order->getCustomer())) {
  679.             $customerId $Order->getCustomer()->getId();
  680.         } else if (!is_null($Customer)) {
  681.             $customerId $Customer->getId();
  682.         }
  683.         return $customerId;
  684.     }
  685.     /**
  686.      * 会員ID
  687.      */
  688.     private function getIfMemberID
  689.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  690.     {
  691.         $customerId $this->getIfMemberNo($sourceData$Order$Customer);
  692.         if (empty($customerId)) {
  693.             return null;
  694.         }
  695.         /* Create Gmo memeber id from customer id
  696.          * Only apply for payment method RegistCredit and CVS
  697.          */
  698.         $gmoMemberId $this->gmoMemberRepository->getGmoMemberId($customerId);
  699.         if (is_null($gmoMemberId)) {
  700.             // Create new member id
  701.             $gmoMemberId =
  702.                 $this->gmoMemberRepository->createGmoMemberId($customerId);
  703.             if (is_null($gmoMemberId)) {
  704.                 return null;
  705.             }
  706.             // Save member id into plg_gmo_payment_gateway_member
  707.             $this->gmoMemberRepository
  708.                 ->updateOrCreate($customerId$gmoMemberId);
  709.             $this->entityManager->flush();
  710.         }
  711.         return $gmoMemberId;
  712.     }
  713.     /**
  714.      * 表示電話番号
  715.      */
  716.     private function getIfServiceTel
  717.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  718.     {
  719.         return $this->gmoPaymentMethodConfig['ServiceTel_1'] . '' .
  720.                $this->gmoPaymentMethodConfig['ServiceTel_2'] . '' .
  721.                $this->gmoPaymentMethodConfig['ServiceTel_3'];
  722.     }
  723.     /**
  724.      * お問合せ先電話番号
  725.      */
  726.     private function getIfReceiptsDisp12
  727.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  728.     {
  729.         return $this->gmoPaymentMethodConfig['ReceiptsDisp12_1'] . '' .
  730.                $this->gmoPaymentMethodConfig['ReceiptsDisp12_2'] . '' .
  731.                $this->gmoPaymentMethodConfig['ReceiptsDisp12_3'];
  732.     }
  733.     /**
  734.      * お問合せ先受付時間
  735.      */
  736.     private function getIfReceiptsDisp13
  737.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  738.     {
  739.         return
  740.             sprintf('%02d',
  741.                     $this->gmoPaymentMethodConfig['ReceiptsDisp13_1']) . ':' .
  742.             sprintf('%02d',
  743.                     $this->gmoPaymentMethodConfig['ReceiptsDisp13_2']) . '-' .
  744.             sprintf('%02d',
  745.                     $this->gmoPaymentMethodConfig['ReceiptsDisp13_3']) . ':' .
  746.             sprintf('%02d',
  747.                     $this->gmoPaymentMethodConfig['ReceiptsDisp13_4']);
  748.     }
  749.     /**
  750.      * 会員作成フラグ
  751.      */
  752.     private function getIfCreateMember
  753.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  754.     {
  755.         return '1';
  756.     }
  757.     /**
  758.      * 名義人
  759.      */
  760.     private function getIfHolderName
  761.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  762.     {
  763.         if (!isset($sourceData['card_name1']) &&
  764.             isset($sourceData['HolderName'])) {
  765.             return $sourceData['HolderName'];
  766.         }
  767.         return $sourceData['card_name1'] . ' ' $sourceData['card_name2'];
  768.     }
  769.     /**
  770.      * オーダーID
  771.      */
  772.     private function getIfOrderID
  773.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  774.     {
  775.         return $sourceData['OrderID'];
  776.     }
  777.     /**
  778.      * 税送料
  779.      */
  780.     private function getIfTax
  781.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  782.     {
  783.         return '';
  784.     }
  785.     /**
  786.      * パラメータバージョン
  787.      */
  788.     private function getIfVerSion
  789.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  790.     {
  791.         return '';
  792.     }
  793.     /**
  794.      * クレジットトークン
  795.      */
  796.     private function getIfToken
  797.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  798.     {
  799.         return $sourceData['token'];
  800.     }
  801.     /**
  802.      * カード登録連番モード
  803.      */
  804.     private function getIfSeqMode
  805.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  806.     {
  807.         return '1';
  808.     }
  809.     /**
  810.      * カード登録連番
  811.      */
  812.     private function getIfCardSeq
  813.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  814.     {
  815.         if (!isset($sourceData['CardSeq'])) {
  816.             return null;
  817.         }
  818.         return $sourceData['CardSeq'];
  819.     }
  820.     /**
  821.      * 決済タイプ
  822.      */
  823.     private function getIfPaymentType
  824.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  825.     {
  826.         return 'E';
  827.     }
  828.     /**
  829.      * 3DS2.0 3DS必須タイプ
  830.      */
  831.     private function getIfTdRequired
  832.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  833.     {
  834.         if (empty($this->gmoPaymentMethodConfig['TdRequired'])) {
  835.             return '0';
  836.         }
  837.         return $this->gmoPaymentMethodConfig['TdRequired'];
  838.     }
  839.     /**
  840.      * 3DS2.0 カード会員最終更新日(YYYYMMDD)
  841.      */
  842.     private function getIfTds2ChAccChange
  843.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  844.     {
  845.         // ゲストの場合
  846.         if (is_null($Customer) || $Customer->getId() == 0) {
  847.             return null;
  848.         }
  849.         return $Customer->getUpdateDate()->format('Ymd');
  850.     }
  851.     /**
  852.      * 3DS2.0 カード会員作成日(YYYYMMDD)
  853.      */
  854.     private function getIfTds2ChAccDate
  855.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  856.     {
  857.         // ゲストの場合
  858.         if (is_null($Customer) || $Customer->getId() == 0) {
  859.             return null;
  860.         }
  861.         return $Customer->getCreateDate()->format('Ymd');
  862.     }
  863.     /**
  864.      * 3DS2.0 カード会員名と配送先名の一致/不一致
  865.      */
  866.     private function getIfTds2ShipNameInd
  867.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  868.     {
  869.         $Shipping $Order->getShippings()[0];
  870.         if (is_null($Shipping)) {
  871.             return null;
  872.         }
  873.         $o_name $Order->getName01() . $Order->getName02();
  874.         $s_name $Shipping->getName01() . $Shipping->getName02();
  875.         if (strcmp($o_name$s_name) == 0) {
  876.             return '01';
  877.         }
  878.         return '02';
  879.     }
  880.     /**
  881.      * 3DS2.0 請求先住所の国コード
  882.      */
  883.     private function getIfTds2BillAddrCountry
  884.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  885.     {
  886.         // 392 固定
  887.         return '392';
  888.     }
  889.     /**
  890.      * 3DS2.0 請求先住所の区域部分の1行目
  891.      */
  892.     private function getIfTds2BillAddrLine1
  893.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  894.     {
  895.         $addr $Order->getPref()->getName() . $Order->getAddr01();
  896.         return PaymentUtil::subString($addr50);
  897.     }
  898.     /**
  899.      * 3DS2.0 請求先住所の区域部分の2行目
  900.      */
  901.     private function getIfTds2BillAddrLine2
  902.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  903.     {
  904.         return PaymentUtil::subString($Order->getAddr02(), 50);
  905.     }
  906.     /**
  907.      * 3DS2.0 請求先住所の郵便番号
  908.      */
  909.     private function getIfTds2BillAddrPostCode
  910.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  911.     {
  912.         return $Order->getPostalCode();
  913.     }
  914.     /**
  915.      * 3DS2.0 請求先住所の都道府県番号(00)
  916.      */
  917.     private function getIfTds2BillAddrState
  918.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  919.     {
  920.         return sprintf('%02s'$Order->getPref()->getId());
  921.     }
  922.     /**
  923.      * 3DS2.0 カード会員のメールアドレス
  924.      */
  925.     private function getIfTds2Email
  926.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  927.     {
  928.         return $Order->getEmail();
  929.     }
  930.     /**
  931.      * 3DS2.0 配送先住所の国コード
  932.      */
  933.     private function getIfTds2ShipAddrCountry
  934.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  935.     {
  936.         // 392 固定
  937.         return '392';
  938.     }
  939.     /**
  940.      * 3DS2.0 配送先住所の区域部分の1行目
  941.      */
  942.     private function getIfTds2ShipAddrLine1
  943.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  944.     {
  945.         $Shipping $Order->getShippings()[0];
  946.         if (is_null($Shipping)) {
  947.             return null;
  948.         }
  949.         $addr $Shipping->getPref()->getName() . $Shipping->getAddr01();
  950.         return PaymentUtil::subString($addr50);
  951.     }
  952.     /**
  953.      * 3DS2.0 配送先住所の区域部分の2行目
  954.      */
  955.     private function getIfTds2ShipAddrLine2
  956.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  957.     {
  958.         $Shipping $Order->getShippings()[0];
  959.         if (is_null($Shipping)) {
  960.             return null;
  961.         }
  962.         return PaymentUtil::subString($Shipping->getAddr02(), 50);
  963.     }
  964.     /**
  965.      * 3DS2.0 配送先住所の郵便番号
  966.      */
  967.     private function getIfTds2ShipAddrPostCode
  968.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  969.     {
  970.         $Shipping $Order->getShippings()[0];
  971.         if (is_null($Shipping)) {
  972.             return null;
  973.         }
  974.         return $Shipping->getPostalCode();
  975.     }
  976.     /**
  977.      * 3DS2.0 配送先住所の都道府県番号(00)
  978.      */
  979.     private function getIfTds2ShipAddrState
  980.         (array $sourceDataOrder $Order nullCustomer $Customer null)
  981.     {
  982.         $Shipping $Order->getShippings()[0];
  983.         if (is_null($Shipping)) {
  984.             return null;
  985.         }
  986.         return sprintf('%02s'$Shipping->getPref()->getId());
  987.     }
  988.     /**
  989.      * GMO-PG 注文に関するインタフェース送受信を行う
  990.      *
  991.      * @param Order $Order 注文
  992.      * @param string $url リクエスト先
  993.      * @param array $paramNames 送信するパラメータ名配列
  994.      * @param array $sendData 送信データ配列
  995.      * @return boolean
  996.      */
  997.     protected function sendOrderRequest
  998.         (Order $Order$url, array $paramNames, array $sendData)
  999.     {
  1000.         PaymentUtil::logInfo('PaymentHelper::sendOrderRequest start.');
  1001.         $bkData $sendData;
  1002.         // OrderID を取得してセット
  1003.         $OrderID $Order->getGmoOrderPayment()->getGmoOrderID();
  1004.         $sendData['OrderID'] = $OrderID;
  1005.         // 送信データを取得
  1006.         $data $this->getIfSendData
  1007.             ($paramNames$sendData$Order$Order->getCustomer());
  1008.         // 送信受信
  1009.         $ret $this->sendRequest($url$data);
  1010.         if ($ret) {
  1011.             $sendData $this->getResults();
  1012.         } else {
  1013.             $sendData = [];
  1014.             $sendData[0]['request_error'] = $this->getError();
  1015.         }
  1016.         $sendData[0]['OrderID'] = $OrderID;
  1017.         $sendData[0]['Amount'] = $Order->getDecPaymentTotal();
  1018.         if (!empty($bkData['JobCd'])) {
  1019.             $sendData[0]['JobCd'] = $bkData['JobCd'];
  1020.         } else if (isset($this->gmoPaymentMethodConfig['JobCd']) &&
  1021.                    !is_null($this->gmoPaymentMethodConfig['JobCd'])) {
  1022.             $sendData[0]['JobCd'] = $this->gmoPaymentMethodConfig['JobCd'];
  1023.         }
  1024.         if (isset($bkData['CardSeq']) && !is_null($bkData['CardSeq'])) {
  1025.             $sendData[0]['CardSeq'] = $bkData['CardSeq'];
  1026.         }
  1027.         if (!is_null($bkData['action_status'])) {
  1028.             $sendData[0]['action_status'] = $bkData['action_status'];
  1029.         }
  1030.         if (isset($bkData['pay_status']) && !is_null($bkData['pay_status'])) {
  1031.             $sendData[0]['pay_status'] = $bkData['pay_status'];
  1032.         }
  1033.         $error $this->getError();
  1034.         if (!is_null($bkData['success_pay_status']) && empty($error)) {
  1035.             $sendData[0]['pay_status'] = $bkData['success_pay_status'];
  1036.         } else if (!is_null($bkData['fail_pay_status']) && !empty($error)) {
  1037.             $sendData[0]['pay_status'] = $bkData['fail_pay_status'];
  1038.         }
  1039.         // 送受信ログデータを保存
  1040.         $GmoOrderPayment $Order->getGmoOrderPayment();
  1041.         $GmoOrderPayment->setPaymentLogData($sendDatafalse$Order);
  1042.         // カード登録連番(物理)を保存
  1043.         if (isset($sendData[0]['CardSeq'])) {
  1044.             $GmoOrderPayment->setCardSeq($sendData[0]['CardSeq']);
  1045.         }
  1046.         $this->entityManager->persist($Order);
  1047.         $this->entityManager->persist($GmoOrderPayment);
  1048.         $this->entityManager->flush();
  1049.         if (!empty($this->error)) {
  1050.             return false;
  1051.         }
  1052.         // 成功時のみ表示用データの構築(購入完了画面/メール向け)
  1053.         $this->setOrderCompleteMessages($Order);
  1054.         PaymentUtil::logInfo('PaymentHelper::sendOrderRequest end.');
  1055.         return true;
  1056.     }
  1057.     /**
  1058.      * GMO-PG インタフェースの送受信を行う
  1059.      *
  1060.      * @param string $url リクエスト先
  1061.      * @param array $sendData 送信データ配列
  1062.      * @return boolean 処理結果
  1063.      */
  1064.     protected function sendRequest($url$sendData)
  1065.     {
  1066.         $this->resetError();
  1067.         PaymentUtil::logInfo($sendData);
  1068.         $data = [];
  1069.         foreach ($sendData as $key => $value) {
  1070.             $data[$key] = mb_convert_encoding($value'SJIS-win''UTF-8');
  1071.         }
  1072.         $client = new Client(['curl.options' => ['CURLOPT_SSLVERSION' => 6]]);
  1073.         $response $client->post($url, ['form_params' => $data]);
  1074.         $r_code $response->getStatusCode();
  1075.         switch ($r_code) {
  1076.         case 200:
  1077.             break;
  1078.         case 404:
  1079.             $msg trans('gmo_payment_gateway.' .
  1080.                          'payment_helper.error3') . $r_code;
  1081.             $this->setError($msg);
  1082.             return false;
  1083.             break;
  1084.         case 500:
  1085.         default:
  1086.             $msg trans('gmo_payment_gateway.' .
  1087.                          'payment_helper.error4') . $r_code;
  1088.             $this->setError($msg);
  1089.             return false;
  1090.             break;
  1091.         }
  1092.         $response_body $response->getBody()->getContents();
  1093.         if (is_null($response_body)) {
  1094.             $msg trans('gmo_payment_gateway.payment_helper.error5');
  1095.             $this->setError($msg);
  1096.             return false;
  1097.         }
  1098.         $arrRet $this->parseResponse($response_body);
  1099.         $this->setResults($arrRet);
  1100.         if (!empty($this->error)) {
  1101.             return false;
  1102.         }
  1103.         return true;
  1104.     }
  1105.     public function setError($msg)
  1106.     {
  1107.         $this->error[] = $msg;
  1108.         PaymentUtil::logError($msg);
  1109.     }
  1110.     public function getError()
  1111.     {
  1112.         return $this->error;
  1113.     }
  1114.     public function resetError()
  1115.     {
  1116.         $this->error = [];
  1117.         PaymentUtil::logInfo("PaymentHelper reset error.");
  1118.     }
  1119.     /**
  1120.      * レスポンスを解析する
  1121.      *
  1122.      * @param string $string レスポンス
  1123.      * @return array 解析結果
  1124.      */
  1125.     protected function parseResponse($string)
  1126.     {
  1127.         $arrRet = array();
  1128.         $string trim($string);
  1129.         if (strpos($string'ACS=1') === 0) {
  1130.             $regex '|^ACS=1&ACSUrl\=(.+?)&PaReq\=(.+?)&MD\=(.+?)$|';
  1131.             $ret preg_match_all($regex$string$matches);
  1132.             if ($ret !== false && $ret 0) {
  1133.                 $arrRet[0]['ACS'] = '1';
  1134.                 $arrRet[0]['ACSUrl'] = $matches[1][0];
  1135.                 $arrRet[0]['PaReq'] = $matches[2][0];
  1136.                 $arrRet[0]['MD'] = $matches[3][0];
  1137.             } else {
  1138.                 $this->setError(trans('gmo_payment_gateway.' .
  1139.                                       'payment_helper.error1'));
  1140.             }
  1141.         } else if (strpos($string'ACS=2') === 0) {
  1142.             $regex '|^ACS=2&RedirectUrl\=(.+?)$|';
  1143.             $ret preg_match_all($regex$string$matches);
  1144.             if ($ret !== false && $ret 0) {
  1145.                 $arrRet[0]['ACS'] = '2';
  1146.                 $arrRet[0]['RedirectUrl'] = $matches[1][0];
  1147.             } else {
  1148.                 $this->setError(trans('gmo_payment_gateway.' .
  1149.                                       'payment_helper.error1'));
  1150.             }
  1151.         } else {
  1152.             $arrTmpAnd explode('&'$string);
  1153.             foreach ($arrTmpAnd as $eqString) {
  1154.                 // $eqString -> CardSeq=2|0|1, DefaultFlag=0|0|0...
  1155.                 $pos strpos($eqString'=');
  1156.                 $key substr($eqString0$pos);
  1157.                 $val substr($eqString$pos 1);
  1158.                 if (strpos($key'<') !== FALSE ||
  1159.                     strpos($key'>') !== FALSE) {
  1160.                     $this->setError(trans('gmo_payment_gateway.' .
  1161.                                           'payment_helper.error2'));
  1162.                     continue;
  1163.                 }
  1164.                 // $val -> 2|0|1, 0|0|0, ...
  1165.                 if (preg_match('/|/'$val)) {
  1166.                     $arrTmpl explode('|'$val);
  1167.                     $max count($arrTmpl);
  1168.                     for ($i 0$i $max$i++) {
  1169.                         $arrRet[$i][$key] = trim($arrTmpl[$i]);
  1170.                     }
  1171.                     // $val -> 2, 0, 1...
  1172.                 } else {
  1173.                     $arrRet[0][$key] = trim($val);
  1174.                 }
  1175.             }
  1176.         }
  1177.         if (isset($arrRet[0]['ErrCode'])) {
  1178.             $this->setError($this->createErrCode($arrRet));
  1179.         }
  1180.         return $arrRet;
  1181.     }
  1182.     /**
  1183.      * エラーコード文字列を構築する
  1184.      *
  1185.      * @param array $arrRet
  1186.      * @return string
  1187.      */
  1188.     protected function createErrCode($arrRet)
  1189.     {
  1190.         $msg '';
  1191.         foreach ($arrRet as $key => $ret) {
  1192.             if (is_array($ret)) {
  1193.                 $errorMsg =
  1194.                     $this->errorUtil->lfGetErrorInformation($ret['ErrInfo']);
  1195.                 $error_text =
  1196.                     empty($errorMsg['message']) ?
  1197.                     $errorMsg['context'] : $errorMsg['message'];
  1198.                 $msg .= $error_text '(' .
  1199.                     sprintf('%s-%s'$ret['ErrCode'], $ret['ErrInfo']) .
  1200.                     '),';
  1201.             } else if ($key == 'ErrInfo') {
  1202.                 if (preg_match('/|/'$ret)) {
  1203.                     $arrTmplInfo explode('|'$ret);
  1204.                     $arrTmplCode explode('|'$arrRet['ErrCode']);
  1205.                 } else {
  1206.                     $arrTmplInfo = array($ret);
  1207.                     $arrTmplCode = array($ret['ErrCode']);
  1208.                 }
  1209.                 foreach ($arrTmplInfo as $key2 => $err) {
  1210.                     $errorMsg $this->errorUtil->lfGetErrorInformation($err);
  1211.                     $error_text = empty($errorMsg['message']) ?
  1212.                         $errorMsg['context'] : $errorMsg['message'];
  1213.                     $msg .= $error_text '(' .
  1214.                         sprintf('%s-%s',
  1215.                                 $arrTmplCode[$key2],
  1216.                                 $arrTmplInfo[$key2]) .
  1217.                         '),';
  1218.                 }
  1219.             }
  1220.         }
  1221.         $msg substr($msg0strlen($msg) - 1); // 最後の,をカット
  1222.         return $msg;
  1223.     }
  1224.     /**
  1225.      * GMO-PG インタフェース送信結果をセット
  1226.      */
  1227.     protected function setResults($results)
  1228.     {
  1229.         $this->results $results;
  1230.         PaymentUtil::logInfo($results);
  1231.     }
  1232.     /**
  1233.      * GMO-PG インタフェース送信結果を取得
  1234.      */
  1235.     protected function getResults()
  1236.     {
  1237.         if (is_null($this->results[0]) && !is_null($this->results)) {
  1238.             return $this->results;
  1239.         }
  1240.         return $this->results[0];
  1241.     }
  1242.     /**
  1243.      * 決済毎に購入完了画面およびメールに表示する内容を生成する
  1244.      * 決済毎のヘルパーでオーバーライドして実装すること
  1245.      *
  1246.      * @param Order $Order
  1247.      * @return array 表示データ配列
  1248.      */
  1249.     protected function makeOrderCompleteMessages(Order $Order)
  1250.     {
  1251.         return [];
  1252.     }
  1253.     /**
  1254.      * 購入完了画面およびメールに表示する内容を保存する
  1255.      *
  1256.      * @param Order $Order
  1257.      */
  1258.     protected function setOrderCompleteMessages(Order $Order)
  1259.     {
  1260.         $data $this->makeOrderCompleteMessages($Order);
  1261.         if (!empty($data)) {
  1262.             $GmoPaymentMethod $Order->getGmoPaymentMethod();
  1263.             $data['title']['value'] = '1';
  1264.             $data['title']['name'] = $GmoPaymentMethod->getPaymentMethod();
  1265.             // 改行を追加
  1266.             $data['lf']['name'] = '';
  1267.             $data['lf']['value'] = '';
  1268.             $GmoOrderPayment $Order->getGmoOrderPayment();
  1269.             $GmoOrderPayment->setOrderCompleteMessages($data);
  1270.             $this->entityManager->persist($GmoOrderPayment);
  1271.             $this->entityManager->flush($GmoOrderPayment);
  1272.         }
  1273.     }
  1274.     /**
  1275.      * 決済ステータス配列を取得する
  1276.      */
  1277.     public function getPaymentStatuses()
  1278.     {
  1279.         $const $this->eccubeConfig;
  1280.         $prefix "gmo_payment_gateway.pay_status.";
  1281.         return [
  1282.             $const[$prefix 'unsettled'] => trans($prefix 'unsettled'),
  1283.             $const[$prefix 'request_success'] =>
  1284.                 trans($prefix 'request_success'),
  1285.             $const[$prefix 'reqsales'] => trans($prefix 'reqsales'),
  1286.             $const[$prefix 'reqcancel'] => trans($prefix 'reqcancel'),
  1287.             $const[$prefix 'reqchange'] => trans($prefix 'reqchange'),
  1288.             $const[$prefix 'paysuccess'] => trans($prefix 'paysuccess'),
  1289.             $const[$prefix 'paystart'] => trans($prefix 'paystart'),
  1290.             $const[$prefix 'expired'] => trans($prefix 'expired'),
  1291.             $const[$prefix 'cancel'] => trans($prefix 'cancel'),
  1292.             $const[$prefix 'fail'] => trans($prefix 'fail'),
  1293.             $const[$prefix 'auth'] => trans($prefix 'auth'),
  1294.             $const[$prefix 'commit'] => trans($prefix 'commit'),
  1295.             $const[$prefix 'sales'] => trans($prefix 'sales'),
  1296.             $const[$prefix 'capture'] => trans($prefix 'capture'),
  1297.             $const[$prefix 'void'] => trans($prefix 'void'),
  1298.             $const[$prefix 'return'] => trans($prefix 'return'),
  1299.             $const[$prefix 'returnx'] => trans($prefix 'returnx'),
  1300.             $const[$prefix 'sauth'] => trans($prefix 'sauth'),
  1301.             $const[$prefix 'check'] => trans($prefix 'check'),
  1302.             $const[$prefix 'except'] => trans($prefix 'except'),
  1303.             $const[$prefix 'trading'] => trans($prefix 'trading'),
  1304.             $const[$prefix 'stop'] => trans($prefix 'stop'),
  1305.         ];
  1306.     }
  1307.     /**
  1308.      * 決済ステータス名称を取得する
  1309.      *
  1310.      * @param int $pay_status 取引状態値
  1311.      * @return string 取引状態
  1312.      */
  1313.     public function getPaymentStatusName($pay_status)
  1314.     {
  1315.         $statuses $this->getPaymentStatuses();
  1316.         return isset($statuses[$pay_status]) ? $statuses[$pay_status] : '';
  1317.     }
  1318.     /**
  1319.      * 対応状況(注文ステータス)から 7:決済処理中、8:購入処理中
  1320.      * を除外したステータス配列を取得する
  1321.      *
  1322.      * @return array 対応状況配列
  1323.      */
  1324.     public function getOrderStatuses()
  1325.     {
  1326.         $results = [];
  1327.         $OrderStatuses $this->orderStatusRepository
  1328.             ->findNotContainsBy(['id' => [OrderStatus::PENDING,
  1329.                                           OrderStatus::PROCESSING]]);
  1330.         foreach ($OrderStatuses as $OrderStatus) {
  1331.             $results[$OrderStatus->getId()] = $OrderStatus->getName();
  1332.         }
  1333.         return $results;
  1334.     }
  1335.     /**
  1336.      * GMO-PGの決済一覧を返す
  1337.      *
  1338.      * @return array 決済配列
  1339.      */
  1340.     public function getGmoPayments()
  1341.     {
  1342.         $results = [];
  1343.         $GmoPaymentMethods $this->gmoPaymentMethodRepository
  1344.             ->findBy([], ['payment_id' => 'ASC']);
  1345.         foreach ($GmoPaymentMethods as $GmoPaymentMethod) {
  1346.             $results[$GmoPaymentMethod->getPaymentId()]
  1347.                 = $GmoPaymentMethod->getPaymentMethod();
  1348.         }
  1349.         return $results;
  1350.     }
  1351. }