dongzai3139 2014-07-16 11:32
浏览 52
已采纳

使用PAYPAL API时无效的事务

I am using PAYPAL API.

I success calling the setExpressCheckout (after calling this method I got ACK=Success) and therefore get a full link that I can proceed with.

After getting the full link (https://www.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=[SESSION_TOKEN]), the full link represent a page, that includes error.

The error:

This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow.

Return to merchant

At this time, we are unable to process your request. Please return to and try another option

Here is my Code:

<?php

/*.
    require_module 'standard';
    require_module 'standard_reflection';
    require_module 'spl';
    require_module 'mysqli';
    require_module 'hash';
    require_module 'session';
    require_module 'streams';
.*/

//turn php errors on
//ini_set('track_errors', true);
    require_once __DIR__ . "/stdlib/all.php";
    require_once __DIR__ . "/SqlManager.php";

/*. array .*/ $body_data = null;
$body_data_txt = "";
/*. string .*/ $htmlpage  = "";
/*. array .*/ $keyAr  = array();
/*. array .*/ $tokenAr = array();
$response = "";
    /*. SqlManager .*/ $sqlm = null;

session_start();

$url = trim('https://api-3t.paypal.com/nvp');
$urlRun = trim('https://www.paypal.com/cgi-bin/webscr');

$body_data = array( 'USER' => *****",
                    'PWD' => "******",                                    
                    'SIGNATURE' => "*****",
                    'VERSION' => "95.0",
                    'PAYMENTREQUEST_0_PAYMENTACTION' => "Sale",
                    'PAYMENTREQUEST_0_AMT' => (string)$_SESSION["AMOUNT"],
                    'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
                    'RETURNURL' => "******",
                    'CANCELURL' => "******",
                    'METHOD' => "SetExpressCheckout"
                                );

$body_data_txt = http_build_query($body_data, '', chr(38));
try
{
    $sqlm = new SqlManager(true);
    //create request and add headers
    $params = array(
            'http' => array(
                'protocol_version' => "1.1",
                'method' => "POST",
                'header' => "".
                    "Connection: close
".
                    "Content-Length: ".strlen($body_data_txt)."
".
                    "Content-type: "."application/x-www-form-urlencoded"."
",
                'content' => $body_data_txt
            ));

    //create stream context
     $ctx = stream_context_create($params);

    //open the stream and send request
    try {
        $fp = fopen($url, 'r', false, $ctx);
    } catch(ErrorException $e) {
        throw new ErrorException("cannot open url" . $url . " error:" . $e->getMessage());
    }
     //get response
     $response = (string)stream_get_contents($fp);
     //check to see if stream is open
     if ($response === "") {
        throw new Exception("php error message = " . "$php_errormsg");
     }

     //close the stream
     fclose($fp);   

     $key = explode("&", $response);

     $keyAr = array();
     foreach ($key as $i => $value) {
        $tmpAr = explode("=", $value);
        if(sizeof($tmpAr) > 1) {
            $keyAr[$tmpAr[0]] = $tmpAr[1];
        }
     }

     if (substr($response, 0, 1) === "<") {
        echo $response;
     } else {
            // Extract the response details.
         if((0 == sizeof($keyAr)) || !array_key_exists('ACK', $keyAr) || (string)$keyAr["ACK"] !== "Success") {
            if (array_key_exists('L_ERRORCODE0', $keyAr) && array_key_exists('L_LONGMESSAGE0', $keyAr)) {
               echo cast("string", htmlspecialchars(urldecode((string)$keyAr["L_ERRORCODE0"]))) . ',' .
                    cast("string", htmlspecialchars(urldecode((string)$keyAr["L_LONGMESSAGE0"])));
            } else {
                echo "Unkown server response!";
            }
         } else {
// ********************************************
               $htmlpage = $urlRun . "?cmd=_express-checkout&".  "TOKEN=" . (string)$keyAr["TOKEN"]; // ******************* IS THIS LINE OK????
// ********************************************
               echo "ok," . $htmlpage; 
            } 
        }
    }

catch(Exception $e)
{
  echo 'Message: ||' .cast("string", str_replace('"', '\\"', $e->getMessage())).'||';
}
?>

the $htmlpage got the full link (see the line with the asterisks remark 'IS THIS LINE OK')

My account is business account. What may be the cause for the problem? Seem kind of configuration problem - are there any setups I shall check?

Thanks :)

  • 写回答

1条回答 默认 最新

  • douxu5845 2014-07-16 20:32
    关注

    The problem is that I have opened the paypal page with 'TOKEN=', and I should open by 'token=' (capitalized letter matter).

    The line:

    $htmlpage = $urlRun . "?cmd=_express-checkout&". "TOKEN=" . (string)$keyAr["TOKEN"];

    should be:

    $htmlpage = $urlRun . "?cmd=_express-checkout&". "token=" . (string)$keyAr["TOKEN"];

    Thanks, anyway :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog