Skip to content

Commit fe38c37

Browse files
committed
new sendPostRequest function with allowed string body
1 parent db83c34 commit fe38c37

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/ApiRequest.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,25 @@ private function sendGetRequest(string $api): array
267267

268268
/**
269269
* Отправка POST-запроса
270-
* @param JsonSerializable $data запрос
270+
* @param string|JsonSerializable $data запрос
271271
* @param string $api адрес API (URI)
272272
* @return array ответ сервера Ypmn
273273
* @throws PaymentException
274274
*/
275-
private function sendPostRequest(JsonSerializable $data, string $api): array
275+
public function sendPostRequest($data, string $api): array
276276
{
277-
$encodedJsonData = $data->jsonSerialize();
277+
if ($data instanceof JsonSerializable) {
278+
$encodedJsonData = $data->jsonSerialize();
279+
} elseif (is_string($data)) {
280+
if (json_decode($data) !== false) {
281+
$encodedJsonData = $data;
282+
} else {
283+
throw new PaymentException('Incorrect request body type');
284+
}
285+
} else {
286+
throw new PaymentException('Incorrect request body JSON');
287+
}
288+
278289

279290
$encodedJsonDataHash = md5($encodedJsonData);
280291

0 commit comments

Comments
 (0)