我一直在研究并尝试使用PayPal Adaptive API进行2天的测试 我亲手用php cURL写了一个相当简单的测试代码...
protected function makePayment($a=''){
if($a==''){return 'OOPs';}
$amount = "1.00";
$receiver = "RECEIVER TEST EMAIL";
$url = 'https://api-3t.sandbox.paypal.com/nvp/Pay';
$paypalHeaders = array(
'X-PAYPAL-SECURITY-USERID : XXXXXXXX',
'X-PAYPAL-SECURITY-PASSWORD : XXXXXXX',
'X-PAYPAL-SECURITY-SIGNATURE : XXXXXXX',
'X-PAYPAL-SECURITY-VERSION: 1.8.6',
'X-PAYPAL-DEVICE-IPADDRESS: <MY SITE IP>',
'X-PAYPAL-REQUEST-DATA-FORMAT : NV',
'X-PAYPAL-RESPONSE-DATA-FORMAT : NV',
'X-PAYPAL-APPLICATION-ID : APP-80W284485P519543T',
'X-PAYPAL-SANDBOX-EMAIL-ADDRESS: MY-SANDBOX-APP-OWNER@email.com'
);
// Format the call payload.
$payload = array(
"actionType"=>"PAY",
"currencyCode"=>"USD",
"receiverList"=>array(
"receiver"=>array(
array("amount"=>$amount,"email"=>$receiver)
)
),
"returnUrl"=>"https://biddingblock.com/api/payment.php",
"cancelUrl"=>"https://biddingblock.com/index.htm",
"requestEnvelope"=>array(
"errorLanguage"=>"en_US",
"detailLevel"=>"ReturnAll"
)
);
// Make the call
$curl = curl_init();
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $paypalHeaders);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
$Response = curl_exec($curl);
curl_close($curl);
return $Response;
*我在此代码上尝试的所有修改仍然没有超过一垒,我收到以下错误*
HTTP / 1.1 400错误请求 服务器:AkamaiGHost 哑剧版:1.0 内容类型:text / html 内容长度:176 到期日:2014年3月31日星期一12:31:45 GMT 日期:星期一,2014年3月31日12:31:45 GMT 连接:关闭
处理您的请求时出错。
参考编号#166.d80300cc.1396269105.de2dda4
我没有使用Adaptive API PHP SDK,这或多或少是完整代码减去真正的密钥和接收者电子邮件
我做错了什么? 有人可以帮忙吗?
PS:我也尝试使用DATA-FORMAT JSON和JSON编码有效载荷数组。
答案 0 :(得分:0)
这对我有用:
$nvp = "&PAYMENTREQUEST_0_PAYMENTACTION=SALE";
$nvp.= "&PAYMENTREQUEST_0_AMT=19.95";
$nvp.= "&PAYMENTREQUEST_0_CURRENCYCODE=USD";
$nvp.= "&RETURNURL=http://www.dropial.com/success.html";
$nvp.= "&CANCELURL=http://www.dropial.com/cancel.html";
$response = wpp_hash('SetExpressCheckout', $nvp);
if ($response['ACK'] == 'Success') {
$this->Session->setFlash('Payment Successful');
} else {
$this->Session->setFlash('Payment Failed');
}
函数wpp_hash定义为:
public function wpp_hash($method = null, $nvp = null) {
$curl_handler = curl_init();
curl_setopt($curl_handler, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp';
curl_setopt($curl_handler, CURLOPT_VERBOSE, 1);
curl_setopt($curl_handler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_handler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl_handler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handler, CURLOPT_POST, 1);
$required_nvp = 'METHOD='.$method;
$required_nvp .= '&VERSION='.urlencode(Configure::read('Paypal.version'));
$required_nvp .= '&USER='.urlencode(Configure::read('Paypal.username'));
$required_nvp .= '&PWD='.urlencode(Configure::read('Paypal.password'));
$required_nvp .= '&SIGNATURE='.urlencode(Configure::read('Paypal.signature'));
curl_setopt($curl_handler, CURLOPT_POSTFIELDS, $required_nvp.$nvp);
$http_responder = curl_exec($curl_handler);
curl_close($curl_handler);
pr($http_responder);
if (!$http_responder) {
throw new BadRequestException($method.'failed: '.curl_error($curl_handler).' ('.curl_errno($curl_handler).')');
}
$responder = explode('&', $http_responder);
$parsed_response = array();
foreach($responder as $response) {
$response_array = explode('=', $response);
if (count($response_array) >= 1){
$parsed_response[$response_array[0]] = urldecode($response_array[1]);
}
}
if ((count($parsed_response) < 1) || !array_key_exists('ACK', $parsed_response)){
throw new BadRequestException('Invalid HTTP Response for POST request ('.$required_nvp.$nvp.') to '.Configure::read('Paypal.endpoint'));
}
return $parsed_response;
}
您可以更改方法以使用其他PayPal交易。就我而言,我正在使用快速结账。
答案 1 :(得分:0)
我已经超越了这个并通过以下方法运行它来解决这个问题。
谢谢
这是我采用的解决方案......
$payload = array(
"actionType"=>"PAY",
"currencyCode"=>"USD",
"receiverList"=>array(
"receiver"=>array(
array("amount"=>$amount,"email"=>$receiver)
)
),
"feesPayer"=>"PRIMARYRECEIVER",
"returnUrl"=>"MyRETURN_URL",
"cancelUrl"=>"MyCANCEL_URL",
"requestEnvelope"=>array(
"errorLanguage"=>"en_US",
"detailLevel"=>"ReturnAll"
)
);
$request = 'curl -s --insecure'.$TEST_url.' -d "'.addslashes(json_encode($payload)).'"';
$response = json_decode(exec($request));