<?php
namespace Plugin\ZeusPayment42\Service;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Exception\ShoppingException;
use Plugin\ZeusPayment42\Repository\ConfigRepository;
use Plugin\ZeusPayment42\Service\ZeusPaymentService;
// SymfonyのWorkflowコンポーネントのイベントを使用します。
use Symfony\Component\Workflow\Event\Event;
class ZeusCancelService implements EventSubscriberInterface {
protected $zeusPaymentService;
protected $configRepository;
/**
* ZeusCancelService constructor.
*
* @param ConfigRepository $configRepository
*/
public function __construct(ConfigRepository $configRepository, ZeusPaymentService $zeusPaymentService)
{
$this->configRepository = $configRepository;
$this->zeusPaymentService = $zeusPaymentService;
}
public static function getSubscribedEvents(): array
{
return [
'workflow.order.transition.cancel' => [['cancel']],
];
}
/**
* 対応状況が注文取消しに変わったときの処理
*
* @param Event $event
*/
public function cancel(Event $event)
{
// 注文取消しになった受注データ
$order = $event->getSubject()->getOrder();
if (!$order->isZeusSkipCancel()) {
$payment = $order->getPayment();
$config = $this->configRepository->get();
//cancel zeus
if ($payment->getId() == $config->getCreditPayment()->getId()) {
log_notice('ZEUS注文取消し:注文番号=>' . $order->getId());
if (!$this->zeusPaymentService->paymentCancel($order, $config)) {
throw new ShoppingException('ゼウス側取消失敗しました。( 注文番号 => ' . $order->getId() . ' ) すでに取消済の可能性があります。ゼウス側管理画面をご確認ください。');
} else {
if (strlen($order->getNote()) > 0) {
$str = $order->getNote() . "\r\n";
} else {
$str = "";
}
$order->setNote($str . '[' . date("Y-m-d H:i:s") . '] 取消処理を行いました。');
}
}
}
}
}