2014-07-16 3 views
0

PAYPAL API를 사용하고 있습니다.PAYPAL API를 사용할 때 잘못된 거래

성공적으로 setExpressCheckout을 호출하면 (이 메서드를 호출 한 후 ACK = 성공을 얻음) 성공적으로 처리 할 수있는 전체 링크를 얻을 수 있습니다.

전체 링크 (https://www.paypal.com/cgi-bin/webscr?cmd=_flow&SESSION=[SESSION_TOKEN])를 가져온 후 전체 링크는 오류를 포함하는 페이지를 나타냅니다.

오류 :

이 트랜잭션은 유효하지 않습니다. 수취인의 웹 사이트로 돌아가 정기적 인 결제 흐름을 사용하여 거래를 완료하십시오. 이 때 상인

반환, 우리는 귀하의 요청을 처리 할 수 ​​없습니다. 로 돌아가서 다른 옵션 여기

을 시도하십시오 나의 코드입니다 :

은 $ htmlpage 전체 링크 ('THIS LINE 확인은'별표 발언으로 라인 참조)

있어

<?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\r\n". 
        "Content-Length: ".strlen($body_data_txt)."\r\n". 
        "Content-type: "."application/x-www-form-urlencoded"."\r\n", 
       '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())).'||'; 
} 
?> 

내 계정은 비즈니스 계정입니다. 문제의 원인은 무엇입니까? 구성 문제로 보입니다 - 확인해야 할 설정이 있습니까?

감사합니다 :)

+0

자세한 정보를 제공해야합니다. 정확한 SetEC API 호출 및 응답을 게시하여 자격 증명을 생략하십시오. –

+0

방금이 게시물에 코드를 추가했습니다. 시청할 수 있습니다. – user3834980

+0

고맙습니다.하지만 제가보고 싶은 것은 코드의 결과입니다. PayPal로 보내지는 데이터를보고 싶습니다. SetEC 호출, 그리고 paypal로부터의 응답. –

답변

0

문제는 내가 'TOKEN ='와 페이팔 페이지를 열었습니다, 나는 (대문자 사항) '= 토큰'에 의해 열해야한다는 것입니다.

라인 :

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

은 다음과 같아야합니다

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

감사 : 어쨌든 :)