app/Plugin/EccubePaymentLite42/Service/SaveGmoEpsilonCreditCardExpirationService.php line 58

Open in your IDE?
  1. <?php
  2. namespace Plugin\EccubePaymentLite42\Service;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Eccube\Entity\Customer;
  5. use Eccube\Repository\CustomerRepository;
  6. use Plugin\EccubePaymentLite42\Repository\ConfigRepository;
  7. use Plugin\EccubePaymentLite42\Service\GmoEpsilonRequest\RequestGetUserInfoService;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. class SaveGmoEpsilonCreditCardExpirationService
  10. {
  11.     /**
  12.      * @var EntityManagerInterface
  13.      */
  14.     private $entityManager;
  15.     /**
  16.      * @var SessionInterface
  17.      */
  18.     private $session;
  19.     /**
  20.      * @var RequestGetUserInfoService
  21.      */
  22.     private $requestGetUserInfoService;
  23.     /**
  24.      * @var CustomerRepository
  25.      */
  26.     private $customerRepository;
  27.     /**
  28.      * @var ConfigRepository
  29.      */
  30.     private $configRepository;
  31.     /**
  32.      * @var GetCardExpireDateTimeService
  33.      */
  34.     private $getCardExpireDateTimeService;
  35.     public function __construct(
  36.         EntityManagerInterface $entityManager,
  37.         SessionInterface $session,
  38.         RequestGetUserInfoService $requestGetUserInfoService,
  39.         CustomerRepository $customerRepository,
  40.         ConfigRepository $configRepository,
  41.         GetCardExpireDateTimeService $getCardExpireDateTimeService
  42.     ) {
  43.         $this->entityManager $entityManager;
  44.         $this->session $session;
  45.         $this->requestGetUserInfoService $requestGetUserInfoService;
  46.         $this->customerRepository $customerRepository;
  47.         $this->configRepository $configRepository;
  48.         $this->getCardExpireDateTimeService $getCardExpireDateTimeService;
  49.     }
  50.     public function handle()
  51.     {
  52.         // ゲスト購入の場合は処理を行わない
  53.         if (is_null($this->session->get('_security_customer'))) {
  54.             return;
  55.         }
  56.         /** @var Customer $customer */
  57.         $customer unserialize($this->session->get('_security_customer'))->getUser();
  58.         /** @var Customer $Customer */
  59.         $Customer $this->customerRepository->find($customer->getId());
  60.         $results $this->requestGetUserInfoService->handle($Customer->getId());
  61.         // クレジットカード有効期限を保存する
  62.         if ($results['status'] === 'OK' && strpos($results['cardExpire'], '/') !== false) {
  63.             $Customer->setGmoEpsilonCreditCardExpirationDate($this->getCardExpireDateTimeService->get($results['cardExpire']));
  64.         }
  65.         $Customer->setCardChangeRequestMailSendDate(null);
  66.         $this->entityManager->persist($Customer);
  67.         $this->entityManager->flush();
  68.     }
  69. }