gpt4 book ai didi

loops - Paypal DoCapture 批处理循环

转载 作者:太空宇宙 更新时间:2023-11-03 16:10:54 27 4
gpt4 key购买 nike

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

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

?>

最佳答案

您只从数据库中提取一行,因为您的 $row2 = mysql_fetch_array($results); 行在您的 for 循环之外。从本质上讲,您正试图一次又一次地获取相同的付款,我敢打赌只有第一个成功。将 fetch 语句移动到 for 循环内。

关于loops - Paypal DoCapture 批处理循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16217570/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com