app/Plugin/ASJPayment/Controller/SendController.php line 104

Open in your IDE?
  1. <?php
  2. namespace Plugin\ASJPayment\Controller;
  3. use Eccube\Controller\AbstractController;
  4. use Eccube\Common\Constant;
  5. use Eccube\Entity\Master\OrderStatus;
  6. use Eccube\Entity\Order;
  7. use Eccube\Entity\Plugin;
  8. use Eccube\Repository\Master\OrderStatusRepository;
  9. use Eccube\Repository\OrderRepository;
  10. use Eccube\Repository\ClassCategoryRepository;
  11. use Eccube\Repository\ProductClassRepository;
  12. use Eccube\Repository\PluginRepository;
  13. use Eccube\Service\CartService;
  14. use Eccube\Service\ShoppingService;
  15. use Plugin\ASJPayment\Repository\ConfigRepository;
  16. use Plugin\ASJRegular\Repository\ASJRegularConfigRepository;
  17. use Plugin\ASJRegular\Repository\ASJRegularProductRegularKindRepository;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\HttpFoundation\Cookie;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. use Symfony\Component\DependencyInjection\ContainerInterface;
  24. class SendController extends AbstractController
  25. {
  26.     /**
  27.      * @var OrderRepository
  28.      */
  29.     protected $orderRepository;
  30.     /**
  31.      * @var OrderStatusRepository
  32.      */
  33.     protected $orderStatusRepository;
  34.     /**
  35.      * @var CartService
  36.      */
  37.     protected $cartService;
  38.     /**
  39.      * @var PluginRepository
  40.      */
  41.     protected $pluginRepository;
  42.     /**
  43.      * @var ConfigRepository
  44.      */
  45.     protected $configRepository;
  46.     /**
  47.      * @var array
  48.      */
  49.     private $chargeTypes = [
  50.         'Plugin\ASJPayment\Service\Method\Credit' => 1,
  51.         'Plugin\ASJPayment\Service\Method\Cvs' => 2,
  52.         'Plugin\ASJPayment\Service\Method\Cvs2' => 3,
  53.         'Plugin\ASJPayment\Service\Method\Atodene' => 4,
  54.         'Plugin\ASJPayment\Service\Method\Atobarai' => 7,
  55.     ];
  56.     /**
  57.      * SendController constructor.
  58.      *
  59.      * @param OrderRepository $orderRepository
  60.      * @param OrderStatusRepository $orderStatusRepository
  61.      * @param CartService $cartService
  62.      * @param PluginRepository $pluginRepository
  63.      * @param ConfigRepository $configRepository
  64.      */
  65.     public function __construct(
  66.         OrderRepository $orderRepository,
  67.         OrderStatusRepository $orderStatusRepository,
  68.         CartService $cartService,
  69.         PluginRepository $pluginRepository,
  70.         ConfigRepository $configRepository,
  71.     ?ASJRegularConfigRepository $ASJRegularConfigRepository,
  72.     ProductClassRepository $ProductClassRepository,
  73.     ClassCategoryRepository $ClassCategoryRepository
  74.     ) {
  75.         $this->orderRepository $orderRepository;
  76.         $this->orderStatusRepository $orderStatusRepository;
  77.         $this->cartService $cartService;
  78.         $this->pluginRepository $pluginRepository;
  79.         $this->configRepository $configRepository;
  80.     $this->ASJRegularConfigRepository $ASJRegularConfigRepository;
  81.     $this->ProductClassRepository $ProductClassRepository;
  82.     $this->ClassCategoryRepository $ClassCategoryRepository;
  83.     }
  84.     /**
  85.      * @Route("/shopping/ASJPayment/send", name="asj_payment_send")
  86.      *
  87.      * @param Request $request
  88.      */
  89.     public function send(Request $requestContainerInterface $container)
  90.     {
  91.         $Config $this->configRepository->get();
  92.         $preOrderId $this->cartService->getPreOrderId();
  93.         $Order $this->orderRepository->findOneBy(['pre_order_id' => $preOrderId]);
  94.         $methodClass $Order->getPayment()->getMethodClass();
  95.         $chargeType $this->chargeTypes[$methodClass];
  96.         if (!$chargeType) {
  97.             return $this->redirectToRoute('shopping_error');
  98.         }
  99.         $Plugin $this->pluginRepository->findOneBy(['code' => 'ASJPayment']);
  100.     if ($this->isGranted('IS_AUTHENTICATED_FULLY') && $chargeType == && $Config->getCardRetention() == 1) {
  101.         $unix_time time();
  102.         $var_key_param 'admin='.$Config->getCreditId().'&amount='.(int)$Order->getPaymentTotal().'&charge='.$Order->getId().'&user='.$Order->getCustomer()->getId().'&time='.$unix_time.'&'.mb_convert_encoding($Config->getCardRetentionPass(), 'EUC-JP''auto');
  103.         $arrSendData = [
  104.             'admin' => $Config->getCreditId(),
  105.             'charge' => $Order->getId(),
  106.             'amount' => (int)$Order->getPaymentTotal(),
  107.             'mail' => $Order->getEmail(),
  108.             'name' => htmlspecialchars($Order->getName01().' '.$Order->getName02(), ENT_QUOTES),
  109.             'charge_type' => $chargeType,
  110.                     'user' => $Order->getCustomer()->getId(),
  111.                     'time' => $unix_time,
  112.                     'key' => hash("sha256"$var_key_param),
  113.             'version' => Constant::VERSION'_' .$Plugin->getVersion(),
  114.             'free1' => $Order->getOrderNo()
  115.         ];
  116.     } else {
  117.             $arrSendData = [
  118.                 'admin' => $Config->getCreditId(),
  119.                 'charge' => $Order->getId(),
  120.                 'amount' => (int)$Order->getPaymentTotal(),
  121.                 'mail' => $Order->getEmail(),
  122.                 'name' => htmlspecialchars($Order->getName01().' '.$Order->getName02(), ENT_QUOTES),
  123.                 'charge_type' => $chargeType,
  124.                 'version' => Constant::VERSION'_' .$Plugin->getVersion(),
  125.                 'free1' => $Order->getOrderNo()
  126.             ];
  127.     }
  128.         if ($chargeType == 3) {
  129.             $arrSendData += [
  130.                 'zip1' => substr($Order->getPostalCode(), 03),
  131.                 'zip2' => substr($Order->getPostalCode(), 34),
  132.                 'state' => $Order->getPref(),
  133.                 'city' => $Order->getAddr01(),
  134.                 'street' => $Order->getAddr02(),
  135.                 'tel' => $Order->getPhoneNumber(),
  136.             ];
  137.         } else if ($chargeType == || $chargeType == 7) {
  138.             $arrSendData += [
  139.                 'zip1' => substr($Order->getPostalCode(), 03),
  140.                 'zip2' => substr($Order->getPostalCode(), 34),
  141.                 'state' => $Order->getPref()->getId(),
  142.                 'city' => htmlspecialchars($Order->getAddr01(), ENT_QUOTES),
  143.                 'street' => htmlspecialchars($Order->getAddr02(), ENT_QUOTES),
  144.                 'tel' => substr($Order->getPhoneNumber(), 03).'-'.substr($Order->getPhoneNumber(), 34).'-'.substr($Order->getPhoneNumber(), 7),
  145.             ];
  146.             foreach ($Order->getShippings() as $Shipping) {
  147.                 $arrSendData += [
  148.                     'ship_name' => htmlspecialchars($Shipping->getName01().' '.$Shipping->getName02(), ENT_QUOTES),
  149.                     'ship_zip1' => substr($Shipping->getPostalCode(), 03),
  150.                     'ship_zip2' => substr($Shipping->getPostalCode(), 34),
  151.                     'ship_state' => $Shipping->getPref()->getId(),
  152.                     'ship_city' => htmlspecialchars($Shipping->getAddr01(), ENT_QUOTES),
  153.                     'ship_street' => htmlspecialchars($Shipping->getAddr02(), ENT_QUOTES),
  154.                     'ship_tel' => substr($Shipping->getPhoneNumber(), 03).'-'.substr($Shipping->getPhoneNumber(), 34).'-'.substr($Shipping->getPhoneNumber(), 7),
  155.                 ];
  156.             }
  157.             $i 1;
  158.             foreach ($Order->getOrderItems() as $OrderItem) {
  159.                 if ((int)$OrderItem->getPriceIncTax()) {
  160.                     $arrSendData += [
  161.                         'item'.$i => htmlspecialchars($OrderItem->getProductName(), ENT_QUOTES),
  162.                         'price'.$i => (int)$OrderItem->getPriceIncTax(),
  163.                         'count'.$i => $OrderItem->getQuantity(),
  164.                     ];
  165.                     $i++;
  166.                 }
  167.             }
  168.         } else {
  169.             $Plugin2 $this->pluginRepository->findOneBy(['code' => 'ASJRegular''enabled' => true]);
  170.             $count 0;
  171.             foreach ($Order->getOrderItems() as $OrderItem) {
  172.                 if($OrderItem->isProduct()) {
  173.                     $Product $OrderItem->getProduct();
  174.                     $ProductClass $OrderItem->getProductClass();
  175.                     $count++;
  176.                 }
  177.             }
  178.             if ($Plugin2 && $count == 1) {
  179.                 $Config2 $this->ASJRegularConfigRepository->find(1);
  180.                 if(!$Product->hasProductClass()) {
  181.                     if($Config2->getSaleType() == $this->ProductClassRepository->findOneBy(['Product' => $Product'ClassCategory1' => null'ClassCategory2' => null])->getSaleType()) {
  182.                         $RegularKind $Product->getRegularKind();
  183.                         $arrSendData += [
  184.                             'regular' => 'on',
  185.                             'regular_kind' => $RegularKind->getId(),
  186.                             'min_day' => $Config2->getMinDay(),
  187.                         ];
  188.                         if ($Order->getDiscount() > 0) {
  189.                             $arrSendData += [
  190.                                 'regular_amount' => $Order->getPaymentTotal() + $Order->getDiscount(),
  191.                             ];
  192.                         }
  193.                     }
  194.                 } else {
  195.                     if($Config2->getSaleType() == $ProductClass->getSaleType()) {
  196.                         $RegularKind $ProductClass->getRegularKind();
  197.                         $arrSendData += [
  198.                             'regular' => 'on',
  199.                             'regular_kind' => $RegularKind->getId(),
  200.                             'min_day' => $Config2->getMinDay(),
  201.                         ];
  202.                         if ($Order->getDiscount() > 0) {
  203.                             $arrSendData += [
  204.                                 'regular_amount' => $Order->getPaymentTotal() + $Order->getDiscount(),
  205.                             ];
  206.                         }
  207.                     }
  208.                 }
  209.             }
  210.         }
  211.         // Chrome時特別処理
  212.         if(version_compare(Constant::VERSION'4.0.4''<')) {
  213.             $useragent $request->server->get('HTTP_USER_AGENT');
  214.             if(strpos($useragent'Chrome/') !== false && strpos($useragent'Edge/') === false) {
  215.                 // セッションクッキーの設定をみて置き換えるかどうか
  216.                 $cookieopt session_get_cookie_params();
  217.                 $re_cookie true;
  218.                     if($cookieopt['secure'] === true && isset($cookieopt['samesite']) && strcasecmp($cookieopt['samesite'], "none")) {
  219.                     $re_cookie false;
  220.                 }
  221.                 // セッションがクッキーとして発行されていたならセッションの設定を変更して再開する
  222.                 if($re_cookie === true && in_array(session_name(), $request->cookies->keys())) {
  223.                     session_write_close();
  224.                     session_set_cookie_params($cookieopt["lifetime"], $cookieopt["path"]."; SameSite=None"$cookieopt["domain"], true$cookieopt["httponly"]);
  225.                     session_start();
  226.                 }
  227.             }
  228.         }
  229.         return $this->render('@ASJPayment/default/send.twig', [
  230.             'action' => $Config->getCreditUrl(),
  231.             'arrSendData' => $arrSendData,
  232.         ]);
  233.     }
  234.     /**
  235.      * @Route("/shopping/ASJPayment/cvs", name="asj_payment_cvs")
  236.      *
  237.      * @param Request $request
  238.      */
  239.     public function cvs(Request $request)
  240.     {
  241.         $Config $this->configRepository->get();
  242.         $preOrderId $this->session->get('pre_order_id');
  243.         $Order $this->orderRepository->findOneBy(['pre_order_id' => $preOrderId]);
  244.         $Plugin $this->pluginRepository->findOneBy(['code' => 'ASJPayment']);
  245.         $arrSendData = [
  246.             'admin' => $Config->getCreditId(),
  247.             'charge' => $Order->getId(),
  248.             'amount' => (int)$Order->getPaymentTotal(),
  249.             'mail' => $Order->getEmail(),
  250.             'name' => htmlspecialchars($Order->getName01().' '.$Order->getName02(), ENT_QUOTES),
  251.             'charge_type' => 2,
  252.             'version' => Constant::VERSION'_' .$Plugin->getVersion(),
  253.         ];
  254.         return $this->render('@ASJPayment/default/send.twig', [
  255.             'action' => $Config->getCreditUrl(),
  256.             'arrSendData' => $arrSendData,
  257.         ]);
  258.     }
  259. }