gpt4 book ai didi

php - PayPal IPN,很多注册,一次付款,都按错误的顺序

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:06 28 4
gpt4 key购买 nike

我最近在 CodeIgniter2 中实现了一个 PayPal IPN,使用 PayPal Lib .我正在使用该系统进行订阅。

我的数据库中有一张表,记录了数据库中所有的IPN请求。

出于某种原因,每次注册后,IPN 请求都无法正常通过。我倾向于获得一个 subscr_payment 和多个 subscr_signups,它们都具有相同的 subscr_id。由于显而易见的原因,它在系统内造成了数不清的麻烦。除此之外,IPN 请求的顺序不正确,有时我会在 subscr_signup 之前收到 subscr_payment - 这使得无法跟踪,因为注册中没有 subscr_id 以将其链接到用户。

我有谷歌,但在这方面找不到太多,我似乎有点反常。我想知道这是否与我正在使用的 PayPal Lib 有关,但我真的不想在 CodeIgniter 之外进行,因为我正在进行大量处理。下面是完整的 IPN 脚本。


class Paypal extends CI_Controller {
function _<em>construct()
{
parent::</em>_construct();
$this->load->library('paypal_lib');
}



<pre><code>function ipn()
{

$this->output->enable_profiler(TRUE);

$this->load->model('payments_model');
$this->load->model('paypal_model');
$this->load->model('users_model');

ob_start();

if ($this->paypal_lib->validate_ipn())
{


$paypal_id = $this->paypal_model->add_paypal_ipn($this->paypal_lib->ipn_data);
// Split the 'custom' field up, containing ID of temp user, ID of package and coupon
$custom = explode(';', $this->paypal_lib->ipn_data['custom']);

###
# subscription sign up
###
if($this->paypal_lib->ipn_data['txn_type'] == 'subscr_signup') {
// Activate user/move from temp > live
$this->users_model->move_temp($custom[0], $this->paypal_lib->ipn_data['subscr_id']);
} # end subscr_signup


###
# subscription payment
###
if($this->paypal_lib->ipn_data['txn_type'] == 'subscr_payment') {
// Grab the coupon info, if we have one
$discount = 1;
if(!empty($custom[2])){
$this->load->model('coupons_model');
$couponinfo = $this->coupons_model->get_coupon($custom[2]);
$discount = $couponinfo->discount;
}
// Grab the package info
$package = $this->packages_model->get_package($custom[1]);
$price = $package->monthly * $discount; // Calculate discount, 0.8 = 20% off

// Does the price calculated match the gross price? If not something fishy is going on, block it
if($price != $this->paypal_lib->ipn_data['mc_gross']){
mail(CONTACT_EMAIL, SITE_NAME.' failed payment attempt, possible hack', 'Price paid doesnt match price computed... paid: '.$this->paypal_lib->ipn_data['mc_gross'].' - price worked out: '.$price."\n\n".print_r($this->paypal_lib->ipn_data, true));
exit;
}

// Grab the user's details based on the subscr_id
$user = $this->users_model->get_user_by_subscr_id($this->paypal_lib->ipn_data['subscr_id']);

// Add payment to the payments table
$data = array(
'user_id' => $user->user_id,
'subscr_id' => $user->subscr_id,
'txn_id' => $this->paypal_lib->ipn_data['txn_id'],
'amount' => $this->paypal_lib->ipn_data['mc_gross'],
'package_id' => $custom[1],
'coupon' => (empty($custom[2]) ? '' : $custom[2])
);
$this->payments_model->add_payment($data);

// Set (forced) user as active, and update their current active package
$data1 = array(
'package_id' => $custom[1],
'active' => 1
);
$this->users_model->update_user($data1, $user->user_id);
} # end subscr_payment


###
# subscription failed/cancelled
###
if($this->paypal_lib->ipn_data['txn_type'] == 'subscr_cancel' || $this->paypal_lib->ipn_data['txn_type'] == 'subscr_failed') {
// Grab user
$user = $this->users_model->get_user_by_subscr_id($this->paypal_lib->ipn_data['subscr_id']);

// Make user inactive
$data = array('active' => 0);
$this->users_model->update_user($data, $user->user_id);
} # end subscr_cancel|subscr_failed





###
# subscription modified/payment changed
###
if($this->paypal_lib->ipn_data['txn_type'] == 'subscr_modify') {
// Grab the coupon info, if we have one
$discount = 1;
if(!empty($custom[2])){
$this->load->model('coupons_model');
$couponinfo = $this->coupons_model->get_coupon($custom[2]);
$discount = $couponinfo->discount;
}
// Grab the package info
$package = $this->packages_model->get_package($custom[1]);
$price = $package->monthly * $discount; // Calculate discount, 0.8 = 20% off

// Does the price calculated match the gross price? If not something fishy is going on, block it
if($price != $this->paypal_lib->ipn_data['mc_gross']){
mail(CONTACT_EMAIL, SITE_NAME.' failed payment attempt, possible hack', 'Price paid doesnt match price computed... paid: '.$this->paypal_lib->ipn_data['mc_gross'].' - price worked out: '.$price."\n\n".print_r($this->paypal_lib->ipn_data, true));
exit;
}

// Grab the user's details based on the subscr_id
$user = $this->users_model->get_user_by_subscr_id($this->paypal_lib->ipn_data['subscr_id']);

// Add payment to the payments table
$data = array(
'user_id' => $user->user_id,
'subscr_id' => $user->subscr_id,
'txn_id' => $this->paypal_lib->ipn_data['txn_id'],
'amount' => $this->paypal_lib->ipn_data['mc_gross'],
'package_id' => $custom[1],
'coupon' => (empty($custom[2]) ? '' : $custom[2])
);
$this->payments_model->add_payment($data);

// Set (forced) user as active, and update their current active package
$data1 = array(
'package_id' => $custom[1],
'active' => 1
);
$this->users_model->update_user($data1, $user->user_id);
} # end subscr_modify

}
}
</code></pre>

以下是针对每笔交易 (CSV) 对我的 IPN 进行调用的示例。

paypal_id,txn_id,subscr_id,txn_type,created
1,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:19:43
2,9XM95194MM564230E,I-FMUK0B5KJWKA,subscr_payment,2011-02-03 16:19:45
3,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:19:57
4,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:20:19
6,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:21:03
7,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:22:25
8,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:25:08
10,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:30:33
12,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 16:41:16
14,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 17:02:42
16,NULL,I-FMUK0B5KJWKA,subscr_signup,2011-02-03 17:45:26

最佳答案

考虑一下 - Paypal 是插入亵渎。现在重新审视这个问题。

这很可能不是您的错,也不是 CodeIgniter 或图书馆的错。 PayPal 非常不擅长以统一和及时的方式提供数据,它也很慢并且不能很好地将数据链接在一起。

我对您的建议是在进行回叫时将所有内容保存到 IPN 表中,甚至在进行 IPN 调用时给自己发送电子邮件。然后努力弄清楚 PayPal 实际发送给您的是什么,您想要什么,然后扔掉其余的。

我认为即使交易与您的网站无关,也会进行 IPN 调用。因此,如果您的祖母通过 PayPal 向您发送圣诞钱,它会出现在 IPN 回调中。

希望对您有所帮助。

关于php - PayPal IPN,很多注册,一次付款,都按错误的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4888436/

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