【问题标题】:Payment with PayPal hangs inside the notify_url page使用 PayPal 付款会挂在 notify_url 页面内
【发布时间】:2021-03-27 11:56:34
【问题描述】:

我有这个页面用贝宝支付,并在“notify_url”中收到通知。购买顺利,但未收到通知。在到达这两行之前一切都很好:$valid_txnid = check_txnid ($data ['txn_id']);$valid_price = check_price ($data ['payment_amount'], $data ['item_number']);
程序挂起的地方。 (我知道这一点是因为我已经从程序的各个点发送了电子邮件,直到我到达那里我没有收到任何东西)。 而且我不知道check_txnid ()check_price () 函数来自哪里,我在任何地方都看不到它们的定义。代码取自另一个帖子:How to get transaction details in notify_url page in paypal

index.php

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" style="padding: 0; margin: 0;">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="sb-pwrdu1932120@business.example.com" />

<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="MiArticulo" />
<input type="hidden" name="item_number" value="1" />
<input type="hidden" name="amount" value="1" />
<input type="hidden" value="19" name="invoice">

<input type="hidden" name="notify_url" value="http://infrangible-discoun.000webhostapp.com/pruebaPaypal/notifyUrl.php">
<input type="hidden" name="currency_code" value="EUR" />
<input type="hidden" name="rm" value="2" >
<input type="hidden" name="return" value="http://infrangible-discoun.000webhostapp.com/paypal4/newfile1.php">  
<input type="image" border="0" name="paypal" src="images/btn_paypal_nl.gif" onClick=""/>
</form>

notifyUrl.php

<?php 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require("conexion.php");

require 'phpmailer/Exception.php';
require 'phpmailer/PHPMailer.php';
require 'phpmailer/SMTP.php';

    // Response from Paypal
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    //$value = urlencode($value);
    $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
    $req .= "&$key=$value";
    }

    // assign posted variables to local variables
    $data['item_name']          = $_POST['item_name'];
    $data['item_number']        = $_POST['item_number'];
    $data['payment_status']     = $_POST['payment_status'];
    $data['payment_amount']     = $_POST['mc_gross'];
    $data['payment_currency']   = $_POST['mc_currency'];
    $data['txn_id']             = $_POST['txn_id'];
    $data['receiver_email']     = $_POST['receiver_email'];
    $data['payer_email']        = $_POST['payer_email'];
    $data['custom']             = $_POST['custom'];
    $data['invoice']            = $_POST['invoice'];
    $data['paypallog']          = $req;
       
    // post back to PayPal system to validate
    $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 
    if (!$fp) {
    // HTTP ERROR       
    } else {    
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        ////mail('atiftariq80@gmail.com','Step 9','Step 9');        
        $res = fgets ($fp, 1024);
        if (true || strcmp($res, "VERIFIED") == 0) {
            ////mail('atiftariq80@gmail.com','PAYMENT VALID','PAYMENT VALID');      
        // Validate payment (Check unique txnid & correct price)
        $valid_txnid = check_txnid($data['txn_id']);            
        $valid_price = check_price($data['payment_amount'], $data['item_number']);
        // PAYMENT VALIDATED & VERIFIED!
        if($valid_txnid && $valid_price){  //doesn't pass this if.             
        //----------------- INSERT RECORDS TO DATABASE-------------------------------------                              
        $name=$_POST['item_name'];
        mysqli_query($db,"insert into ventas value(0,'$name')");
        
        if ($data['invoice']=='basic') {
            $price = 39;
        } else { 
            $price = 159;
        }
        $this->user_model->update_user(
            array(
                'id' => $data['custom'],
                'user_status' => 1,
                'payment_date' => date("Y-m-d H:i:s",time()),
                'next_payment_date' => date('Y-m-d', strtotime('+32 days')),
                'user_package' => $data['invoice'],
                'package_price' => $price
            )
        );
        $data2 = array('id' => '',
        'txn_id' => $data['txn_id'],
        'amount' => $data['payment_amount'],
        'mode ' => $data['payment_status'],
        'paypal_log' => $data['paypallog'],
        'user_id' => $data['custom'],
        'created_at' => date('Y-m-d H:i:s',time())
        );
        $this->db->insert('tbl_paypal_log', $data2);   
        //----------------- INSERT RECORDS TO DATABASE-------------------------------------
        }else{    
         // Payment made but data has been changed
        // E-mail admin or alert user

        }                       
    } elseif ($res=='INVALID') {
            // PAYMENT INVALID & INVESTIGATE MANUALY! 
            // E-mail admin or alert user
            ////mail('atiftariq80@gmail.com','PAYMENT INVALID AND INVESTIGATE MANUALY','PAYMENT INVALID AND INVESTIGATE MANUALY');  
    }       
    }       
    fclose ($fp);
    } 
?>

【问题讨论】:

    标签: php paypal


    【解决方案1】:

    我不知道 check_txnid () 和 check_price () 函数来自哪里,我没有看到任何地方定义。

    这似乎是你的问题。不要调用不存在的函数。

    如果您想检查交易 ID 和价格对于您所提供的产品是唯一且有效的,请创建实际执行此操作的实际函数。

    如果您在交易过程中向 PayPal 提供了这样一个唯一编号,例如,您可以使用“自定义”或“发票”来匹配数据库中的现有订单记录并验证价格是否对应。

    【讨论】:

    • 但问题是我的数据库中仍然没有任何内容。我正在考虑将它们添加到数据库挂起的那个点。
    • 验证的重点是在向数据库添加内容之前进行验证。而且您正在调用不存在的验证函数,这将导致您的代码完全失败。所以你需要解决这个明显的问题,即使这意味着现在不进行验证,并继续你真正想要完成的任何事情。
    • 好的,我必须检查数据库中是否没有带有“txn_id”的项目。但是......以及价格和数量。我是否还必须检查数据库中是否已经没有?
    • 你必须做你想做的事。这个地方是您自己的验证和业务逻辑所在,使用 IPN 中的信息。
    • 在代码的前面部分,您正在检查从回发到 PayPal 的“已验证”响应,这看起来很不对劲。看起来 if 语句被硬编码为始终为“真”,即从 PayPal 查找此验证的检查。这显然很糟糕。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2012-12-31
    • 2013-11-30
    • 2011-04-21
    • 2014-03-23
    • 2014-07-15
    相关资源
    最近更新 更多