app/Plugin/ZeusPayment42/Service/ZeusCancelService.php line 42

Open in your IDE?
  1. <?php
  2. namespace Plugin\ZeusPayment42\Service;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Eccube\Service\PurchaseFlow\PurchaseContext;
  5. use Eccube\Exception\ShoppingException;
  6. use Plugin\ZeusPayment42\Repository\ConfigRepository;
  7. use Plugin\ZeusPayment42\Service\ZeusPaymentService;
  8. use Plugin\ZeusPayment42\Entity\Config;
  9. // SymfonyのWorkflowコンポーネントのイベントを使用します。
  10. use Symfony\Component\Workflow\Event\Event;
  11. class ZeusCancelService implements EventSubscriberInterface {
  12.     protected $zeusPaymentService;
  13.     protected $configRepository;
  14.     
  15.     /**
  16.      * ZeusCancelService constructor.
  17.      *
  18.      * @param ConfigRepository $configRepository
  19.      */
  20.     public function __construct(ConfigRepository $configRepositoryZeusPaymentService $zeusPaymentService)
  21.     {
  22.         $this->configRepository $configRepository;
  23.         $this->zeusPaymentService $zeusPaymentService;
  24.     }
  25.     
  26.     public static function getSubscribedEvents(): array
  27.     {
  28.         return [
  29.             'workflow.order.transition.cancel' => [['cancel']],
  30.         ];
  31.     }
  32.     
  33.     /**
  34.      * 対応状況が注文取消しに変わったときの処理
  35.      *
  36.      * @param Event $event
  37.      */
  38.     public function cancel(Event $event)
  39.     {
  40.         // 注文取消しになった受注データ
  41.         $order $event->getSubject()->getOrder();
  42.         
  43.         if (!$order->isZeusSkipCancel()) {
  44.             $payment $order->getPayment();
  45.             
  46.             $config $this->configRepository->get();
  47.             //cancel zeus
  48.             if ($config->isPluginSettingCreditPayment() && $payment->getId() == $config->getCreditPayment()->getId()) {
  49.                 log_notice('ZEUS注文取消し:注文番号=>' $order->getId());
  50.                 if (!$this->zeusPaymentService->paymentCancel($order$config)) {
  51.                     throw new ShoppingException('ゼウス側取消失敗しました。( 注文番号 => ' $order->getId() . ' ) すでに取消済の可能性があります。ゼウス側管理画面をご確認ください。');
  52.                 } else {
  53.                     if (strlen($order->getNote()) > 0) {
  54.                         $str $order->getNote() . "\r\n";
  55.                     } else {
  56.                         $str "";
  57.                     }
  58.                     $order->setNote($str '[' date("Y-m-d H:i:s") . '] 取消処理を行いました。');
  59.                     $order->setZeusSaleType(Config::ZEUS_SALE_TYPE_CANCEL);
  60.                 }
  61.             }elseif($config->isPluginSettingLaterPayment() && $payment->getId() == $config->getLaterPayment()->getId()) {
  62.                 // 取消後払い
  63.                 if (!$this->zeusPaymentService->paymentLaterCancel($order$config)) {
  64.                     throw new ShoppingException('ゼウス側取消失敗しました。( 注文番号 => ' $order->getId() . ' ) すでに取消済の可能性があります。ゼウス側管理画面をご確認ください。');
  65.                 } else {
  66.                     if (strlen($order->getNote()) > 0) {
  67.                         $str $order->getNote() . "\r\n";
  68.                     } else {
  69.                         $str "";
  70.                     }
  71.                     $order->setNote($str '[' date("Y-m-d H:i:s") . '] 取消処理を行いました。');
  72.                     $order->setZeusLaterSaleType(Config::ZEUS_LATER_SALE_TYPE_CANCEL);
  73.                     
  74.                 }
  75.             }
  76.         }
  77.     }
  78. }