【问题标题】:Payment gateway doesn't show sucess/ fail支付网关不显示成功/失败
【发布时间】:2017-08-16 02:49:50
【问题描述】:

我想制作自定义付款方式选项。客户选择支付的金额。这个过程很简单客户填写表格,无论表格中的金额是多少,都会被重定向到付款页面。之后,它返回到该站点。 我的代码在支付网关页面之前运行完美,之后页面没有获取/运行成功或失败功能。

这是我的表单的前端。

function make_my_payment() {
    if (isset($_POST['formset']) and!empty($_POST['formset'])) {
        require_once dirname(__FILE__).
        '/payu.php';
        date_default_timezone_set('Asia/Kolkata');
        //update the live credentials once done testing.
        /* Payment success logic goes here. */
        function payment_success() {
            //echo "<pre>";
            //print_r($_POST);die;
            global $wpdb;
            $wpdb - > insert('wp_payment_details', array('payment_id' => $_POST['mihpayid'], 'fname' => $_POST['firstname'], 'lname' => $_POST['lastname'], 'email' => $_POST['email'], 'phone' => $_POST['phone'], 'branch' => $_POST['udf1'], 'amount' => $_POST['udf4'], 'total_amount' => $_POST['amount'], 'additional_charge' => $_POST['udf2'], 'notification' => $_POST['udf3'], 'payment_datetime' => time(), 'notification_datetime' => $_POST['udf5'], 'status' => 1, ));
            //send text message
            $text_message = "Thank%20you%20for%20the%20payment%20of%20".$_POST['amount'].
            "%20at%20Nikita%20Jewellers.";
            $ch1 = curl_init();
            curl_setopt($ch1, CURLOPT_URL, "http://makemysms.in/api/sendsms.php?username=NIKITAJWL&password=NIKITA123&sender=NIKITA&mobile=".$_POST['phone'].
                "&type=1&message=".$text_message);
            curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
            $output = curl_exec($ch1);
            curl_close($ch1);
            echo '<h4>You have successfully paid amount '.$_POST['amount'].
            '</h4>';
        }

        function payment_failure() {
            /* Payment failure logic goes here. */
            echo "Payment Failure";
        }
        /* Payments made easy. */
        pay_page(array('key' => '4XKLg4', 'txnid' => uniqid('nikita_'), 'amount' => $_POST['total_amount'], 'firstname' => $_POST['fname'], 'lastname' => $_POST['lname'], 'email' => $_POST['email'], 'phone' => $_POST['phone'], 'udf1' => $_POST['orderScheme'], 'udf2' => $_POST['additional_charge'], 'udf3' => $_POST['send_notification'], 'udf4' => $_POST['amount'], 'udf5' => $_POST['notification_date'], 'productinfo' => 'Nikita Make payment', 'surl' => 'payment_success', 'furl' => 'payment_failure'), 'jeYETVtZ');
        /* And we are done. */
    }
    if (empty($_POST['formset'])) {
        $html. = "<form id='payment_form' method='post'> < table border = '0'
        class = 'make_payment' > <tr>
                        <td style='padding-top: 10px'>
                            <b>Full Name <span style='color:red;'>*</span></b>
                            <input type='text' required name='fname' id='fname' placeholder='First' />
                            <input type='text' required name='lname' id='lname' placeholder='Last' />
                        </td>
                    </tr> < tr > <td>
                            <b>Email <span style='color:red;'>*</span></b>
                            <input type='email' required name='email' id='email' />
                        </td> < /tr> < tr > <td>
                            <b>Mobile <span style='color:red;'>*</span></b>
                            <input type='text' minlength='10' maxlength='10' required name='phone' id='phone' />
                        </td> < /tr> < tr > <td>
                            <b>Scheme / Order No. <span style='color:red;'>*</span><i>(Enter 'none' if you don't have scheme/order no. OR 'new member' if you are starting a new scheme.)</i></b>
                            <input type='text' required name='orderScheme' id='orderScheme' />
                        </td> < /tr> < tr > <td>
                            <b>Mode of Payment <span style='color:red;'>*</span></b>
                            <input  type='radio' required name='additional_charge' id='additional_charge' value = '0'/>Debit 
                            <i>(No charge)</i> <br/>
                            <input  type='radio' required name='additional_charge' id='additional_charge' value = '0'/>Credit + NetBanking <i>(No charge)</i> <br/>
                            <input  type='radio' required name='additional_charge' id='additional_charge' value = '1.90'/>Amex + International Card <i>(1.90% Additional charge)</i>
                        </td> < /tr> < tr > <td>
                            <b>Amount <span style='color:red;'>*</span></b>
                            <input  type='number' required name='amount' id='amount' />
                        </td> < /tr> < tr > <td>
                            <b>Total Amount</b>
                            <input type='text' readonly name='total_amount' id='total_amount' /> <br/>
                            <label>Amount + Service Tax + Transaction Fee</label>
                        </td> < /tr> < tr > <td>
                            <b>Enable SMS Notification</b>
                            <input type='checkbox' name='send_notification' id='send_notification' />
                            <label>For recurring payments only : A reminder sms will be sent on your mobile number to make your next payment. Leave unchecked if making one time payment.</label>
                        </td> < /tr> < tr id = 'notification_row'
        style = 'display:none' > <td>
                            <b>Reminder Date</b>
                            <input type='text' name='notification_date' id='notification_date' />
                        </td> < /tr> < tr > <td style='text-align:center;'>
                            <input type='submit' name='pay_btn' id='pay_btn' value='Pay' style='margin: 0' />
                        </td> < /tr> < input type = 'hidden'
        name = 'formset'
        value = '1' > < /table> < /form>
        ";
        return $html;
    }

支付网关的 Payu.php 文件已针对此表单进行了修改,因此发布了我修改的确切代码。

public static
function show_page($result) {
    if ($result['status'] === Misc::SUCCESS) {
        //                      header( 'Location:' . $result['data'] );
        //              else
        //                      throw new Exception( $result['data'] );
        //
        //                        echo ($result ['data']);
        $nik = $result['data'];
        echo '<META HTTP-EQUIV="refresh" content="0;URL='.$nik.
        '">';
        echo "<script type='text/javascript'>document.location.href='{$nik}';</script>";
        $result['data'] = $nik;
    } else throw new Exception($result['data']);
    echo($result['data']);
}
public static
function show_reponse($result) {
    if ($result['status'] === Misc::SUCCESS) {
        $result['data']();
        //                     echo "<script type='text/javascript'>alert('$result['data']());</script>";
    } else {
        return $result['data'];
        //                    $nik=$result['data'];
        //                   echo "<script type='text/javascript'>alert('$nik');</script>";
    }
}
}

在支付 Payu 文件中,我必须删除 PHP 重定向,因为它给出了已经发送的错误标头所以我不得不使用 javascript 进行重定向。那么我现在应该怎么做才能让它获得完美的成功/失败信息。

【问题讨论】:

    标签: javascript php wordpress


    【解决方案1】:

    标头在输出开始时发送,因此请检查任何过早的输出(如 PHP 开头标记之前的空格等)。重新启用 PHP 重定向并让它做它的事情。关键是在那之前不要输出任何东西。我们需要查看更多代码才能知道该页面中是否有我们可以提供帮助的内容。

    这是 StackOverflow 中关于查找已发送标头问题原因的参考:Link

    【讨论】:

    • 好的,我管理了标头已发送的问题。仍然没有对成功和失败进行排序。
    • 那么当你有成功或失败时,$result 变量的内容是什么?你能为我们做一个 var_dump 吗?
    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 2013-11-02
    • 2017-08-04
    • 2015-06-06
    • 2014-04-26
    • 2011-05-05
    • 2021-03-31
    相关资源
    最近更新 更多