Skip to content

Commit

Permalink
new sendPostRequest function with allowed string body
Browse files Browse the repository at this point in the history
  • Loading branch information
payuru committed Mar 11, 2024
1 parent db83c34 commit fe38c37
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/ApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,25 @@ private function sendGetRequest(string $api): array

/**
* Отправка POST-запроса
* @param JsonSerializable $data запрос
* @param string|JsonSerializable $data запрос
* @param string $api адрес API (URI)
* @return array ответ сервера Ypmn
* @throws PaymentException
*/
private function sendPostRequest(JsonSerializable $data, string $api): array
public function sendPostRequest($data, string $api): array
{
$encodedJsonData = $data->jsonSerialize();
if ($data instanceof JsonSerializable) {
$encodedJsonData = $data->jsonSerialize();
} elseif (is_string($data)) {
if (json_decode($data) !== false) {
$encodedJsonData = $data;
} else {
throw new PaymentException('Incorrect request body type');
}
} else {
throw new PaymentException('Incorrect request body JSON');
}


$encodedJsonDataHash = md5($encodedJsonData);

Expand Down

0 comments on commit fe38c37

Please sign in to comment.