$.ajax({
type: 'POST',
url: 'pay_request.php',
dataType: 'json',
async: false,
data: { json: JSON.stringify(json_data)},
}).done( function( data ) {
console.log('done');
console.log(data);
})
.fail( function( data ) {
console.log('fail');
console.log(data);
});
отправляет в php файл
let json_data = {
"checkout": {
"test" : true,
"order": {
"amount": 1,
"currency": "USD",
"description": "Тестовый заказ"
},
"settings": {
"decline_url": "http://www.example.com/decline",
"fail_url": "http://www.example.com/fail",
"notification_url": "http://www.example.com/notify",
"success_url": "http://www.example.com/success"
},
"transaction_type": "payment",
"version": 2
},
}
Это объект который нужно отправить
<?php
if (isset($_POST['json'])) {
$data = $_POST['json'];
try {
$auth = base64_encode("4225:3834fbef1fe6ea024ef77f5c79ec7ff1ba710ea6241c08c2f341afda8af4c1c4");
$url = 'https://checkout.bepaid.by/ctp/api/checkouts';
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Basic $auth\r\n",
'json' => $data
)
)));
echo $result;
} catch (Throwable $th) {
throw $th;
}
}
Мне приходить 422 ошибка
[19-May-2021 06:43:35 UTC] PHP Warning: file_get_contents(https://checkout.bepaid.by/ctp/api/checkouts): failed to open stream: HTTP request failed! HTTP/1.1 422 Unprocessable Entity
in /Applications/MAMP/htdocs/Whatsthere/pay_request.php on line 14
использую mamp
Вот инструкция для подключения