我正在尝试创建自己的Woocommerce Payment Gateway插件
在 // Material dialog
implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
函数中,我调用用于创建支付票证的公共函数:
process_payment
当API在结帐页面前端的请求中给出错误时,我得到以下错误代码:function create_ticket($body){
global $config;
// Set CURL parameters required to create the ticket
$request = curl_init("{$config['root']}/api/tickets");
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_POST, true);
curl_setopt($request, CURLOPT_POSTFIELDS, json_encode($body));
curl_setopt($request, CURLOPT_TIMEOUT, 30);
add_headers($request);
// Execute the request
$response = curl_exec($request);
check_response($request, $response);
// Get the response
$http_status = curl_getinfo($request, CURLINFO_HTTP_CODE);
if ($http_status === 201) {
// The ticket was created.
$ticket = json_decode($response);
return $ticket->ticketNumber;
} else {
// There was an error
show_error($http_status, $response, 'creating the ticket');
}
}
,并在控制台日志中显示:SyntaxError: Unexpected token E in JSON at position 0
有人可以帮助我在结帐页面的前端获得正确的可读错误消息吗?
编辑: Show_error函数:
Unable to fix malformed JSON