Php 贝宝RESTAPI执行错误
我试图在Wordpress主题中实现PayPal支付。 我获取令牌,创建付款,将用户重定向到approval链接,获得用户的批准,但由于某些原因,我无法执行付款“curl响应为空 下面是代码(我仔细检查了executeURL和令牌,它们是正确的)Php 贝宝RESTAPI执行错误,php,wordpress,curl,paypal,Php,Wordpress,Curl,Paypal,我试图在Wordpress主题中实现PayPal支付。 我获取令牌,创建付款,将用户重定向到approval链接,获得用户的批准,但由于某些原因,我无法执行付款“curl响应为空 下面是代码(我仔细检查了executeURL和令牌,它们是正确的) 当您从批准url返回时,以前存储的令牌和执行url信息将丢失。它将变为空。您需要将其存储在cookie或数据库表中,并在返回站点执行时检索它请检查此答案,这与您问的问题类似。curl verbose开关会给你?任何响应头?你能发布执行url吗?@lib
当您从批准url返回时,以前存储的令牌和执行url信息将丢失。它将变为空。您需要将其存储在cookie或数据库表中,并在返回站点执行时检索它请检查此答案,这与您问的问题类似。curl verbose开关会给你?任何响应头?你能发布执行url吗?@lib 4-这种情况包括缺少头-我已经为answer@adyvcurl没有响应,这是执行url
if (isset($_GET['token']) && isset($_GET['PayerID']) ){
$received_token = sanitize_text_field ( $_GET['token'] );
$received_payerId = sanitize_text_field ( $_GET['PayerID'] );
$execute_urls = get_option('paypal_processing');
$payment_execute_url= $execute_urls[$current_user->ID];
$execute_urls[$current_user->ID] = '';
update_option('paypal_processing',$execute_urls);
$payment_execute = array(
'payer_id' => $received_payerId
);
$json = json_encode($payment_execute);
$json_resp = make_post_call($payment_execute_url, $json,$received_token);
print_r($json_resp);
echo "Payment Execute processed " . $json_resp['id'] ." with state '". $json_resp['state']."'";
}
function make_post_call($url, $postdata,$token) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
#curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec( $curl );
if (empty($response)) {
// some kind of an error happened
print 'curl error';
curl_close($curl); // close cURL handler
} else {
$info = curl_getinfo($curl);
// echo "Time took: " . $info['total_time']*1000 . "ms\n";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
//echo "Received error: " . $info['http_code']. "\n";
//echo "Raw response:".$response."\n";
exit('paypal error');
}
}
// Convert the result from JSON format to a PHP array
$jsonResponse = json_decode($response, TRUE);
return $jsonResponse;
}