程序问答   发布时间:2022-05-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Paypal IPN,将交易插入数据库大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Paypal IPN,将交易插入数据库?

开发过程中遇到Paypal IPN,将交易插入数据库的问题如何解决?下面主要结合日常开发的经验,给出你关于Paypal IPN,将交易插入数据库的解决方法建议,希望对你解决Paypal IPN,将交易插入数据库有所启发或帮助;

所以最近iv从codeHack购买了Paypal支付系统,无论iv尝试过什么,我都无法找出问题所在。

问题是它在一个 paypal 上有效,但在另一个 paypal 上不起作用。

两个 paypal 都在发送 IPN 消息。 在这两种情况下,付款都有效,一种是存储到数据库中,另一种是不存在的。 iv 注意到的唯一区别是,paypal 不起作用,付款仍处于暂停状态,但在 IPN 消息中,它被标记为已完成,因此应该不是问题。

配置:

<?php
/* DATABASE SETTinGS */
// Database hostname,don't change this unless your hostname is different
define('db_host','localhost');
// Database username
define('db_user','-b');
// Database password
define('db_pass','-');
// Database name
define('db_name','-');

/* GENERAL SETTinGS */
// This will change the title on the website
define('site_name','Super Balanced');
// Currency code,default is USD,you can vIEw the List here: http://cactus.io/resources/toolBox/HTML-currency-symbol-codes
define('currency_code','&euro;');
// Account required for checkout?
define('account_required',truE);
// The from email that will appear on the customer's order details email
define('mail_from','my@paypal.net');
// Send mail to the customers,etc?
define('mail_enabled',truE);

/* PAYPAL SETTinGS */
// Accept payments with PayPal?
define('paypal_enabled',truE);
// Your business email account,this is where you'll receive the money
define('paypal_email','my@paypal.net');
// If the test mode is set to true it will use the PayPal sandBox website,which is used for tesTing purposes.
// Read more about PayPal sandBox here: https://developer.paypal.com/developer/accounts/
// Set this to false when you're ready to start accepTing payments on your business account
define('paypal_testmode',falsE);
// Currency to use with PayPal,default is USD
define('paypal_currency','EUR');
// PayPal IPN url,this should point to the IPN file located in the "ipn" directory
define('paypal_ipn_url','https://www.paypal.test/ini.php');
// PayPal cancel URl,the page the customer returns to when they cancel the payment
define('paypal_cancel_url','cancel');
// PayPal return URL,the page the customer returns to after the payment has been made:
define('paypal_return_url','return');
?>

<?php
include '../config.php';
include '../functions.php';
// Get all input variables and convert them all to URL String variables
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&',$raw_post_data);
$myPost = [];
foreach ($raw_post_array as $keyval) {
    $keyval = explode('=',$keyval);
    if (count($keyval) == 2) $myPost[$keyval[0]] = urldecode($keyval[1]);
}
$req = 'cmd=_notify-valIDate';
$get_magic_quotes_exists = function_exists('get_magic_quotes_gpc') ? true : false;
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";
}
// Below will verify the transaction,it will make sure the input data is correct,we wouldn't want anybody trying to cheat the system..
$ch = curl_init(paypal_testmode ? 'https://www.sandBox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch,CURLOPT_http_VERSION,CURL_http_VERSION_1_1);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,CURLOPT_POSTFIELDS,$req);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,CURLOPT_SSL_VERIFYHOST,2);
curl_setopt($ch,CURLOPT_FORBID_REUSE,CURLOPT_httpheader,['Connection: Close']);
$res = curl_exec($ch);
curl_close($ch);
if (strcmp($res,'VERIFIED') == 0) {
    // transaction is verifIEd and successful...
    $pdo = pdo_connect_MysqL();
    $products_in_cart = [];
    $sub@R_895_10586@l = 0.00;
    $shipPing@R_895_10586@l = 0.00;
    // Iterate the cart items and insert the transaction items into the MysqL database
    for ($i = 1; $i < ($_POST['num_cart_items']+1); $i++) {
        // update product quantity in the products table
        $stmt = $pdo->prepare('updatE products SET quantity = quantity - ? WHERE quantity > 0 AND ID = ?');
        $stmt->execute([ $_POST['quantity' . $i],$_POST['item_number' . $i] ]);
        // Product related variables
        $option = isset($_POST['os0_' . $i]) ? $_POST['os0_' . $i] : '';
        if (empty($option)) {
            $option = isset($_POST['option_SELEction1_' . $i]) ? $_POST['option_SELEction1_' . $i] : '';
        }
        $item_price = floatval($_POST['mc_gross_' . $i]) / intval($_POST['quantity' . $i]);
        // Insert product into the "transactions_items" table
        $stmt = $pdo->prepare('INSERT INTO transactions_items (txn_ID,item_ID,item_price,item_quantity,item_options,item_shipPing_pricE) VALUES (?,?,?)');
        $stmt->execute([ $_POST['txn_ID'],$_POST['item_number' . $i],$item_price,$_POST['quantity' . $i],$option,$_POST['mc_shipPing' . $i] ]);
        // Add product to array
        $products_in_cart[] = [
            'ID' => $_POST['item_number' . $i],'quantity' => $_POST['quantity' . $i],'options' => $option,'Meta' => [
                'name' => $_POST['item_name' . $i],'price' => $item_price
            ]
        ];
        // Add product price to the sub@R_895_10586@l variable
        $sub@R_895_10586@l += $item_price;
        // Add product shipPing to the @R_895_10586@l shipPing variable
        $shipPing@R_895_10586@l += floatval($_POST['mc_shipPing' . $i]);
    }
    // Insert the transaction into our transactions table,as the payment status changes the query will execute again and update it,make sure the "txn_ID" column is unique
    $stmt = $pdo->prepare('INSERT INTO transactions (txn_ID,payment_amount,payment_status,created,payer_email,first_name,last_name,address_street,address_city,address_state,address_zip,address_country,account_ID,payment_method) VALUES (?,?) ON DUPliCATE KEY updatE payment_status = VALUES(payment_status)');
    $stmt->execute([
        $_POST['txn_ID'],$sub@R_895_10586@l+$shipPing@R_895_10586@l,$_POST['payment_status'],date('Y-m-d H:i:s'),$_POST['payer_email'],$_POST['first_name'],$_POST['last_name'],$_POST['address_street'],$_POST['address_city'],$_POST['address_state'],$_POST['address_zip'],$_POST['address_country'],$_POST['custom'],'paypal'
    ]);
    $order_ID = $pdo->lasTinsertID();
    // Send order details to the customer's email address
    send_order_details_email(
        $_POST['payer_email'],$products_in_cart,$order_ID
    );
}
?>
由于隐私(IPN 路径、电子邮件、数据库等),某些 URL 已更改 任何想法都会有所帮助。 谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Paypal IPN,将交易插入数据库全部内容,希望文章能够帮你解决Paypal IPN,将交易插入数据库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: