我和另一个程序员已经在这几天毫无乐趣了。我们现在所要做的就是从贝宝那里得到一个成功的回应。不幸的是,paypal的api被糟糕地记录在案。
这是我们的代码:
<?php
class Paypal {
/**
* Last error message(s)
* @var array
*/
protected $_errors = array();
/**
* API Credentials
* Use the correct credentials for the environment in use (Live / Sandbox)
* @var array
*/
protected $_credentials = array(
'USER' => '*************************',
'PWD' => '****************',
'SIGNATURE' => '************************************************',
);
/**
* API endpoint
* Live - https://api-3t.paypal.com/nvp
* Sandbox - https://api-3t.sandbox.paypal.com/nvp
* @var string
*/
protected $_endPoint = 'https://svcs.sandbox.paypal.com/AdaptivePayments/Pay';
/**
* API Version
* @var string
*/
protected $_version = '74.0';
public function newstartpayment() {
//set PayPal Endpoint to sandbox
$url = trim("https://svcs.sandbox.paypal.com/AdaptivePayments/Pay");
//PayPal API Credentials
$API_UserName = $_credentials['USER'];
$API_Password = $_credentials['PWD'];
$API_Signature = $_credentials['SIGNATURE'];
//Default App ID for Sandbox
$API_AppID = "******************";
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";
//Create request payload with minimum required parameters
$bodyparams = array (
"requestEnvelope.errorLanguage" => "en_US",
"actionType" => "PAY",
"currencyCode" => "USD",
"cancelUrl" => "http://www.paypal.com",
"returnUrl" => "http://www.paypal.com",
"receiverList.receiver(0).email" => "************@paypal.com", //TODO
"receiverList.receiver(0).amount" => "40", //TODO
"receiverList.receiver(0).primary" => "true", //TODO
"receiverList.receiver(1).email" => "****************@paypal.com", //TODO
"receiverList.receiver(1).amount" => "30", //TODO
"receiverList.receiver(1).primary" => "false", //TODO
'USER' => '************************',
'PWD' => '***********',
'SIGNATURE' => '*************************************'
);
// convert payload array into url encoded query string
$body_data = http_build_query($bodyparams, "", chr(38));
try
{
//create request and add headers
$params = array("http" => array(
"method" => "POST",
"content" => $body_data,
"header" => "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
"X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
"X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
"X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
"X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n"
));
//create stream context
$ctx = stream_context_create($params);
//open the stream and send request
$fp = @fopen($url, "r", false, $ctx);
//get response
$response = stream_get_contents($fp);
//check to see if stream is open
if ($response === false) {
throw new Exception("php error message = " . $php_errormsg);
}
//close the stream
fclose($fp);
return $response;
}
catch (Exception $e) {
error_log($e->getMessage());
print_r($e);
return false;
}
}
$paypal = new Paypal();
?>
好,现在执行此代码时,会出现以下错误:
PayPal返回:2012-02-19T15:07:01.883-08:00失败ff3b99b56fcb72486531520003平台应用程序RorApplicationAuthentication失败。API凭据不正确。
我们已经穷途末路了,请上帝保佑…
最佳答案
您正在使用PyPal沙盒或Live PayPal API凭据。
关于php - PHP-PayPal集成-向多个帐户付款,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9354267/