app/Plugin/GmoPaymentGateway42/Entity/GmoOrderPayment.php line 20

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\Entity;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Eccube\Entity\Order;
  9. use Plugin\GmoPaymentGateway42\Util\PaymentUtil;
  10. /**
  11.  * GmoOrderPayment
  12.  *
  13.  * @ORM\Table(name="plg_gmo_payment_gateway_order_payment")
  14.  * @ORM\Entity(repositoryClass="Plugin\GmoPaymentGateway42\Repository\GmoOrderPaymentRepository")
  15.  */
  16. class GmoOrderPayment
  17. {
  18.     /**
  19.      * @var int
  20.      *
  21.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue(strategy="IDENTITY")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @var int
  28.      *
  29.      * @ORM\Column(name="order_id", type="integer", options={"unsigned":true})
  30.      */
  31.     private $order_id;
  32.     /**
  33.      * @var text
  34.      *
  35.      * @ORM\Column(name="memo01", type="text", nullable=true)
  36.      */
  37.     private $memo01;
  38.     /**
  39.      * @var text
  40.      *
  41.      * @ORM\Column(name="memo02", type="text", nullable=true)
  42.      */
  43.     private $memo02;
  44.     /**
  45.      * @var text
  46.      *
  47.      * @ORM\Column(name="memo03", type="text", nullable=true)
  48.      */
  49.     private $memo03;
  50.     /**
  51.      * @var text
  52.      *
  53.      * @ORM\Column(name="memo04", type="text", nullable=true)
  54.      */
  55.     private $memo04;
  56.     /**
  57.      * @var text
  58.      *
  59.      * @ORM\Column(name="memo05", type="text", nullable=true)
  60.      */
  61.     private $memo05;
  62.     /**
  63.      * @var text
  64.      *
  65.      * @ORM\Column(name="memo06", type="text", nullable=true)
  66.      */
  67.     private $memo06;
  68.     /**
  69.      * @var text
  70.      *
  71.      * @ORM\Column(name="memo07", type="text", nullable=true)
  72.      */
  73.     private $memo07;
  74.     /**
  75.      * @var text
  76.      *
  77.      * @ORM\Column(name="memo08", type="text", nullable=true)
  78.      */
  79.     private $memo08;
  80.     /**
  81.      * @var text
  82.      *
  83.      * @ORM\Column(name="memo09", type="text", nullable=true)
  84.      */
  85.     private $memo09;
  86.     /**
  87.      * @var text
  88.      *
  89.      * @ORM\Column(name="memo10", type="text", nullable=true)
  90.      */
  91.     private $memo10;
  92.     /**
  93.      * @return int
  94.      */
  95.     public function getId()
  96.     {
  97.         return $this->id;
  98.     }
  99.     /**
  100.      * @return int
  101.      */
  102.     public function getOrderId()
  103.     {
  104.         return $this->order_id;
  105.     }
  106.     /**
  107.      * @return text
  108.      */
  109.     public function getMemo01()
  110.     {
  111.         return $this->memo01;
  112.     }
  113.     /**
  114.      * @return text
  115.      */
  116.     public function getMemo02()
  117.     {
  118.         return $this->memo02;
  119.     }
  120.     /**
  121.      * @return text
  122.      */
  123.     public function getMemo03()
  124.     {
  125.         return $this->memo03;
  126.     }
  127.     /**
  128.      * @return text
  129.      */
  130.     public function getMemo04()
  131.     {
  132.         return $this->memo04;
  133.     }
  134.     /**
  135.      * @return text
  136.      */
  137.     public function getMemo05()
  138.     {
  139.         return $this->memo05;
  140.     }
  141.     /**
  142.      * @return text
  143.      */
  144.     public function getMemo06()
  145.     {
  146.         return $this->memo06;
  147.     }
  148.     /**
  149.      * @return text
  150.      */
  151.     public function getMemo07()
  152.     {
  153.         return $this->memo07;
  154.     }
  155.     /**
  156.      * @return text
  157.      */
  158.     public function getMemo08()
  159.     {
  160.         return $this->memo08;
  161.     }
  162.     /**
  163.      * @return text
  164.      */
  165.     public function getMemo09()
  166.     {
  167.         return $this->memo09;
  168.     }
  169.     /**
  170.      * @return text
  171.      */
  172.     public function getMemo10()
  173.     {
  174.         return $this->memo10;
  175.     }
  176.     /**
  177.      * @param integer $order_id
  178.      *
  179.      * @return $this;
  180.      */
  181.     public function setOrderId($order_id)
  182.     {
  183.         $this->order_id $order_id;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @param text $memo01
  188.      *
  189.      * @return $this;
  190.      */
  191.     public function setMemo01($memo01)
  192.     {
  193.         $this->memo01 $memo01;
  194.         return $this;
  195.     }
  196.     /**
  197.      * @param text $memo02
  198.      *
  199.      * @return $this;
  200.      */
  201.     public function setMemo02($memo02)
  202.     {
  203.         $this->memo02 $memo02;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @param text $memo03
  208.      *
  209.      * @return $this;
  210.      */
  211.     public function setMemo03($memo03)
  212.     {
  213.         $this->memo03 $memo03;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @param text $memo04
  218.      *
  219.      * @return $this;
  220.      */
  221.     public function setMemo04($memo04)
  222.     {
  223.         $this->memo04 $memo04;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @param text $memo05
  228.      *
  229.      * @return $this;
  230.      */
  231.     public function setMemo05($memo05)
  232.     {
  233.         $this->memo05 $memo05;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @param text $memo06
  238.      *
  239.      * @return $this;
  240.      */
  241.     public function setMemo06($memo06)
  242.     {
  243.         $this->memo06 $memo06;
  244.         return $this;
  245.     }
  246.     /**
  247.      * @param text $memo07
  248.      *
  249.      * @return $this;
  250.      */
  251.     public function setMemo07($memo07)
  252.     {
  253.         $this->memo07 $memo07;
  254.         return $this;
  255.     }
  256.     /**
  257.      * @param text $memo08
  258.      *
  259.      * @return $this;
  260.      */
  261.     public function setMemo08($memo08)
  262.     {
  263.         $this->memo08 $memo08;
  264.         return $this;
  265.     }
  266.     /**
  267.      * @param text $memo09
  268.      *
  269.      * @return $this;
  270.      */
  271.     public function setMemo09($memo09)
  272.     {
  273.         $this->memo09 $memo09;
  274.         return $this;
  275.     }
  276.     /**
  277.      * @param text $memo10
  278.      *
  279.      * @return $this;
  280.      */
  281.     public function setMemo10($memo10)
  282.     {
  283.         $this->memo10 $memo10;
  284.         return $this;
  285.     }
  286.     /**
  287.      * AccessID および AccessPass が存在するか確認する
  288.      *
  289.      * @return boolean
  290.      */
  291.     public function isExistsAccessIDAndPass()
  292.     {
  293.         $memo05 $this->getMemo05();
  294.         if (is_null($memo05)) {
  295.             return false;
  296.         }
  297.         $data json_decode($memo05true);
  298.         if (isset($data['AccessID']) && isset($data['AccessPass'])) {
  299.             return true;
  300.         }
  301.         return false;
  302.     }
  303.     /**
  304.      * 決済画面の入力値を取得する
  305.      *
  306.      * @return GmoPaymentInput
  307.      */
  308.     public function getGmoPaymentInput()
  309.     {
  310.         $GmoPaymentInput = new GmoPaymentInput();
  311.         $data $this->getMemo01();
  312.         if (!is_null($data) && !empty($data)) {
  313.             $GmoPaymentInput->setArrayData(json_decode($datatrue));
  314.         }
  315.         return $GmoPaymentInput;
  316.     }
  317.     /**
  318.      * 決済画面の入力値をセットする
  319.      *
  320.      * @param GmoPaymentInput $GmoPaymentInput
  321.      * @return $this
  322.      */
  323.     public function setGmoPaymentInput(GmoPaymentInput $GmoPaymentInput)
  324.     {
  325.         $data $GmoPaymentInput->getArrayData();
  326.         if (empty($data)) {
  327.             $this->setMemo01(null);
  328.         } else {
  329.             $this->setMemo01(json_encode($data));
  330.         }
  331.         return $this;
  332.     }
  333.     /**
  334.      * GMO-PG インタフェース送信で必要になるOrderIDを返す
  335.      *
  336.      * @return string OrderID
  337.      */
  338.     public function getGmoOrderID()
  339.     {
  340.         $paymentLog $this->getPaymentLogData();
  341.         if (isset($paymentLog['OrderID']) &&
  342.             !is_null($paymentLog['OrderID']) &&
  343.             !empty($paymentLog['OrderID'])) {
  344.             // 生成済みのOrderIDを返す
  345.             return $paymentLog['OrderID'];
  346.         }
  347.         // 新規に生成して返す
  348.         return $this->getOrderId() . '-' date('dHis');
  349.     }
  350.     /**
  351.      * GMO-PG インタフェース送受信ログデータを保存する
  352.      *
  353.      * @param array $data 送信受信データ配列
  354.      * @param boolean $isOnlyLog ログのみ保存するどうか
  355.      * @param Order $Order 注文
  356.      * @return GmoOrderPayment
  357.      */
  358.     public function setPaymentLogData
  359.         (array $data$isOnlyLogOrder $Order null)
  360.     {
  361.         PaymentUtil::logInfo('GmoOrderPayment::setPaymentLogData start.');
  362.         if (isset($data[0]) && is_array($data[0])) {
  363.             $arrTemp $data[0];
  364.             unset($data[0]);
  365.             $data array_merge((array)$data, (array)$arrTemp);
  366.         }
  367.         foreach ($data as $key => $val) {
  368.             if (!$val || is_array($val) || preg_match('/^[\w\s]+$/i'$val)) {
  369.                 continue;
  370.             }
  371.             $char_code "UTF-8";
  372.             $temp mb_convert_encoding($val'sjis-win'$char_code);
  373.             $temp mb_convert_encoding($temp$char_code'sjis-win');
  374.             if ($val !== $temp) {
  375.                 $temp mb_convert_encoding($val$char_code'sjis-win');
  376.                 $temp mb_convert_encoding($temp'sjis-win'$char_code);
  377.                 if ($val === $temp) {
  378.                     $data[$key] =
  379.                         mb_convert_encoding($val$char_code'sjis-win');
  380.                 } else {
  381.                     $data[$key] = 'unknown encoding strings';
  382.                 }
  383.             }
  384.         }
  385.         $paymentLog = [];
  386.         $memo09 $this->getMemo09();
  387.         if (!is_null($memo09) && !empty($memo09)) {
  388.             $paymentLog json_decode($memo09true);
  389.         }
  390.         $paymentLog[] = [date('Y-m-d H:i:s') => $data];
  391.         $this->setMemo09(json_encode($paymentLog));
  392.         if (!$isOnlyLog) {
  393.             $paymentLog = [];
  394.             $memo05 $this->getMemo05();
  395.             if (!is_null($memo05) && !empty($memo05)) {
  396.                 $paymentLog json_decode($memo05true);
  397.             }
  398.             foreach ($data as $key => $val) {
  399.                 if (empty($val) && !empty($paymentLog[$key])) {
  400.                     if ($key !== 'action_status' &&
  401.                         $key !== 'pay_status') {
  402.                         unset($data[$key]);
  403.                     }
  404.                 }
  405.             }
  406.             $paymentLog array_merge($paymentLog, (array)$data);
  407.             $this->setMemo05(json_encode($paymentLog));
  408.             if (isset($data['pay_status'])) {
  409.                 $this->setMemo04($data['pay_status']);
  410.                 if (is_null($Order)) {
  411.                     return $this;
  412.                 }
  413.                 // 注文にもセットする
  414.                 $Order->setGmoPaymentGatewayPaymentStatus($data['pay_status']);
  415.                 PaymentUtil::logInfo
  416.                     ("Set payment_status = " $data['pay_status'] .
  417.                      ", order_id = " $Order->getId());
  418.             }
  419.         }
  420.         PaymentUtil::logInfo('GmoOrderPayment::setPaymentLogData end.');
  421.         return $this;
  422.     }
  423.     /**
  424.      * GMO-PG インタフェース送受信ログデータを取得する
  425.      *
  426.      * @return array 送受信ログデータ配列
  427.      */
  428.     public function getPaymentLogData()
  429.     {
  430.         $results = [];
  431.         $memo05 $this->getMemo05();
  432.         if (!is_null($memo05) && !empty($memo05)) {
  433.             $results json_decode($memo05true);
  434.         }
  435.         $results['payment_log'] = [];
  436.         $memo09 $this->getMemo09();
  437.         if (!is_null($memo09) && !empty($memo09)) {
  438.             $results['payment_log'] = json_decode($memo09true);
  439.         }
  440.         if (isset($results[0]) && is_array($results[0])) {
  441.             $arrTemp $results[0];
  442.             unset($results[0]);
  443.             $results array_merge((array)$results, (array)$arrTemp);
  444.         }
  445.         return $results;
  446.     }
  447.     /**
  448.      * 購入完了画面向けのメッセージ配列を保存する
  449.      *
  450.      * @param array $data
  451.      * @return $this
  452.      */
  453.     public function setOrderCompleteMessages(array $data)
  454.     {
  455.         $this->setMemo02(json_encode($data));
  456.         return $this;
  457.     }
  458.     /**
  459.      * 購入完了画面向けのメッセージ配列の先頭にマージする
  460.      *
  461.      * @param array $mergeData 先頭にマージするメッセージ配列
  462.      * @return $this
  463.      */
  464.     public function mergeHeadOrderCompleteMessages(array $mergeData)
  465.     {
  466.         $data = [];
  467.         $memo02 $this->getMemo02();
  468.         if (!empty($memo02)) {
  469.             $data json_decode($memo02true);
  470.         }
  471.         $data array_merge($mergeData$data);
  472.         return $this->setOrderCompleteMessages($data);
  473.     }
  474.     /**
  475.      * 購入完了画面向けのメッセージ配列を返す
  476.      *
  477.      * @return array メッセージ配列
  478.      */
  479.     public function getOrderCompleteMessages()
  480.     {
  481.         $data $this->getMemo02();
  482.         if (is_null($data) || empty($data)) {
  483.             return [];
  484.         }
  485.         $messages = [];
  486.         $data json_decode($datatrue);
  487.         if (isset($data['title'])) {
  488.             $messages[] = $data['title']['name'] . "\n";
  489.         }
  490.         foreach ($data as $key => $values) {
  491.             if ($key !== 'title') {
  492.                 $message "";
  493.                 if (!empty($values['name'])) {
  494.                     $message .= $values['name'];
  495.                 }
  496.                 if (!empty($message) && !empty($values['value'])) {
  497.                     $message .= ": ";
  498.                 }
  499.                 if (!empty($values['value'])) {
  500.                     $message .= $values['value'];
  501.                 }
  502.                 $messages[] = $message "\n";
  503.             }
  504.         }
  505.         return $messages;
  506.     }
  507.     /**
  508.      * 決済に利用したカード登録連番(物理)を返す
  509.      *
  510.      * @return integer|null カード登録連番(物理)
  511.      */
  512.     public function getCardSeq()
  513.     {
  514.         return $this->getMemo07();
  515.     }
  516.     /**
  517.      * 決済に利用したカード登録連番(物理)をセットする
  518.      *
  519.      * @param integer $cardSeq カード登録連番(物理)
  520.      * @return $this
  521.      */
  522.     public function setCardSeq($cardSeq)
  523.     {
  524.         return $this->setMemo07($cardSeq);
  525.     }
  526. }