gpt4 book ai didi

php - Paypal IPN : Reading multiple item_name and quantities and saving to a database

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

下面是我的 IPN 代码。我的问题是我无法在表 payments_paypal 中添加多个项目名称或数量。实际上 IPN 并没有监听 payer_id,quantity,item_name(multiple items)。

我们如何在这里 $_POST item_name1 或 item_name2 等,以便在验证时我可以在其他页面中获取它,这将是成功页面。虽然我已经通过其他方法实现了这一点,但这不是正确的方法。所以我想知道为什么这些变量不是来自 ipn 的字符串形式,只有这些变量以字符串 txn、smt、st、currency 的形式出现,其余的都丢失了。如果我们必须在此处使用循环,我们如何发送值以从此处 ipn.php 插入循环。

如有任何帮助,我们将不胜感激。

    $raw_post_data = file_get_contents('php://input'); 
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);

}

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}

/*
* Post IPN data back to PayPal to validate the IPN data is genuine
* Without this step anyone can fake IPN data
*/
$paypalURL = PAYPAL_URL;
$ch = curl_init($paypalURL);
if ($ch == FALSE) {
return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);

// Set TCP timeout to 30 seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: company-name'));
$res = curl_exec($ch);

/*
* Inspect IPN validation result and act accordingly
* Split response headers and payload, a better way for strcmp
*/
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp($res, "VERIFIED") == 0 || strcasecmp($res, "VERIFIED") == 0) {

// Retrieve transaction info from PayPal
$item_number = $_POST['item_number'];
$txn_id = $_POST['txn_id'];
$payment_gross = $_POST['mc_gross'];
$currency_code = $_POST['mc_currency'];
$payment_status = $_POST['payment_status'];
$quantity = $_POST['quantity'];

// Check if transaction data exists with the same TXN ID
$prevPayment = $db->query("SELECT payment_id FROM payments WHERE txn_id = '".$txn_id."'");
if($prevPayment->num_rows > 0){
exit();
}else{
// Insert transaction data into the database
$insert = $db->query("INSERT INTO payments_paypal(item_number,txn_id,payment_gross,currency_code,payment_status) VALUES('".$item_number."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."')");
}

}

最佳答案

看起来您在 //Retrieve transaction info from PayPal 部分中使用的代码非常简单,并不是为了查找多个项目而编写的,例如编号变量,如 item_name1item_name2

您应该记录您收到但未正确处理的 IPN 的文本,或者从您的 PayPal 帐户历史记录中获取它们的文本:https://www.paypal.com/us/smarthelp/article/where-can-i-access-my-ipn-history-faq3692

另外,查看多个项目的变量名文档:https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/

然后,您可以修改代码以读取和处理这些多编号变量,并将它们存储在您想要的任何数据库架构中,这可能需要额外的列或其他内容。

关于php - Paypal IPN : Reading multiple item_name and quantities and saving to a database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59692984/

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