2013-04-25 24 views
1

我想從貝寶實施doCapture API的批處理過程。我有下面的代碼,它只處理數據庫的第一個記錄...幫助! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx貝寶DoCapture批處理循環

<?php 
include("xxxxx.php");<---- this is just the database connection 

$query2="SELECT * 
    FROM x where payment_status = 'Pending'"; 
// WHERE custom IN (
    // SELECT custom 
    // FROM x 
    // GROUP BY custom 
    // HAVING count(custom) > 1 
    //) 
    //ORDER BY custom"; 
$results=mysql_query($query2); 
$row2 = mysql_fetch_array($results); 
$row_count=mysql_num_rows($results); 
echo $row_count; 
//$auth=$row2['auth_id']; 
//while($row2 =mysql_fetch_array($results)){ 

$arrSize=sizeof($row_count); 

for ($number = 0; $number < $arrSize; $number++) { 

//for($i=0; $i<$row_count; $i++){ 
echo $row2['auth_id']; // prints hello 


//echo $row2['auth_id']; 
/** DoCapture NVP example; last modified 08MAY23. 
* 
* Capture a payment. 
*/ 

$environment = 'sandbox'; // or 'beta-sandbox' or 'live' 

/** 
* Send HTTP POST Request 
* 
* @param string The API method name 
* @param string The POST Message fields in &name=value pair format 
* @return array Parsed HTTP Response body 
*/ 
function PPHttpPost($methodName_, $nvpStr_) { 
//for($i=0; $i<$row_count; $i++){ 
    global $environment; 

    // Set up your API credentials, PayPal end point, and API version. 
    $API_UserName = urlencode(''); 
    $API_Password = urlencode(''); 
    $API_Signature = urlencode('.'); 
    $API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp"; 
    if("sandbox" === $environment || "beta-sandbox" === $environment) { 
     $API_Endpoint = "https://api-3t.$environment.paypal.com/nvp"; 
    } 
    $version = urlencode('51.0'); 

    // Set the curl parameters. 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $API_Endpoint); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 

    // Turn off the server and peer verification (TrustManager Concept). 
    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, 1); 

    // Set the API operation, version, and API signature in the request. 
    $nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_"; 

    // Set the request as a POST FIELD for curl. 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq); 

    // Get response from the server. 
    $httpResponse = curl_exec($ch); 

    if(!$httpResponse) { 
     exit("$methodName_ failed: ".curl_error($ch).'('.curl_errno($ch).')'); 
    } 

    // Extract the response details. 
    $httpResponseAr = explode("&", $httpResponse); 

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

    if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) { 
     exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint."); 
    } 

    return $httpParsedResponseAr; 
} 

// Set request-specific fields. 
$authorizationID = urlencode($row2['auth_id']); 

$amount = urlencode('1.99'); 
$currency = urlencode('USD');       // or other currency ('GBP', 'EUR', 'JPY', 'CAD', 'AUD') 
$completeCodeType = urlencode('Complete');    // or 'NotComplete' 
$invoiceID = urlencode('example_invoice_id'); 
$note = urlencode('example_note'); 

// Add request-specific fields to the request string. 
$nvpStr="&AUTHORIZATIONID=$authorizationID&AMT=$amount&COMPLETETYPE=$completeCodeType&CURRENCYCODE=$currency&NOTE=$note"; 



// Execute the API operation; see the PPHttpPost function above. 
$httpParsedResponseAr = PPHttpPost('DoCapture', $nvpStr); 

if("SUCCESS" == strtoupper($httpParsedResponseAr["ACK"]) || "SUCCESSWITHWARNING" == strtoupper($httpParsedResponseAr["ACK"])) { 
    exit('Capture Completed Successfully: '.print_r($httpParsedResponseAr, true)); 
} else { 
    exit('DoCapture failed: ' . print_r($httpParsedResponseAr, true)); 
//} 
}} 
//} 

?> 
+0

讓我們拋出一些調試!開始回顯您收到的行數,print_r一些數組以找出問題的具體位置。逐步解決腳本問題。如果您有像NetBeans或Zend這樣的IDE,請使用斷點並查看正在處理的數據。 – Sugitime 2013-04-25 22:33:22

回答

0

你只取一排從數據庫中,因爲你$row2 = mysql_fetch_array($results);行是你的for循環之外。從本質上講,你試圖一次又一次地獲得同樣的支付,而且我敢打賭,只有第一個成功。將讀取語句移到for循環中。