app/Plugin/EccubePaymentLite42/Controller/Admin/Store/GmoEpsilonConfigController.php line 22

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite42\Controller\Admin\Store;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Eccube\Common\EccubeConfig;
  5. use Eccube\Controller\AbstractController;
  6. use Eccube\Entity\Payment;
  7. use Eccube\Repository\Master\SaleTypeRepository;
  8. use Eccube\Repository\PaymentRepository;
  9. use Plugin\EccubePaymentLite42\Entity\Config;
  10. use Plugin\EccubePaymentLite42\Entity\GmoEpsilonPayment;
  11. use Plugin\EccubePaymentLite42\Form\Type\Admin\ConfigType;
  12. use Plugin\EccubePaymentLite42\Repository\ConfigRepository;
  13. use Plugin\EccubePaymentLite42\Service\GmoEpsilonRequestService;
  14. use Plugin\EccubePaymentLite42\Service\GmoEpsilonUrlService;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Component\Form\FormError;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. class GmoEpsilonConfigController extends AbstractController
  20. {
  21.     /**
  22.      * @var EccubeConfig
  23.      */
  24.     protected $eccubeConfig;
  25.     /**
  26.      * @var ConfigRepository
  27.      */
  28.     protected $configRepository;
  29.     /**
  30.      * @var PaymentRepository
  31.      */
  32.     protected $paymentRepository;
  33.     /**
  34.      * @var GmoEpsilonRequestService
  35.      */
  36.     protected $gmoEpsilonRequestService;
  37.     /**
  38.      * @var SaleTypeRepository
  39.      */
  40.     protected $saleTypeRepository;
  41.     /**
  42.      * @var GmoEpsilonUrlService
  43.      */
  44.     private $gmoEpsilonUrlService;
  45.     public function __construct(
  46.         EccubeConfig $eccubeConfig,
  47.         ConfigRepository $configRepository,
  48.         PaymentRepository $paymentRepository,
  49.         GmoEpsilonRequestService $gmoEpsilonRequestService,
  50.         SaleTypeRepository $saleTypeRepository,
  51.         GmoEpsilonUrlService $gmoEpsilonUrlService
  52.     ) {
  53.         $this->eccubeConfig $eccubeConfig;
  54.         $this->configRepository $configRepository;
  55.         $this->paymentRepository $paymentRepository;
  56.         $this->gmoEpsilonRequestService $gmoEpsilonRequestService;
  57.         $this->saleTypeRepository $saleTypeRepository;
  58.         $this->gmoEpsilonUrlService $gmoEpsilonUrlService;
  59.     }
  60.     /**
  61.      * @Route(
  62.      *     "/%eccube_admin_route%/eccube_payment_lite/store/plugin/config", name="eccube_payment_lite42_admin_config"
  63.      * )
  64.      * @Template("@EccubePaymentLite42/admin/config.twig")
  65.      */
  66.     public function index(Request $request)
  67.     {
  68.         /** @var Config $Config */
  69.         $Config $this->configRepository->find(1);
  70.         $originalIpBlackList = new ArrayCollection();
  71.         foreach ($Config->getIpBlackList() as $list) {
  72.             $originalIpBlackList->add($list);
  73.         }
  74.         $form $this->createForm(ConfigType::class, $Config);
  75.         $form->handleRequest($request);
  76.         // ssl対応判定
  77.         if (!extension_loaded('openssl')) {
  78.             $form['environmental_setting']->addError(new FormError('※ このサーバはSSLに対応していません。'));
  79.         }
  80.         if ($form->isSubmitted() && $form->isValid()) {
  81.             /** @var Config $Config */
  82.             $Config $form->getData();
  83.             $st_code '';
  84.             $paymentIds $Config->getGmoEpsilonPayments()->map(function ($GmoEpsilonPayment) {
  85.                 return $GmoEpsilonPayment->getId();
  86.             })->toArray();
  87.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['credit'], $paymentIds) ? '1' '0';
  88.             $st_code .= '0'// credit 2
  89.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['conveni'], $paymentIds) ? '1' '0';
  90.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['netbank_jnb'], $paymentIds) ? '1' '0';
  91.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['netbank_rakuten'], $paymentIds) ? '1' '0';
  92.             $st_code .= '-0'// "-" unused 6
  93.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['payeasy'], $paymentIds) ? '1' '0';
  94.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['webmoney'], $paymentIds) ? '1' '0';
  95.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['ywallet'], $paymentIds) ? '1' '0';
  96.             $st_code .= '-0'// "-" unused 10
  97.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['paypal'], $paymentIds) ? '1' '0';
  98.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['bitcash'], $paymentIds) ? '1' '0';
  99.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['chocom'], $paymentIds) ? '1' '0';
  100.             $st_code .= '0-'// unused 14
  101.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['sphone'], $paymentIds) ? '1' '0';
  102.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['jcb'], $paymentIds) ? '1' '0';
  103.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['sumishin'], $paymentIds) ? '1' '0';
  104.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['deferred'], $paymentIds) ? '1' '0';
  105.             $st_code .= '0-00';
  106.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['virtual_account'], $paymentIds) ? '1' '0';
  107.             $st_code .= '00-';
  108.             $st_code .= in_array($this->eccubeConfig['gmo_epsilon']['pay_id']['paypay'], $paymentIds) ? '1' '0';
  109.             $st_code .= '0000-00000';
  110.             $arrParameter = [
  111.                 'contract_code' => $Config->getContractCode(),
  112.                 'user_id' => 'connect_test',
  113.                 'user_name' => '接続テスト',
  114.                 'user_mail_add' => 'test@test.co.jp',
  115.                 'st_code' => $st_code,
  116.                 'process_code' => '3',
  117.                 'xml' => '1',
  118.             ];
  119.             $arrXML $this->gmoEpsilonRequestService->sendData(
  120.                 $this->gmoEpsilonUrlService->getUrl('receive_order3'),
  121.                 $arrParameter
  122.             );
  123.             $err_code $this->gmoEpsilonRequestService->getXMLValue($arrXML'RESULT''ERR_CODE');
  124.             switch ($err_code) {
  125.                 case '':
  126.                     break;
  127.                 case '607':
  128.                     $form['contract_code']->addError(new FormError('※ 契約コードが違います。'));
  129.                     break;
  130.                 default:
  131.                     $form['contract_code']->addError(new FormError('※ '.$this->gmoEpsilonRequestService->getXMLValue($arrXML'RESULT''ERR_DETAIL')));
  132.                     break;
  133.             }
  134.             if ($form->isValid()) {
  135.                 // 決済方法を追加
  136.                 $this->savePaymentData($Config->getGmoEpsilonPayments());
  137.                 $this->entityManager->persist($Config);
  138.                 $this->entityManager->flush();
  139.                 $this->addSuccess('gmo_epsilon.admin.save.success''admin');
  140.                 return $this->redirectToRoute('eccube_payment_lite42_admin_config');
  141.             }
  142.         }
  143.         return [
  144.             'form' => $form->createView(),
  145.         ];
  146.     }
  147.     public function savePaymentData($GmoEpsilonPayments)
  148.     {
  149.         $Payment $this->paymentRepository->findOneBy([], ['sort_no' => 'DESC']);
  150.         $sortNo $Payment $Payment->getSortNo() + 1;
  151.         foreach ($GmoEpsilonPayments as $GmoEpsilonPayment) {
  152.             /** @var GmoEpsilonPayment $GmoEpsilonPayment */
  153.             /** @var Payment $Payment */
  154.             $Payment $this->paymentRepository->findOneBy(['method_class' => $GmoEpsilonPayment->getMethodClass()]);
  155.             if (is_null($Payment)) {
  156.                 $Payment = new Payment();
  157.                 $Payment->setCharge($GmoEpsilonPayment->getCharge());
  158.                 $Payment->setSortNo($sortNo);
  159.                 $Payment->setVisible(true);
  160.                 $Payment->setMethod($GmoEpsilonPayment->getName());
  161.                 $Payment->setMethodClass($GmoEpsilonPayment->getMethodClass());
  162.                 $Payment->setRuleMin($GmoEpsilonPayment->getRuleMin());
  163.                 $Payment->setRuleMax($GmoEpsilonPayment->getRuleMax());
  164.                 $Payment->setVisible(true);
  165.             } else {
  166.                 $Payment->setVisible(true);
  167.             }
  168.             $this->entityManager->persist($Payment);
  169.             $sortNo++;
  170.         }
  171.     }
  172.     /**
  173.      * Button update payment table
  174.      *
  175.      * @Route(
  176.      *     "/%eccube_admin_route%/eccube_payment_lite/store/plugin/update_payment_table",
  177.      *     name="eccube_payment_lite42_admin_update_payment_table"
  178.      * )
  179.      */
  180.     public function updatePaymentData()
  181.     {
  182.         $Payments $this->paymentRepository->findBy([], ['sort_no' => 'ASC']);
  183.         $gmoEpsilon4 $this->eccubeConfig['gmo_epsilon']['payment']['gmo_epsilon4'];
  184.         $ecPaymentLite4 $this->eccubeConfig['gmo_epsilon']['payment']['ec_payment_lite4'];
  185.         $arrPaymentGmo = [];
  186.         $arrPaymentLite4 = [];
  187.         if (isset($Payments)) {
  188.             foreach ($Payments as $payment) {
  189.                 if (strpos($payment->getMethodClass(), $gmoEpsilon4)) {
  190.                     $arrPaymentGmo[] = $payment;
  191.                 } elseif (strpos($payment->getMethodClass(), $ecPaymentLite4)) {
  192.                     $arrPaymentLite4[] = $payment;
  193.                 }
  194.             }
  195.             try {
  196.                 foreach ($arrPaymentGmo as $paymentGmo) {
  197.                     $method_class str_replace($gmoEpsilon4$ecPaymentLite4$paymentGmo->getMethodClass());
  198.                     $paymentGmo->setMethodClass($method_class);
  199.                     $this->entityManager->persist($paymentGmo);
  200.                     $this->entityManager->flush();
  201.                     foreach ($arrPaymentLite4 as $paymentLite4) {
  202.                         if ($paymentGmo->getMethod() === $paymentLite4->getMethod()) {
  203.                             $this->paymentRepository->delete($paymentLite4);
  204.                             $this->entityManager->flush();
  205.                         }
  206.                     }
  207.                 }
  208.                 $this->addSuccess('gmo_epsilon.admin.save.update_success''admin');
  209.             } catch (\Exception $exception) {
  210.                 log_info('Update Payment Data Error: '.$exception->getMessage());
  211.                 $this->addError('gmo_epsilon.admin.save.failed''admin');
  212.             }
  213.         } else {
  214.             $this->addError('gmo_epsilon.admin.save.failed''admin');
  215.         }
  216.         return $this->redirectToRoute('eccube_payment_lite42_admin_config');
  217.     }
  218. }