2012-07-02 55 views
0

調用PayPal CreateInvoice API的代碼。它總是失敗,說「無效的請求」,並得到errorId 580001.我經歷了幾次填充請求和API文檔的代碼。不知道請求中的數據是錯誤的。請求中可能有什麼錯誤?我在這裏錯過了什麼嗎?PayPal API createInvoice始終返回errorId 580001

function getInvoiceAPIHeader() 
    { 
     global $API_Username, $API_Password, $Signature; 

     $API_Username = $this->config['username']; 
     $API_Password = $this->config['password']; 
     $Signature = $this->config['signature']; 


     $headers[0] = "Content-Type: text/namevalue";    // either text/namevalue or text/xml 
     $headers[1] = "X-PAYPAL-SECURITY-USERID: $API_Username"; //API user 
     $headers[2] = "X-PAYPAL-SECURITY-PASSWORD: $API_Password"; //API PWD 
     $headers[3] = "X-PAYPAL-SECURITY-SIGNATURE: $Signature"; //API Sig 
     $headers[4] = "X-PAYPAL-APPLICATION-ID: {$this->APPLICATION_ID}"; //APP ID   
     $headers[6] = "X-PAYPAL-REQUEST-DATA-FORMAT: ".self::REQUEST_DATA_FORMAT.""; //Set Name Value Request Format 
     $headers[7] = "X-PAYPAL-RESPONSE-DATA-FORMAT: ".self::RESPONSE_DATA_FORMAT.""; //Set Name Value Response Format  

     Debugger::dump($headers); 
     return $headers; 
    } 



function curlRequest($str_req) 
{  
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $this->end_url); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getInvoiceAPIHeader());  

    curl_setopt($ch, CURLOPT_HEADER, 1); // tells curl to include headers in response, use for testing 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, TRUE); 

    // setting the NVP $my_api_str as POST FIELD to curl 
    $log_req = $aryRresponse = explode("&", $str_req); 
    var_dump($log_req); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $str_req); 

    // getting response from server 
    $httpResponse = curl_exec($ch); 
    //var_dump($httpResponse); 

    if(!$httpResponse) 
    { 
     Debugger::dump("no response"); 
     $response = "{$this->end_url} failed: ".curl_error($ch)."(".curl_errno($ch).")"; 
     return $response; 
    } 

    $aryRresponse = explode("&", $httpResponse); 
    var_dump($aryRresponse); 
    return $httpResponse; 
} 

請求轉儲:

array(
    (int) 0 => 'Content-Type: text/namevalue', 
    (int) 1 => 'X-PAYPAL-SECURITY-USERID: stest_1339339519_biz_api1.paypal.com', 
    (int) 2 => 'X-PAYPAL-SECURITY-PASSWORD: 1339339539', 
    (int) 3 => 'X-PAYPAL-SECURITY-SIGNATURE: A2I9zTt-d7IIbjVBlzNeLjVm9UJxAPoaKvgzcIz6c6G1-sLSKn5jcI3b', 
    (int) 4 => 'X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T', 
    (int) 6 => 'X-PAYPAL-REQUEST-DATA-FORMAT: NV', 
    (int) 7 => 'X-PAYPAL-RESPONSE-DATA-FORMAT: NV' 
) 

array 
    0 => string 'invoice.merchantEmail=stest_1339339519_biz%40paypal.com' (length=55) 
    1 => string 'invoice.payerEmail=stest_1340973819_per%40paypal.com' (length=52) 
    2 => string 'invoice.currencyCode=USD' (length=24) 
    3 => string 'invoice.number=PP-99' (length=20) 
    4 => string 'invoice.paymentTerms=Net10' (length=26) 
    5 => string 'invoice.itemList.item%281%29.name=Coke' (length=38) 
    6 => string 'invoice.itemList.item%281%29.description=From+CocaCola' (length=54) 
    7 => string 'invoice.itemList.item%281%29.quantity=2' (length=39) 
    8 => string 'invoice.itemList.item%281%29.unitPrice=01.65' (length=44) 
    9 => string 'invoice.itemList.item%281%29.taxName=Tax1' (length=41) 
    10 => string 'invoice.itemList.item%281%29.taxRate=7' (length=38) 

響應轉儲:

array 
     0 => string 'HTTP/1.1 200 OK 
    Date: Mon, 02 Jul 2012 17:06:05 GMT 
    Server: Apache-Coyote/1.1 
    CACHE-CONTROL: no-cache 
    X-PAYPAL-MESSAGE-PROTOCOL: NONE 
    X-PAYPAL-RESPONSE-DATA-FORMAT: NV 
    X-EBAY-SOA-REQUEST-ID: 13848a7f-b860-a486-d656-c516ffffc6d8!Invoice!10.72.109.101![] 
    X-PAYPAL-OPERATION-NAME: CreateInvoice 
    X-PAYPAL-SERVICE-NAME: {http://svcs.paypal.com/types/pt}Invoice 
    X-PAYPAL-SERVICE-VERSION: 1.0.0 
    X-PAYPAL-ERROR-RESPONSE: TRUE 
    Content-Type: text/plain;charset=UTF-8 
    Set-Cookie: Apache=10.72.109.11.13412487648'... (length=679) 
     1 => string 'responseEnvelope.ack=Failure' (length=28) 
     2 => string 'responseEnvelope.correlationId=4cab848d7c2a0' (length=44) 
     3 => string 'responseEnvelope.build=2910623' (length=30) 
     4 => string 'error(0).errorId=580001' (length=23) 
     5 => string 'error(0).domain=PLATFORM' (length=24) 
     6 => string 'error(0).subdomain=Application' (length=30) 
     7 => string 'error(0).severity=Error' (length=23) 
     8 => string 'error(0).category=Application' (length=29) 
     9 => string 'error(0).message=Invalid+request%3A+%7B0%7D' (length=43) 

什麼可能是錯誤的請求?任何指針?

回答

1

,我已經經歷了類似的錯誤,最常見的原因是:

不設置X-PAYPAL-MESSAGE-PROTOCOL(一次性的機會),設置商戶電子郵件/ ID和低交易金額。

確實注意到您的X-PAYPAL-MESSAGE-PROTOCOL設置爲FALSE(可能是一個問題)?

他們是我可以從var轉儲給你的最好的指針。

您有權訪問測試網關嗎?

+0

感謝您的回覆。發現問題並能夠立即創建發票。項目列表的索引以'1'開始,而不是'0' – siva