我正在尝试集成贝宝支付网关api,但它响应的是整数1。我不确定出了什么问题。我在这里分享我的代码。我正在使用php。如果我要更改卡的详细信息,它会停止响应或花费过多的响应时间,则我成功获得了gettinig令牌。
<?php
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
//open connection
$ch = curl_init();
$client = "Client Id Removed";
$secret = "Secret code Removed";
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, $client.":".$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);
}
curl_close($ch);
$c = curl_init();
$data = '{
"intent":"sale",
"payer": {
"payment_method": "CREDIT_CARD",
"funding_instruments": [
{
"credit_card": {
"number": "5454545454545454",
"type": "mastercard",
"expire_month": 12,
"expire_year": 2021,
"cvv2": 111,
"first_name": "Joe",
"last_name": "Shopper"
}
}
]
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
},
"description":"This is the payment transaction description."
}
]
}
';
curl_setopt($c, CURLOPT_URL, "https://api.sandbox.paypal.com/v2/payments/payment");
curl_setopt($c, CURLOPT_CUSTOMREQUEST ,"POST");
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $data);
curl_setopt($c, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Authorization: Bearer ".$json->access_token));
$result = curl_exec($c);
curl_close($c);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
print_r($result);
}
?>
答案 0 :(得分:0)
Payments API不能直接用于处理信用卡(付款方式:“ CREDIT_CARD”)-请参阅红色消息。它仅在几个国家/地区短暂提供,并在很久以前就被PayPal收购Braintree删除。
实际上,Braintree取代了旧的经典API PayPal Payments Pro。 REST API没有。