Запрос POST должен быть отправлен на конечную точку API (https://api.example.com/api/v1/pay-terminal/).
В запросе требуется номер телефона клиента в поле «имя пользователя» (текстовый тип).
И успешный ответ должен выглядеть так:
Код: Выделить всё
"status": 200,
"error": "",
"message": "",
"data": {
"cash_wallt": 0,
"special_amount": 0
},
"patch": [],
"date": "2024-10-16 12:57:47"
}
Код: Выделить всё
public function process_payment($order_id) {
$order = wc_get_order($order_id);
$amount = $order->get_total();
$description = sprintf(__('Order #%s', 'woocommerce'), $order->get_order_number());
$customer_phone = $order->get_billing_phone();
// Step 1: Check Customer Credit
$credit_response = wp_remote_post('https://api.example.com/api/v1/payment-terminal/', [
'headers' => [
'Authorization' => 'Bearer ' . $this->apikey, // API key
'Content-Type' => 'application/json'
],
'body' => json_encode(['username' => $customer_phone]) // Customer phone number
]);
if (is_wp_error($credit_response)) {
wc_add_notice('Authentication error', 'error');
return;
}
$credit_body = json_decode(wp_remote_retrieve_body($credit_response), true);
if ($credit_body['status'] != 200) {
wc_add_notice('Failed Authentication', 'error');
return;
}
}
Я уже дважды проверил и подтвердил следующее:
Ключ API (токен) правильный и включен в заголовок запроса.
Номер телефона соответствует зарегистрированному учетную запись на платформе шлюза.
На сервере IP внесен в белый список.
Чтобы убедиться, что проблема не связана с плагином, я даже попробовал прямой запрос с помощью Curl:
Код: Выделить всё
curl -X POST https://api.example.com/api/v1/payment-terminal/ \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d "{\"username\": \"{phone number}\"}"
Код: Выделить всё
{
"status": 403,
"error": null,
"message": "permission denied",
"data": [],
"patch": [],
"date": "2024-12-09 20:13:21"
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... y-endpoint