Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CancelingService.php
Go to the documentation of this file.
1 <?php
7 
13 use Psr\Log\LoggerInterface;
14 
19 {
23  private $caseManagement;
24 
28  private $serviceFactory;
29 
33  private $gateway;
34 
38  private $cancelGuaranteeAbility;
39 
43  private $logger;
44 
54  public function __construct(
55  CaseManagementInterface $caseManagement,
56  UpdatingServiceFactory $serviceFactory,
57  Gateway $gateway,
58  CancelGuaranteeAbility $cancelGuaranteeAbility,
59  LoggerInterface $logger
60  ) {
61  $this->caseManagement = $caseManagement;
62  $this->serviceFactory = $serviceFactory;
63  $this->gateway = $gateway;
64  $this->cancelGuaranteeAbility = $cancelGuaranteeAbility;
65  $this->logger = $logger;
66  }
67 
71  public function cancelForOrder($orderId)
72  {
73  if (!$this->cancelGuaranteeAbility->isAvailable($orderId)) {
74  return false;
75  }
76 
77  $caseEntity = $this->caseManagement->getByOrderId($orderId);
78 
79  try {
80  $disposition = $this->gateway->cancelGuarantee($caseEntity->getCaseId());
81  } catch (GatewayException $e) {
82  $this->logger->error($e->getMessage());
83  return false;
84  }
85 
86  $updatingService = $this->serviceFactory->create('guarantees/cancel');
87  $data = [
88  'guaranteeDisposition' => $disposition
89  ];
90  $updatingService->update($caseEntity, $data);
91 
92  return true;
93  }
94 }
$logger
__construct(CaseManagementInterface $caseManagement, UpdatingServiceFactory $serviceFactory, Gateway $gateway, CancelGuaranteeAbility $cancelGuaranteeAbility, LoggerInterface $logger)