我创建一个PayPal支付用PHP,这是到目前为止的代码:宝PHP REST API
$ch = curl_init();
$clientId = "clientID";
$secret = "secret";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
//print_r($json->access_token);
if ($_POST['creditcard'] == 'paypal') {
$data = '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://returnurl.com",
"cancel_url":"http://returnurl.com"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"' . preg_replace("/[^0-9,.]/", "", $order_price) .'",
"currency":"' . $currency_code .'"
},
"description":"' . ucfirst($type) . ' Logo Purchase. ' . '"
}
]
}';
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
"Authorization: Bearer " . $json->access_token,
"Content-length: ".strlen($data))
);
print_r($data);
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else {
$json_output = json_decode($result);
print_r($result);
if(isset($json_output->{'links'}[2]->{'href'}))
$_SESSION['execute_url'] = $json_output->{'links'}[2]->{'href'};
if(isset($json_output->{'links'}[1]->{'href'}))
header('Location:' .$json_output->{'links'}[1]->{'href'});
}
}
}
curl_close($ch);
我签我的测试帐号,我重定向到重定向URL。所以我假设一切工作正常。接下来的部分是我无法弄清楚的。我正在尝试在这里执行付款。
我是否使用从上述以前代码收到的付款网址?
我试着这样做:
$data = '{ "payer_id" : "' .$_GET['PayerID'] . '" }';
curl_setopt($ch, CURLOPT_URL, $stored_execute_url;
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
"Authorization: Bearer " . $_GET['token'],
"Content-length: ".strlen($data))
);
print_r($data);
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
所有我得到的是“错误:没有响应”
我一直在关注这个链接https://developer.paypal.com/webapps/developer/docs/integration/web/accept-paypal-payment/,我能够得到,直到最后一部分。
我想通了。我使用PayPal返回网址中给出的令牌。我尝试使用原始的令牌,并购买了。贝宝返回您的网站时,令牌是否有目的? – Marquisk2