我被要求使用交易ID通过PayPal API检索买家的电子邮件地址。我可以看到我可以使用GetTransactionDetails函数来执行此操作。
我已经设法使用我使用SOAP提供的凭据登录但是在运行GetTransactionDetails时,我收到了错误。
这是我的代码:
$user = "XXXXXX";
$pass = "XXXXXX";
$sign = "XXXXXX";
$socket_context = stream_context_create(array('http' => array('protocol_version' => 1.0)));
$client = new SoapClient("https://www.paypal.com/wsdl/PayPalSvc.wsdl", array('exceptions' => 0,'stream_context' => $socket_context,'trace' => 1));
$params = array(
"Username" => $user,
"Password" => $pass,
"Signature" => $sign);
$credentials = new stdClass();
$credentials->Credentials = new SoapVar(
$params,
SOAP_ENC_OBJECT,
'Credentials');
$headers = new SoapVar(
$credentials,
SOAP_ENC_OBJECT,
'CustomSecurityHeaderType',
'urn:ebay:apis:eBLBaseComponents');
$client->__setSoapHeaders(
new SoapHeader(
'urn:ebay:api:PayPalAPI',
'RequesterCredentials',
$headers)
);
if (is_soap_fault($credentials)) {
print "SOAP Fault: $credentials->faultcode, $credentials->faultstring<br />";
} else {
print "logged in";
}
$args = array(
"Version" => "124.0",
"TransactionID" => "12345ABCDE");
$GetTransactionDetailsRequest = new stdClass();
$GetTransactionDetailsRequest->GetTransactionDetailsRequest = new SoapVar(
$args,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequestType',
'urn:ebay:api:PayPalAPI');
$params = new SoapVar(
$GetTransactionDetailsRequest,
SOAP_ENC_OBJECT,
'GetTransactionDetailsRequest');
$result = $client->GetTransactionDetails($params);
print "<pre>";
print_r($result);
print "</pre>";
这是我在运行之后看到的错误:
SoapFault Object
(
[message:protected] => Bad Request
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /location/to/file.php
[line:protected] => 42
[trace:Exception:private] => Array
(
[0] => Array
(
[function] => __doRequest
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => XXXXXXXXXXXXXXXXXXXX
[1] => https://api.sandbox.paypal.com/2.0/
[2] =>
[3] => 1
[4] => 0
)
)
[1] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => GetTransactionDetails
[1] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[2] => Array
(
[file] => /location/to/file.php
[line] => 42
[function] => GetTransactionDetails
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => SoapVar Object
(
[enc_type] => 301
[enc_value] => stdClass Object
(
[GetTransactionDetailsRequest] => SoapVar Object
(
[enc_type] => 301
[enc_value] => Array
(
[Version] => 124.0
[TransactionID] => 12345ABCDE
)
[enc_stype] => GetTransactionDetailsRequestType
[enc_ns] => urn:ebay:api:PayPalAPI
)
)
[enc_stype] => GetTransactionDetailsRequest
)
)
)
)
[previous:Exception:private] =>
[faultstring] => Bad Request
[faultcode] => HTTP
)
它失败的路线是:
$result = $client->GetTransactionDetails($params);
我以前从未使用过PayPal API,而且我从几个不同的示例中删除了代码,所以如果有人知道更好的方法,那就太棒了!
注意:
答案 0 :(得分:0)
经过多次挖掘,结果证明API违反了Sandbox Endpoint!我在调用SoapClient后立即将以下代码添加到我的脚本中:
<?php
echo '<a href="site_url">Link content</a>';
?>
现在有效!