app/Plugin/StripeRec/StripeRecEvent.php line 361

Open in your IDE?
  1. <?php
  2. /*
  3. * Plugin Name : StripePaymentGateway
  4. *
  5. * Copyright (C) 2018 Subspire Inc. All Rights Reserved.
  6. * http://www.subspire.co.jp/
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Plugin\StripeRec;
  12. // if( \file_exists(dirname(__FILE__).'/../../StripePaymentGateway/vendor/stripe/stripe-php/init.php')) {
  13. //     include_once(dirname(__FILE__).'/../../StripePaymentGateway/vendor/stripe/stripe-php/init.php');
  14. // }
  15. use Eccube\Common\EccubeConfig;
  16. use Eccube\Event\TemplateEvent;
  17. use Eccube\Event\EventArgs;
  18. use Eccube\Entity\Payment;
  19. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  20. use Plugin\StripePaymentGateway\Repository\StripeConfigRepository;
  21. use Plugin\StripePaymentGateway\Service\Method\StripeCreditCard;
  22. use Plugin\StripePaymentGateway\Entity\StripeOrder;
  23. use Plugin\StripePaymentGateway\Repository\StripeOrderRepository;
  24. use Plugin\StripePaymentGateway\Entity\StripeCustomer;
  25. use Plugin\StripePaymentGateway\StripeClient;
  26. use Plugin\StripeRec\Service\ConfigService;
  27. use Eccube\Repository\Master\OrderStatusRepository;
  28. use Eccube\Entity\Master\OrderStatus;
  29. use Eccube\Entity\Order;
  30. use Eccube\Entity\Customer as Customer;
  31. use Doctrine\ORM\EntityManagerInterface;
  32. use Eccube\Event\EccubeEvents;
  33. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  34. use Symfony\Component\DependencyInjection\ContainerInterface;
  35. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  36. use Plugin\StripeRec\Service\Method\StripeRecurringNagMethod;
  37. use Eccube\Service\OrderHelper;
  38. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  39. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  40. use Symfony\Component\Form\Extension\Core\Type\TextType;
  41. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  42. use Symfony\Component\Form\FormError;
  43. use Plugin\StripeRec\Entity\PurchasePoint;
  44. use Eccube\Entity\ProductClass;
  45. use Eccube\Form\Type\PriceType;
  46. use Eccube\Common\Constant;
  47. class StripeRecEvent implements EventSubscriberInterface
  48. {
  49.     const NEW_CHARGE_ORDER_COPIED "plg_striperec.new_charge_order_copied";
  50.     const REC_ORDER_CREATED "plg_striperec.rec_order_created";
  51.     const RECURRING_CHECKOUT_FINALIZE "plg_striperec.rec_order_checkout_finalize";
  52.     const ADMIN_RECORDER_INDEX_COMPLETE "plg_striperec.admin.rec_order_index_complete";
  53.     const REC_ORDER_SUBSCRIPTION_PAID "plg_striperec.rec_order_subscription_paid";
  54.     /**
  55.      * @var エラーメッセージ
  56.      */
  57.     private $errorMessage null;
  58.     /**
  59.      * @var 国際化
  60.      */
  61.     private static $i18n = array();
  62.     /**
  63.      * @var EntityManagerInterface
  64.      */
  65.     protected $entityManager;
  66.     /**
  67.      * @var StripeConfigRepository
  68.      */
  69.     protected $stripeConfigRepository;
  70.     /**
  71.      * @var OrderStatusRepository
  72.      */
  73.     private $orderStatusRepository;
  74.     /**
  75.      * @var StripeOrderRepository
  76.      */
  77.     private $stripeOrderRepository;
  78.     /**
  79.      * @var StripeCustomerRepository
  80.      */
  81.     private $stripeCustomerRepository;
  82.     /**
  83.      * @var string ロケール(jaかenのいずれか)
  84.      */
  85.     private $locale 'en';
  86.     /**
  87.      * @var EccubeConfig
  88.      */
  89.     protected $eccubeConfig;
  90.     /**
  91.      * @var Session
  92.      */
  93.     protected $session;
  94.     protected $container;
  95.     protected $util_service;    
  96.     public function __construct(
  97.         EccubeConfig $eccubeConfig,
  98.         StripeConfigRepository $stripeConfigRepository,
  99.         StripeOrderRepository $stripeOrderRepository,
  100.         OrderStatusRepository $orderStatusRepository,
  101.         EntityManagerInterface $entityManager,
  102.         SessionInterface $session,
  103.         ContainerInterface $container
  104.     )
  105.     {
  106.         $this->eccubeConfig $eccubeConfig;
  107.         $this->locale=$this->eccubeConfig['locale'];
  108.         $this->stripeConfigRepository $stripeConfigRepository;
  109.         $this->stripeOrderRepository $stripeOrderRepository;
  110.         $this->orderStatusRepository $orderStatusRepository;
  111.         $this->entityManager $entityManager;
  112.         $this->session $session;
  113.         $this->container $container;
  114.         $this->util_service $this->container->get("plg_stripe_payment.service.util");     
  115.         $this->stripeCustomerRepository $this->entityManager->getRepository(StripeCustomer::class);
  116.     }
  117.     /**
  118.      * @return array
  119.      */
  120.     public static function getSubscribedEvents()
  121.     {
  122.         return [
  123.             'Shopping/index.twig'           => 'onShoppingIndexTwig',
  124.             'Shopping/confirm.twig'         => 'onShoppingConfirmTwig',
  125.             "@admin/Product/product.twig"   => "onProductEdit",             
  126.             // 'front.shopping.complete.initialize'=>'onFrontShoppingCompleteInitialize',
  127.             '@admin/Order/edit.twig'               =>  'onAdminOrderEdit',
  128.             'Mypage/index.twig'             => 'myPageNaviRenderBefore',
  129.             'Mypage/history.twig'           => 'myPageNaviRenderBefore',
  130.             'Mypage/favorite.twig'          => 'myPageNaviRenderBefore',
  131.             'Mypage/change.twig'            => 'myPageNaviRenderBefore',
  132.             'Mypage/change_complete.twig'   => 'myPageNaviRenderBefore',
  133.             'Mypage/delivery.twig'          => 'myPageNaviRenderBefore',
  134.             'Mypage/delivery_edit.twig'     => 'myPageNaviRenderBefore',
  135.             'Mypage/withdraw.twig'          => 'myPageNaviRenderBefore',  
  136.             'Cart/index.twig'               =>  'onCartPage',
  137.             'StripeRec/Resource/template/Mypage/recurring_tab.twig' => 'myPageNaviRenderBefore',
  138.             EccubeEvents::MAIL_ORDER => 'sendOrderMailBefore',
  139.             EccubeEvents::ADMIN_PRODUCT_EDIT_INITIALIZE =>  'onProdEditInit',
  140.             EccubeEvents::ADMIN_PRODUCT_EDIT_COMPLETE   =>  'onProdEditComplete',
  141.         ];
  142.     }
  143.     public function onCartPage(TemplateEvent $event) {
  144.         $recItemMap = [];
  145.         $Carts $event->getParameter('Carts');
  146.         $config_service $this->container->get('plg_stripe_rec.service.admin.plugin.config');
  147.         $is_multi_product = !$config_service->get(ConfigService::MULTI_PRODUCT);
  148.         if (!$is_multi_product) {
  149.             foreach($Carts as $Cart) {
  150.                 $CartItems $Cart->getItems();
  151.                 foreach($CartItems as $item) {
  152.                     $pc $item->getProductClass();
  153.                     if ($pc->isRegistered()) {
  154.                         $cart_plus_url $this->container->get('router')->generate('cart_handle_item'
  155.                             array('operation' => 'up''productClassId' => $pc->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  156.                         $cart_minus_url $this->container->get('router')->generate('cart_handle_item',
  157.                             array('operation' => 'down''productClassId' => $pc->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
  158.                         if (!\in_array($cart_plus_url$recItemMap)) {
  159.                             $recItemMap[] = $cart_plus_url;
  160.                         }
  161.                         if (!\in_array($cart_minus_url$recItemMap)) {
  162.                             $recItemMap[] = $cart_minus_url;
  163.                         }
  164.                     }
  165.                 }
  166.             }
  167.             if (count($recItemMap) > 0) {
  168.                 $event->setParameter('recItemMap'$recItemMap);
  169.                 $event->addSnippet('StripeRec/Resource/template/default/Cart/index.js.twig');
  170.             }
  171.         }
  172.     }
  173.     public function onAdminOrderEdit(TemplateEvent $event
  174.     {
  175.         $Order $event->getParameter('Order');
  176.         $rec_order $Order->getRecOrder();
  177.         if ($rec_order) {
  178.             $pb_service $this->container->get('plg_stripe_rec.service.pointbundle_service');
  179.             $bundles $pb_service->getBundleProducts($rec_order);
  180.             
  181.             $price_sum $pb_service->getPriceSum($rec_order);        
  182.             extract($price_sum);
  183.             if($bundles){
  184.                 $bundle_order_items $bundles['order_items'];
  185.                 $initial_amount += $bundles['price'];
  186.             }else{
  187.                 $bundle_order_items null;
  188.             }
  189.             if($coupon_str $rec_order->getCouponDiscountStr()){
  190.                 $coupon_service $this->container->get('plg_stripe_rec.service.coupon_service');
  191.                 $initial_discount $coupon_service->couponDiscountFromStr($initial_amount$coupon_str);
  192.                 $recurring_discount $coupon_service->couponDiscountFromStr($recurring_amount$coupon_str);
  193.                 $coupon_discount $coupon_service->couponDiscount($coupon_str);
  194.             }else{
  195.                 $initial_discount 0;
  196.                 $recurring_discount 0;
  197.             }
  198.             $event->setParameter('rec_order'$rec_order);
  199.             $event->setParameter('bundle_order_items'$bundle_order_items);
  200.             $event->setParameter('initial_amount'$initial_amount);
  201.             $event->setParameter('recurring_amount'$recurring_amount);
  202.             $event->setParameter('initial_discount'$initial_discount);
  203.             $event->setParameter('recurring_discount'$recurring_discount);
  204.             $event->setParameter('coupon_discount'$coupon_discount ?? 0);
  205.             $event->addSnippet('StripeRec/Resource/template/admin/Order/edit.twig');
  206.         }
  207.         if ($Order->getRecOrder()) {
  208.             $event->addSnippet("StripeRec/Resource/template/admin/Order/rec_mail_dialog.css.twig");
  209.         }
  210.     }
  211.     public function onProdEditComplete(EventArgs $args){
  212.         $form $args->getArgument('form');
  213.         $Product $args->getArgument('Product');
  214.         
  215.         $def_pc $Product->getDefaultClass();
  216.         if(!$Product->isStripeProduct() || !$def_pc){
  217.             return;
  218.         }
  219.         // =======add bundle product========
  220.         $bundle_code $form->get('bundle_product')->getData();
  221.         if($bundle_code){
  222.             $bundle_product $this->entityManager->getRepository(ProductClass::class)->findOneBy(['code' =>  $bundle_code]);
  223.             if(!empty($bundle_product) && $def_pc != $bundle_product){                
  224.                 $def_pc->setBundleProduct($bundle_code);
  225.             }
  226.             if (empty($bundle_product)) {
  227.                 $form->get('bundle_product')->addError(new FormError("stripe_recurring.admin.rec_order.error.invalid_bundle_product"));
  228.             }
  229.         } else {
  230.             $def_pc->setBundleProduct("");
  231.         }
  232.         $this->entityManager->persist($def_pc);
  233.         $this->entityManager->flush();
  234.         $bundle_required $form->get('bundle_required')->getData();
  235.         if($bundle_required !== $def_pc->isBundleRequired()){
  236.             if ($bundle_required && !$bundle_code) {
  237.                 $form->get('bundle_product')->addError(new FormError("stripe_recurring.admin.rec_order.error.empty_bundle_product"));
  238.             } else {
  239.                 $def_pc->setBundleRequired($bundle_required);
  240.                 $this->entityManager->persist($def_pc);
  241.                 $this->entityManager->flush();
  242.             }
  243.         }
  244.         //BOC check if first cycle free
  245.         $first_cycle_free $form->get('first_cycle_free')->getData();
  246.         if($first_cycle_free !== $def_pc->getFirstCycleFree()){
  247.             $def_pc->setFirstCycleFree($first_cycle_free);
  248.             $this->entityManager->persist($def_pc);
  249.             $this->entityManager->flush();
  250.         }
  251.         //EOC check if first cycle free
  252.         if($first_cycle_free){//If first cycle is free make initial price as product price
  253.             $initial_price=0;
  254.             if ($initial_price !== $def_pc->getInitialPrice()) {
  255.                 $def_pc->setInitialPrice($initial_price);
  256.                 $this->entityManager->persist($def_pc);
  257.                 $this->entityManager->flush();
  258.             }
  259.         } else {
  260.             $initial_price $form->get('initial_price')->getData();
  261.             if ($initial_price !== $def_pc->getInitialPrice()) {
  262.                 $def_pc->setInitialPrice($initial_price);
  263.                 $this->entityManager->persist($def_pc);
  264.                 $this->entityManager->flush();
  265.             }
  266.         }
  267.         
  268.         $register_flg $form->get('register_flg')->getData();
  269.         // ==========add price object==========
  270.         $price_change_flg $form->get("price_change_flg")->getData() === "1" "update""register";
  271.         if( (!$def_pc->isRegistered() && (empty($register_flg) || $register_flg === "none")) || ($def_pc->isRegistered() && $price_change_flg !== "update")){
  272.             return;
  273.         }
  274.         
  275.         $util_service $this->container->get("plg_stripe_recurring.service.util");
  276.         
  277.         $res $util_service->saveDefaultClass($def_pc$register_flg$price_change_flg);
  278.         if(!$res){
  279.             $form->get('register_flg')->addError(new FormError($util_service->getErrMsg()));
  280.         }
  281.     }
  282.     public function onProdEditInit(EventArgs $args){   
  283.         
  284.         $builder $args->getArgument('builder');
  285.         $Product $args->getArgument("Product");        
  286.         $def_pc $Product->getDefaultClass();        
  287.         if($def_pc && $Product->isStripeProduct()){
  288.             $isFirstCycleFree=$def_pc->getFirstCycleFree();
  289.             $initialPriceOptions=[
  290.                 'required'  =>  false
  291.             ];
  292.             if($isFirstCycleFree){
  293.                 $initialPriceOptions=[
  294.                     'required'  =>  false,
  295.                     'disabled'  =>  true
  296.                 ];
  297.             }
  298.             $builder->add('register_flg'ChoiceType::class, [
  299.                 'required'  => true,
  300.                 // 'label'     =>  trans('stripe_recurring.admin.product_class.register_flg')
  301.                 'choices'   =>  [
  302.                     // '指定なし' =>  'none',
  303.                     // '日次' =>  'day',
  304.                     // '3ヶ月ごと' =>  'quarter',
  305.                     // '6ヶ月ごと' =>  'semiannual',
  306.                     // '週次' =>   'week',
  307.                     '月次' => 'month',
  308.                     '年次' =>  'year'
  309.                 ],
  310.             ])
  311.             ->add('price_change_flg'HiddenType::class, [
  312.                 'required'  =>  false                
  313.             ])
  314.             ->add('bundle_product'TextType::class, [
  315.                 'required'  =>  false,
  316.             ])
  317.             ->add('bundle_required'CheckboxType::class, [
  318.                 'label' => 'stripe_recurring.mypage.schedule.bundle_required',
  319.                 'required' => false,
  320.             ])
  321.             ->add('initial_price'PriceType::class, $initialPriceOptions)
  322.             ->add('first_cycle_free',CheckboxType::class,[
  323.                 'label' => 'stripe_recurring.admin.product.first_cycle_free',
  324.                 'required' => false,
  325.             ]);
  326.             
  327.         }
  328.     }
  329.     /**
  330.      * @param TemplateEvent $event
  331.      */
  332.     public function onShoppingConfirmTwig(TemplateEvent $event)
  333.     {
  334.         $Order $event->getParameter('Order');
  335.         
  336.         if ($Order->getPayment()->getMethodClass() === StripeRecurringNagMethod::class
  337.                 &&  $this->isEligiblePaymentMethod($Order->getPayment(),$Order->getPaymentTotal())
  338.                 && $Order->hasStripePriceId()) {
  339.             
  340.             $pb_service $this->container->get('plg_stripe_rec.service.pointbundle_service');
  341.             $purchase_point =  empty($_REQUEST['purchase_point']) ? 'on_date' $_REQUEST['purchase_point'];
  342.             $after_days = empty($_REQUEST['_shopping_order']['after_days']) ? null $_REQUEST['_shopping_order']['after_days'];
  343.             $bundle_include_arr = empty($_REQUEST['bundle_include']) ? null $_REQUEST['bundle_include'];
  344.             $bundle_include_arr $this->precessBundleInclude($bundle_include_arr$Order);
  345.             
  346.             $purchase_point $pb_service->calculatePurchasePoint($purchase_point$after_days);
  347.             $this->session->getFlashBag()->set("purchase_point"$purchase_point);
  348.             $this->session->set("bundle_include_arr"$bundle_include_arr);
  349.             
  350.             $is_bundle = empty($_REQUEST['is_bundle']) ? false $_REQUEST['is_bundle'] === "checked";        
  351.             $this->session->set('is_bundle'$is_bundle);
  352.             $bundles $pb_service->getBundleProductsOrderByShipping($Order$bundle_include_arr);
  353.             $eccube_version $this->getEccubeVersion();
  354.             if($eccube_version "4.0.3"){
  355.                 $event->addSnippet('@StripeRec/default/Shopping/bundle_product.4.0.0.twig');                    
  356.             }else{
  357.                 $event->addSnippet('@StripeRec/default/Shopping/bundle_product.4.0.4.twig');
  358.             }
  359.             
  360.             $event->setParameter('is_bundle_disabled'true);
  361.             $event->setParameter('is_bundle'$is_bundle);
  362.             $event->setParameter('bundle_include_arr'$bundle_include_arr);
  363.             $event->setParameter('bundles'$bundles);
  364.             $this->replaceItems($event);                
  365.             $event->addAsset('StripeRec/Resource/assets/css/shopping_index_bundle.css.twig');
  366.             $event->addSnippet('StripeRec/Resource/template/default/Shopping/confirm_screen.js.twig');
  367.         }
  368.     }
  369.     public function onShoppingIndexTwig(TemplateEvent $event){
  370.         $pc $this->entityManager->getRepository(ProductClass::class)->findOneBy(['id' => 11]);
  371.         
  372.         $Order $event->getParameter('Order');
  373.         // $this->session->getFlashBag()->set("stripe_customer_id", false);
  374.         // $this->session->getFlashBag()->set("payment_method_id", false);
  375.         // $this->session->getFlashBag()->set("purchase_point", false);
  376.         // $this->session->set('is_bundle', true);
  377.         // $this->session->set("bundle_include_arr", null);
  378.         $pb_service $this->container->get('plg_stripe_rec.service.pointbundle_service');
  379.         $purchase_point =  empty($_REQUEST['purchase_point']) ? 'on_date' $_REQUEST['purchase_point'];
  380.         $after_days = empty($_REQUEST['_shopping_order']['after_days']) ? null $_REQUEST['_shopping_order']['after_days'];
  381.         $bundle_include_arr = empty($_REQUEST['bundle_include']) ? null $_REQUEST['bundle_include'];
  382.         $bundle_include_arr $this->precessBundleInclude($bundle_include_arr$Order);
  383.         $purchase_point $pb_service->calculatePurchasePoint($purchase_point$after_days);
  384.         $this->session->getFlashBag()->set("purchase_point"$purchase_point);
  385.         $this->session->set("bundle_include_arr"$bundle_include_arr);
  386.         $is_bundle true;
  387.         if($Order) {
  388.             $StripeConfig $this->stripeConfigRepository->getConfigByOrder($Order);
  389.             $pb_service $this->container->get('plg_stripe_rec.service.pointbundle_service');
  390.             if ($Order->getPayment()->getMethodClass() === StripeRecurringNagMethod::class
  391.                 &&  $this->isEligiblePaymentMethod($Order->getPayment(),$Order->getPaymentTotal())
  392.                 && $Order->hasStripePriceId()) {
  393.                 
  394.                 $purchase_points $this->entityManager->getRepository(PurchasePoint::class)->findby(['enabled' => true]);
  395.                 
  396.                 $stripeClient = new StripeClient($StripeConfig->secret_key);
  397.                 //BOC check if registered shop customer
  398.                 $stripePaymentMethodObj false;
  399.                 $customerObj=false;
  400.                 $isSaveCardOn=false;
  401.                 $Customer=$Order->getCustomer();
  402.                 if($Customer instanceof Customer){
  403.                     $customerObj=$Customer;
  404.                     $StripeCustomer=$this->stripeCustomerRepository->findOneBy(array('Customer'=>$Customer));
  405.                     if($StripeCustomer instanceof StripeCustomer){
  406.                         $isSaveCardOn=$StripeCustomer->getIsSaveCardOn();
  407.                         $stripePaymentMethodObj $stripeClient->retrieveLastPaymentMethodByCustomer($StripeCustomer->getStripeCustomerId());
  408.                         if( !($stripePaymentMethodObj instanceof PaymentMethod) || !$stripeClient->isPaymentMethodId($stripePaymentMethodObj->id) ) {
  409.                             $stripePaymentMethodObj false;
  410.                         }
  411.                     }
  412.                 }
  413.                 //EOC check if registered shop customer
  414.                 
  415.                 if(isset($_REQUEST['stripe_card_error'])){
  416.                     $this->errorMessage=$_REQUEST['stripe_card_error'];
  417.                 }
  418.                 $bundles $pb_service->getBundleProductsOrderByShipping($Ordernull);
  419. //                $StripeConfig = $this->stripeConfigRepository->get();
  420.                 $stripeCSS 'StripePaymentGateway/Resource/assets/css/stripe.css.twig';
  421.                 $event->addAsset($stripeCSS);
  422.                 $event->setParameter('stripConfig'$StripeConfig);
  423.                 $event->setParameter('stripeErrorMessage'$this->errorMessage);
  424.                 $event->setParameter('stripeCreditCardPaymentId'$Order->getPayment()->getId());
  425.                 $event->setParameter('stripePaymentMethodObj'$stripePaymentMethodObj);
  426.                 $event->setParameter('customerObj'$customerObj);
  427.                 $event->setParameter('stripeIsSaveCardOn'true);
  428.                 $event->setParameter('stripe_locale'$this->locale);
  429.                 $event->setParameter('purchase_points'$purchase_points);
  430.                 $event->setParameter('bundle_include_arr'null);
  431.                 $event->setParameter('bundles'$bundles);
  432.                 // $event->addSnippet('@StripeRec/default/Shopping/stripe_rec_org.twig');
  433.                 $event->addSnippet('@StripeRec/default/Shopping/purchase_point_select.twig');
  434.     
  435.                 $event->setParameter('is_bundle_disabled'false);
  436.                 $event->setParameter('is_bundle'$is_bundle);
  437.                 $eccube_version $this->getEccubeVersion();
  438.                 if($eccube_version "4.0.3"){
  439.                     $event->addSnippet('@StripeRec/default/Shopping/bundle_product.4.0.0.twig');                    
  440.                 }else{
  441.                     $event->addSnippet('@StripeRec/default/Shopping/bundle_product.4.0.4.twig');
  442.                 }
  443.                 
  444.                 // $event->addSnippet('@StripeRec/default/Shopping/shopping_index.twig');
  445.                 $this->replaceItems($event);
  446.                 $stripeJS'StripeRec/Resource/assets/js/stripe_recurring_js.twig';
  447.                 $event->addAsset($stripeJS);
  448.                 $event->addAsset('StripeRec/Resource/assets/css/shopping_index_bundle.css.twig');
  449.                 $event->addSnippet('StripeRec/Resource/template/default/Shopping/confirm_screen.js.twig');
  450.             }
  451.             // change payment label
  452.             $Payment $this->entityManager->getRepository(Payment::class)->findOneBy(['method_class'  => StripeRecurringNagMethod::class]);
  453.             if($Payment){
  454.                $event->setParameter('stripe_pay_id'$Payment->getId());
  455.                $event->setParameter('method_name'$Payment->getMethod());
  456.                $event->setParameter('checkout_ga_enable'$StripeConfig->checkout_ga_enable);
  457.                $event->addSnippet('@StripeRec/default/Shopping/paymethod_label.js.twig');
  458.             }
  459.         }
  460.     }
  461.     public function sendOrderMailBefore(EventArgs $event)
  462.     {
  463.         $this->container->get('plg_stripe_rec.service.email.service')->onSendOrderMailBefore($event);
  464.     }
  465.     public function myPageNaviRenderBefore(TemplateEvent $event){
  466.         $event->addSnippet('@StripeRec/default/Mypage/navi.twig');
  467.     }
  468.     public function onProductEdit(TemplateEvent $event){
  469.         
  470.         $event->addSnippet('@StripeRec/admin/product_recurring.twig');
  471.     }
  472.     private function isEligiblePaymentMethod(Payment $Payment,$total){
  473.         $min $Payment->getRuleMin();
  474.         $max $Payment->getRuleMax();
  475.         if (null !== $min && $total $min) {
  476.             return false;
  477.         }
  478.         if (null !== $max && $total $max) {
  479.             return false;
  480.         }
  481.         return true;
  482.     }
  483.     private function precessBundleInclude($bundle_include_arr$Order){
  484.         $order_items $Order->getProductOrderItems();
  485.         $res = [];
  486.         foreach($order_items as $order_item){
  487.             $pc $order_item->getProductClass();
  488.             if(!$pc->isBundleRequired()){
  489.                 if(empty($bundle_include_arr[$order_item->getId()])){
  490.                     $res[$order_item->getId()] = 0;
  491.                 }else{
  492.                     $res[$order_item->getId()] = $bundle_include_arr[$order_item->getId()];
  493.                 }
  494.             }else{
  495.                 $res[$order_item->getId()] = 1;
  496.             }
  497.         }
  498.         if(empty($res)){
  499.             $res null;
  500.         }
  501.         return $res;
  502.     }
  503.     private function replaceItems(TemplateEvent $event){
  504.         $source $event->getSource();
  505.         $find_delivery_for $this->between("{% for orderItem in shipping.productOrderItems %}""{% endfor %}"$source);
  506.         $replace "{% include '@StripeRec/default/Shopping/shopping_index.twig' %}";
  507.         $source str_replace($find_delivery_for$replace$source);
  508.         $event->setSource($source);
  509.     }
  510.     public function between($from$to$source) {
  511.         $arr explode($from$source);
  512.         if (isset($arr[1])) {
  513.             $arr explode($to$arr[1]);
  514.             return $arr[0];
  515.         }
  516.         return '';
  517.     }
  518.     /**
  519.      * @param string $from
  520.      * @param string $to
  521.      * @param string $source
  522.      * @return string
  523.      */
  524.     public function betweenInclude($from$to$source) {
  525.         return $from $this->between($from$to$source) . $to;
  526.     }
  527.     public function getEccubeVersion(){
  528.         // $kernel = $this->container->get('kernel');
  529.         // $project_dir = $kernel->getProjectDir();
  530.         // $package_path = $project_dir.'/package.json';
  531.         // if (file_exists($package_path) === false) {
  532.         //     return "4.0.4xxx";
  533.         // }
  534.         // $json = json_decode(file_get_contents($package_path));
  535.         // if(!empty($json->version)){
  536.         //     return $json->version;
  537.         // }
  538.         return Constant::VERSION;
  539.     }
  540. }