Skip to content

Commit f919430

Browse files
author
Denis Schedrikov
committed
moved exceptions from the sendGetRequest method
1 parent 05e3f16 commit f919430

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/ApiRequest.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private function reportsSign($parameters)
171171
* @return array ответ сервера Ypmn
172172
* @throws PaymentException
173173
*/
174-
private function sendGetRequest(string $api, ?string $emptyResponseMessage = null, bool $curlException = true): array
174+
private function sendGetRequest(string $api): array
175175
{
176176
$curl = curl_init();
177177
$date = (new DateTime())->format(DateTimeInterface::ATOM);
@@ -241,14 +241,6 @@ private function sendGetRequest(string $api, ?string $emptyResponseMessage = nul
241241
}
242242
}
243243

244-
if ($curlException && mb_strlen($err) > 0) {
245-
throw new PaymentException($err);
246-
}
247-
248-
if ($emptyResponseMessage !== null && ($response == null || strlen($response) === 0)) {
249-
throw new PaymentException($emptyResponseMessage);
250-
}
251-
252244
return ['response' => $response, 'error' => $err];
253245
}
254246

@@ -374,7 +366,17 @@ public function sendRefundRequest(RefundInterface $refund): array
374366
/** @inheritdoc */
375367
public function sendStatusRequest(string $merchantPaymentReference): array
376368
{
377-
return $this->sendGetRequest(self::STATUS_API . '/' . $merchantPaymentReference, 'Вы можете попробовать другой способ оплаты, либо свяжитесь с продавцом.');
369+
$responseData = $this->sendGetRequest(self::STATUS_API . '/' . $merchantPaymentReference);
370+
371+
if (mb_strlen($responseData['error']) > 0) {
372+
throw new PaymentException($responseData['error']);
373+
}
374+
375+
if ($responseData['response'] == null || strlen($responseData['response']) === 0) {
376+
throw new PaymentException('Вы можете попробовать другой способ оплаты, либо свяжитесь с продавцом.');
377+
}
378+
379+
return $responseData;
378380
}
379381

380382
/** @inheritdoc */
@@ -398,7 +400,7 @@ public function sendPayoutCreateRequest(PayoutInterface $payout)
398400
/** @inheritdoc */
399401
public function sendReportChartRequest(array $params): array
400402
{
401-
return $this->sendGetRequest(self::REPORT_CHART_API . '/?' . http_build_query($params), null, false);
403+
return $this->sendGetRequest(self::REPORT_CHART_API . '/?' . http_build_query($params));
402404
}
403405

404406
/** @inheritdoc */
@@ -415,13 +417,13 @@ public function sendReportChartUpdateRequest(array $params): array
415417

416418
$params = array_merge($getParams, $params);
417419

418-
return $this->sendGetRequest(self::REPORT_CHART_API . '/?' . http_build_query($params), null, false);
420+
return $this->sendGetRequest(self::REPORT_CHART_API . '/?' . http_build_query($params));
419421
}
420422

421423
/** @inheritdoc */
422424
public function sendReportGeneralRequest(array $params): array
423425
{
424-
return $this->sendGetRequest(self::REPORT_GENERAL_API . '/?' . http_build_query($params), null, false);
426+
return $this->sendGetRequest(self::REPORT_GENERAL_API . '/?' . http_build_query($params));
425427
}
426428

427429
/**

0 commit comments

Comments
 (0)