我想使用paypal api创建付款,看起来它正在运行,因为它正在加载https://www.sandbox.paypal.com/checkoutnow?页面,但然后它更改为错误页面,没有任何错误代码(至少我没有看到任何错误代码)。
创建付款文件:
$ch = curl_init();
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_SSLVERSION , 6); //NEW ADDITION
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);
$token = $json->access_token;
}
curl_close($ch); //THIS CODE IS NOW WORKING!
$ch = curl_init();
$data = '{
"intent": "sale",
"redirect_urls":
{
"return_url": "http://' . $_SERVER['SERVER_NAME'] . '/git",
"cancel_url": "http://' . $_SERVER['SERVER_NAME'] . '/niegit"
},
"payer":
{
"payment_method": "paypal"
},
"transactions": [
{
"amount":
{
"total": "50",
"currency": "USD"
},
"description": "This is the payment transaction description.",
"payment_options": {
"allowed_payment_method": "INSTANT_FUNDING_SOURCE"
},
}]
}';
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer " . $token
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if(empty($result))die(curl_error($ch));
else
{
print_r(json_encode($result));
}
curl_close($ch);
付款执行文件:
$ch = curl_init();
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_SSLVERSION , 6); //NEW ADDITION
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);
$token = $json->access_token;
}
curl_close($ch); //THIS CODE IS NOW WORKING!
$paymentURL = 'https://api.sandbox.paypal.com/v1/payments/payment/' . $_POST['paymentID'] . "/execute/ ";
$ch = curl_init();
$data = '{
"payer_id": "'. $_POST['payerID'] .'"
}';
curl_setopt($ch, CURLOPT_URL, $paymentURL);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer " . $token
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
if(empty($result))die(curl_error($ch));
else
{
print_r(json_encode($result));
}
curl_close($ch);
答案 0 :(得分:0)
我假设你放置了JS按钮,就像Paypal指令一样。
检查付款回拨方式。如果您遵循Paypal指令,则解决或拒绝将不存在。
paypal.Button.render({
env: 'sandbox', // Specify 'sandbox' for the test environment
payment: function (resolve, reject) {
// Set up the payment here, when the buyer clicks on the button
var createPaymentUrl = '';
paypal.request.post(createPaymentUrl)
.then(function (data) {
resolve(data.paymentID);
})
.catch(function (data) {
});
},
onAuthorize: function (data, actions) {
// Execute the payment here, when the buyer approves the transaction
},
onCancel: function (data, actions) {
},
onError: function (err) {
// Show an error page here, when an error occurs
}
}, '#paypal-button');