PayPal错误。此交易无效。请返回收件人的网站,使用他们的常规结帐流程完成您的交易

时间:2015-03-06 10:36:43

标签: paypal paypal-sandbox

我正在尝试将PayPal Direct payement实施到我的网站。

在进行SetExpressCheckout调用时,我从PayPal返回一个Succes令牌:

Array
(
    [TIMESTAMP] => 2015-03-06T10:16:55Z
    [CORRELATIONID] => 7d0a42f74fa6b
    [ACK] => Success
    [VERSION] => 121
    [BUILD] => 15420584
    [AMT] => 125.00
    [CURRENCYCODE] => EUR
    [AVSCODE] => X
    [CVV2MATCH] => M
    [TRANSACTIONID] => 29A40018PU668530B
)

响应如下:

TIMESTAMP = 2015%2D03%2d06T10%3a16%3a55Z&安培;的correlationID = 7d0a42f74fa6b&安培; ACK =成功&安培; VERSION = 121安培; BUILD = 15420584&安培; AMT = 125%2e00&安培; CURRENCYCODE = EUR&安培; AVSCODE = X&安培; CVV2MATCH = M&安培; TRANSACTIONID = 29A40018PU668530B

我试图以几种方式取消网址,以便将响应发送回顶级贝宝。我现在使用的是:

$result = rawurldecode($result);

结果看起来像是不受欢迎的: TIMESTAMP = 2015-03-06T10:16:55Z&安培;的correlationID = 7d0a42f74fa6b&安培; ACK =成功&安培; VERSION = 121安培; BUILD = 15420584&安培; AMT = 125.00&安培; CURRENCYCODE = EUR&安培; AVSCODE = X&安培; CVV2MATCH = M&安培; TRANSACTIONID = 29A40018PU668530B

我试图用strtolower来哄骗这个请求结果如下:

小写结果:

时间戳= 2015-03-06t10:31:45Z&安培;的correlationID = 490f48424be02&安培; ACK =成功&安培;版本= 121安培;建立= 15420584&安培; AMT =125.00¤cycode= EUR&安培; avscode = X&安培; cvv2match = M&安培;的transactionId = 80g4320670816912n

我在cycode之前意识到这个奇怪的角色:¤

当我尝试使用PHP的重定向发回令牌时,(有或没有小写):

header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&'.$result);

我被重定向到: https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION= ...

话说:

  

此交易无效。请返回收件人的网站   使用常规结帐流程完成交易。返回   对商家目前,我们无法处理您的请求。   请返回并尝试其他选项。试验场地

即使我使用的是非小写版本,我也会遇到同样的错误!

我意识到localhost是个问题。上传我的网站时,SetExpressCheckout令牌很好。

现在问题是当我收回这个令牌时: TOKEN = EC%2d0PA6125744246545G&安培; TIMESTAMP = 2015%2D03%2d06T13%3A10%3a09Z&安培;的correlationID = 10c7929423b68&安培; ACK =成功&安培; VERSION = 121安培; BUILD = 15640276

使用以下参数发送GetExpressCheckoutDetails请求:

Array
(
    [METHOD] => GetExpressCheckoutDetails
    [USER] => ...
    [PWD] => ...
    [SIGNATURE] => ...
    [VERSION] => 121
    [TOKEN] => TOKEN=EC-0PA6125744246545G&TIMESTAMP=2015-03-06T13:10:09Z&CORRELATIONID=10c7929423b68&ACK=Success&VERSION=121&BUILD=15640276
)

我仍然收到令牌错误:

Array
(
    [TIMESTAMP] => 2015-03-06T13:10:10Z
    [CORRELATIONID] => 4ec125d8280f3
    [ACK] => Failure
    [VERSION] => 121
    [BUILD] => 15640276
    [L_ERRORCODE0] => 10410
    [L_SHORTMESSAGE0] => Invalid token
    [L_LONGMESSAGE0] => Invalid token.
    [L_SEVERITYCODE0] => Error
)

感谢您帮助我解决这个问题!

1 个答案:

答案 0 :(得分:2)

我意识到这个问题已经过了一年多了,但我认为值得回答。

首先,根据您在数组中显示的内容,令牌无效的响应是准确的:

TOKEN=EC-0PA6125744246545G&TIMESTAMP=2015-03-06T13:10:09Z&CORRELATIONID=10c7929423b68&ACK=Success&VERSION=121&BUILD=15640276

这应该停留在和号(&)上,如下所示,可以像这样访问$response数组,将单个值传递到下一个API请求中:

 $response["TOKEN"]; // this will ONLY return "EC-0PA6125744246545G" - remember that 
 // these tokens don't last beyond a few hours, but your next call should be 
 // a few seconds after the SetEC.

该决议涉及一种特定方法:http_build_query()

// this is a method in a class that I built. Use it as needed
public function startRequest($params = array()){
    // this creates a handle to use later to add the request parameters to the curl call
    $request = http_build_query($params);

    $ch = curl_init();

    // cURL settings
    // the variable $this->_endpoint in this case points to:
    // https://api-3t.sandbox.paypal.com/nvp - you may be using SOAP, 
    // so URL will be different
    $curlOptions = array(
        CURLOPT_URL             => $this->_endpoint,
        CURLOPT_VERBOSE         => 1,
        CURLOPT_SSL_VERIFYPEER  => false,
        CURLOPT_SSL_VERIFYHOST  => 2,
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_POST            => 1,
        CURLOPT_POSTFIELDS      => $request
    );

    curl_setopt_array($ch, $curlOptions);

    // send request - $response will hold the API response
    $response = curl_exec($ch);

$response变量是来自PayPal的数组响应,可以像这样使用:

$responseText = '';
foreach($response as $k=>$v){
        $responseText .= $k ."=". $v ."\r\n";
}

// log the API response (and the request) to a file - always a good idea, 
// in case you need support for issues later on.
file_put_contents(path_to_log_file, current_time . ' MST - API response: \r\n' . $responseText ."\r\n===========\r\n", FILE_APPEND);

// also, you can access each value in the $response array so that you can use them 
// in later calls like DoEC:
$response["TOKEN"];

如果我能进一步澄清,请告诉我。