Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从paypal IPN交易中提取产品id或名称_Php_Mysql_Paypal - Fatal编程技术网

Php 如何从paypal IPN交易中提取产品id或名称

Php 如何从paypal IPN交易中提取产品id或名称,php,mysql,paypal,Php,Mysql,Paypal,我目前正在开发一个网上购物商店。对于这个网站,我没有将任何购物车历史记录存储到我的数据库中,因此我没有关于客户订单的任何详细信息。我计划在客户付款后立即获得订单详细信息 我现在的问题是,我的产品以数组形式发送到paypal,每个交易都保存到我的数据库表字段中,如下所示: 20-1,21-1 20和21是产品id,它旁边是数量 我需要知道我是否可以只从paypal IPN检索订单,而不创建特定的数据库来存储来自客户的订单 拜托,我真的需要你的帮助 $product_id_string = $_PO

我目前正在开发一个网上购物商店。对于这个网站,我没有将任何购物车历史记录存储到我的数据库中,因此我没有关于客户订单的任何详细信息。我计划在客户付款后立即获得订单详细信息

我现在的问题是,我的产品以数组形式发送到paypal,每个交易都保存到我的数据库表字段中,如下所示:

20-1,21-1

20和21是产品id,它旁边是数量

我需要知道我是否可以只从paypal IPN检索订单,而不创建特定的数据库来存储来自客户的订单

拜托,我真的需要你的帮助

$product_id_string = $_POST['custom'];
$product_id_string = rtrim($product_id_string, ","); // remove last comma
// Explode the string, make it an array, then query all the prices out, add them up, and make sure they match the payment_gross amount
$id_str_array = explode(",", $product_id_string); // Uses Comma(,) as delimiter(break point)
$fullAmount = 0;
foreach ($id_str_array as $key => $value) {

    $id_quantity_pair = explode("-", $value); // Uses Hyphen(-) as delimiter to separate product ID from its quantity
    $product_id = $id_quantity_pair[0]; // Get the product ID
    $product_quantity = $id_quantity_pair[1]; // Get the quantity
    $query = "SELECT price FROM products WHERE id='$product_id' LIMIT 1";
    $result = mysqli_query($conn, $query);
    while($row = mysqli_fetch_array($result)){
        $product_price = $row["price"];
    }
    $product_price = $product_price * $product_quantity;
    $fullAmount = $fullAmount + $product_price;
}
$fullAmount = number_format($fullAmount, 2);
$grossAmount = $_POST['mc_gross']; 
if ($fullAmount != $grossAmount) {
        $message = "Possible Price Jack: " . $_POST['mc_gross'] . " != $fullAmount \n\n\n$req";
        mail("email@gmail.com", "Price Jack or Bad Programming", $message, "From: email@gmail.com" );
        exit(); // exit script
} 
// END ALL SECURITY CHECKS NOW IN THE DATABASE IT GOES ------------------------------------
////////////////////////////////////////////////////
// Assign local variables from the POST PayPal variables
$custom = $_POST['custom'];
$payer_email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$payment_date = $_POST['payment_date'];
$mc_gross = $_POST['mc_gross'];
$payment_currency = $_POST['payment_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payment_type = $_POST['payment_type'];
$payment_status = $_POST['payment_status'];
$txn_type = $_POST['txn_type'];
$payer_status = $_POST['payer_status'];
$address_street = $_POST['address_street'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_zip = $_POST['address_zip'];
$address_country = $_POST['address_country'];
$address_status = $_POST['address_status'];
$notify_version = $_POST['notify_version'];
$verify_sign = $_POST['verify_sign'];
$payer_id = $_POST['payer_id'];
$mc_currency = $_POST['mc_currency'];
$mc_fee = $_POST['mc_fee'];

// Place the transaction into the database
$sql = mysqli_query($conn, "INSERT INTO transactions (id, product_id_array, payer_email, first_name, last_name, payment_date, mc_gross, payment_currency, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee) 
   VALUES('$txn_id','$custom','$payer_email','$first_name','$last_name','$payment_date','$mc_gross','$payment_currency','$receiver_email','$payment_type','$payment_status','$txn_type','$payer_status','$address_street','$address_city','$address_state','$address_zip','$address_country','$address_status','$notify_version','$verify_sign','$payer_id','$mc_currency','$mc_fee')") or die ("unable to execute the query");

mysqli_close();
// Mail yourself the details
mail("email@gmail.com", "New Order Entered: ".$txn_id, $req, "From: email@gmail.com");
?>

也许我不明白,但您可以使用
item\u namex
字段在请求中添加完整描述,或者可以在付款后使用用于检索价格以进行检查的查询来检索描述。除此之外,考虑到交易是一个非常重要的事件,在交易过程中,保存所有与交易相关的参数的所有值都是明智的:如果有人购买,你会改变物品的价格吗?FullAmount和GrossAmount不匹配,但付款是正确的,最后检查FullAmount和GrossAmount是否足够需要清楚地检查响应是否无效,这不是沙箱付款(test_ipn!=1),收件人电子邮件是您的paypal电子邮件地址,txn id尚未处理,上面的代码只是我完整代码的一个片段。响应有效,且价格与全额和总额相符。我现在的问题是如何从数组字段中提取产品详细信息可能我还不了解,但您可以使用
item\u namex
字段在请求中添加完整描述,或者可以在付款后使用查询来检索价格以供检查。除此之外,考虑到交易是一个非常重要的事件,在交易过程中,保存所有与交易相关的参数的所有值都是明智的:如果有人购买,你会改变物品的价格吗?FullAmount和GrossAmount不匹配,但付款是正确的,最后检查FullAmount和GrossAmount是否足够需要清楚地检查响应是否无效,这不是沙箱付款(test_ipn!=1),收件人电子邮件是您的paypal电子邮件地址,txn id尚未处理,上面的代码只是我完整代码的一个片段。响应有效,且价格与全额和总额相符。我现在的问题是如何从数组字段中提取产品细节