Paypal DoCapture批处理循环

时间:2013-04-25 14:32:28

标签: loops paypal

我正在尝试从paypal实现doCapture API的批处理。我有下面的代码,它只处理数据库的第一条记录...帮助!! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

<?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));
//}
}}
//}

?>

1 个答案:

答案 0 :(得分:0)

您只从数据库中取出一行,因为您的$row2 = mysql_fetch_array($results);行不在for循环中。从本质上讲,你试图一遍又一遍地捕获相同的支付,我愿意打赌只有第一个支付成功。将fetch语句移到for循环内部。