app/Plugin/ZeusPayment4/Service/ZeusCancelService.php line 41

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