50 private $createCaseBuilder;
60 private $orderRepository;
65 private $caseRepository;
81 $this->createCaseBuilder = $createCaseBuilder;
82 $this->apiClient = $apiClient;
97 $caseParams = $this->createCaseBuilder->build($orderId);
98 $storeId = $this->getStoreIdFromOrder($orderId);
100 $caseCreationResult = $this->apiClient->makeApiCall(
107 if (!isset($caseCreationResult[
'investigationId'])) {
111 return (
int)$caseCreationResult[
'investigationId'];
124 $storeId = $this->getStoreIdFromCase($signifydCaseId);
125 $guaranteeCreationResult = $this->apiClient->makeApiCall(
129 'caseId' => $signifydCaseId,
134 $disposition = $this->processDispositionResult($guaranteeCreationResult);
148 $storeId = $this->getStoreIdFromCase($caseId);
149 $result = $this->apiClient->makeApiCall(
150 '/cases/' . $caseId .
'/guarantee',
153 'guaranteeDisposition' => self::GUARANTEE_CANCELED
158 $disposition = $this->processDispositionResult(
$result);
159 if ($disposition !== self::GUARANTEE_CANCELED) {
160 throw new GatewayException(
"API returned unexpected disposition: $disposition.");
175 private function processDispositionResult(array
$result)
177 if (!isset(
$result[
'disposition'])) {
181 $disposition = strtoupper(
$result[
'disposition']);
183 if (!in_array($disposition, [
184 self::GUARANTEE_APPROVED,
185 self::GUARANTEE_DECLINED,
186 self::GUARANTEE_PENDING,
187 self::GUARANTEE_CANCELED,
188 self::GUARANTEE_IN_REVIEW,
189 self::GUARANTEE_UNREQUESTED
191 throw new GatewayException(
192 sprintf(
'API returns unknown guaranty disposition "%s".', $disposition)
205 private function getStoreIdFromCase(
int $caseId)
207 $case = $this->caseRepository->getByCaseId($caseId);
208 $orderId =
$case->getOrderId();
210 return $this->getStoreIdFromOrder($orderId);
219 private function getStoreIdFromOrder(
int $orderId)
221 $order = $this->orderRepository->get($orderId);
223 return $order->getStoreId();
const DISPOSITION_FRAUDULENT
const GUARANTEE_UNREQUESTED
__construct(CreateCaseBuilderInterface $createCaseBuilder, ApiClient $apiClient, OrderRepositoryInterface $orderRepository, CaseRepositoryInterface $caseRepository)
const GUARANTEE_IN_REVIEW
submitCaseForGuarantee($signifydCaseId)