在我的网站上,我希望实现自适应贝宝支付方法。有没有可能用curl .Can实现?谁提供php代码进行自适应支付?
发布于 2014-10-18 01:29:31
以下是paypal的curl调用代码
对于自适应支付,首先你需要用你的'clientId‘和'secret’生成访问令牌。然后,使用该访问令牌,您可以调用Paypal自适应支付API。
我已经给出了生成访问令牌的示例。然后从paykey获取交易细节(您可以根据需要更改调用)。
//Get access token from client Id
$ch = curl_init();
$clientId = PAYPAL_CLIENT_ID;
$secret = PAYPAL_CLIENT_SECRET;
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/oauth2/token');// Change it to "https://api.paypal.com/v1/oauth2/token" for live
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);
$accessToken = null;
if (empty($result))
return 'Access Token could not generated';
else {
$json = json_decode($result);
$accessToken = $json->access_token;
}
curl_close($ch);
/**
* Get payment transaction details from
* - AccessToken
* - PayKey
*/
$curl = curl_init('https://api.sandbox.paypal.com/v1/payments/payment/' . $input['payKey']);
curl_setopt($curl, CURLOPT_POST, false);
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 ' . $accessToken,
'Accept: application/json',
'Content-Type: application/json'
));
$response = curl_exec($curl);
$result = json_decode($response);你可以有一个paypal curl调用https://github.com/paypal/rest-api-curlsamples/blob/master/execute_all_calls.php的参考例子
发布于 2014-10-15 20:56:09
发布于 2016-07-29 12:07:21
//This example for making a payment //对于沙盒模式$apiUrl = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
//对于实时模式//$apiUrl = 'https://svcs.paypal.com/AdaptivePayments/Pay';
$_username = "**********";
$_password = "**********";
$_ipaddress = "**********";
$_application_id = "**********";
$returnUrl = "**********"
$cancelUrl = "****************";
$receivers = array(
array(
'email' => "receiver1@abc.com",
'amount' => 50,
'primary' => true
),
array(
'email' => "receiver2@abc.com",
'amount' => 20,
'primary' => false
)
);
$requestEnvelope = array(
'errorLanguage' => 'en_US',
'detailLevel' => 'ReturnAll'
);
$packet = array(
'actionType' => "PAY",
'currencyCode' => "USD",
'feesPayer' => "EACHRECEIVER",
'receiverList' => array(
'receiver' => $receivers
),
'memo' => "Here you can write memo desc",
'returnUrl' => $returnUrl,
'cancelUrl' => $cancelUrl,
'requestEnvelope' => $requestEnvelope
);
$headers = array(
"X-PAYPAL-SECURITY-USERID: " . $_username,
"X-PAYPAL-SECURITY-PASSWORD: " . $_password,
"X-PAYPAL-SECURITY-SIGNATURE: " . $_signature,
"X-PAYPAL-DEVICE-IPADDRESS: ".$_ipaddress,
"X-PAYPAL-REQUEST-DATA-FORMAT: JSON",
"X-PAYPAL-RESPONSE-DATA-FORMAT: JSON",
"X-PAYPAL-APPLICATION-ID: " . $_application_id);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . $call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($packet));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
print_r( json_decode(curl_exec($ch), TRUE));
//After execution of request , you got a paykey and using that key you can receive payment from Buyer.https://stackoverflow.com/questions/26380575
复制相似问题