麻烦存储php中的参数数据

时间:2017-01-22 08:46:55

标签: php storage

我对php和支付集成很新。 但我已经成功整合了支付系统,但我面临的问题是如何将这些确认值存储在数据库中。 这是我的response.php代码,其中来自网关的确认响应被发送回响应页面。使用代码我能够获得确认状态输出,问题是如何将其存储在db中。 [这是输出] [1]

    <?php
    include 'header.php';
    include 'dbconnect.php';
    header("Pragma: no-cache");
    header("Cache-Control: no-cache");
    header("Expires: 0");
    ?>
    <html>
    <head></head>
    <body>
    <?php
    // following files need to be included
    require_once("./paytm/PaytmKit/lib/config_paytm.php");
    require_once("./paytm/PaytmKit/lib/encdec_paytm.php");

    $paytmChecksum = "";
    $paramList = array();
    $isValidChecksum = "FALSE";

    $paramList = $_POST;
    $paytmChecksum = isset($_POST["CHECKSUMHASH"]) ? $_POST["CHECKSUMHASH"] : ""; //Sent by Paytm pg

    //Verify all parameters received from Paytm pg to your application. Like MID received from paytm pg is same as your application’s MID, TXN_AMOUNT and ORDER_ID are same as what was sent by you to Paytm PG for initiating transaction etc.
    $isValidChecksum = verifychecksum_e($paramList, PAYTM_MERCHANT_KEY, $paytmChecksum); //will return TRUE or FALSE string.


    if($isValidChecksum == "TRUE") {
        echo "<b>Checksum matched and following are the transaction details:</b>" . "<br/>";
        if ($_POST["STATUS"] == "TXN_SUCCESS") {
            echo "<b>Transaction status is success</b>" . "<br/>";


            //Process your transaction here as success transaction.
            //Verify amount & order id received from Payment gateway with your application's order id and amount.
        }
        else {
            echo "<b>Transaction status is failure</b>" . "<br/>";
        }

        if (isset($_POST) && count($_POST)>0 )
        { 
          //here iam trying to store it but it is not working as shows undefined functions
            foreach($_POST as $paramName => $paramValue) {
                    echo "<br/>" . $paramName . " = " . $paramValue;
                    $sql = "INSERT INTO txn_details (MID, ORDERID, TXNAMOUNT, CURRENCY, TXNID, BANKTXNID, STATUS, RESPCODE, RESPMSG, TXNDATE, GATEWAYNAME, BANKNAME, PAYMENTMODE) 
        VALUES ('$MID', '$ORDERID', '$TXNAMOUNT', '$CURRENCY', '$TXNID', '$BANKTXNID', '$STATUS', '$RESPCODE', '$RESPMSG', '$TXNDATE', '$GATEWAYNAME', '$BANKNAME', '$PAYMENTMODE')";  
        $result = $conn->query($sql);               
            }
        }


    }
    else {
        echo "<b>Checksum mismatched.</b>";
        //Process transaction as suspicious.
    }

    include 'footer.php';
    ?>

    </body>
    </html>


  [1]: https://i.stack.imgur.com/DnNRg.png

这是pgredirect.php,其中我定义了Mid Mid和OTHERS。

<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");

// following files need to be included
require_once("./lib/config_paytm.php");
require_once("./lib/encdec_paytm.php");

$checkSum = "";
$paramList = array();

$ORDER_ID = $_POST["ORDER_ID"];
$CUST_ID = $_POST["CUST_ID"];
$INDUSTRY_TYPE_ID = $_POST["INDUSTRY_TYPE_ID"];
$CHANNEL_ID = $_POST["CHANNEL_ID"];
$TXN_AMOUNT = $_POST["TXN_AMOUNT"];
$EMAIL = $_POST["EMAIL"];
$MSISDN = $_POST["MSISDN"];


// Create an array having all required parameters for creating checksum.
$paramList["MID"] = PAYTM_MERCHANT_MID;
$paramList["ORDER_ID"] = $ORDER_ID;
$paramList["CUST_ID"] = $CUST_ID;
$paramList["INDUSTRY_TYPE_ID"] = $INDUSTRY_TYPE_ID;
$paramList["CHANNEL_ID"] = $CHANNEL_ID;
$paramList["TXN_AMOUNT"] = $TXN_AMOUNT;
$paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
$paramList["CALLBACK_URL"] = "http://localhost/wd/response.php";


$paramList["MSISDN"] = $MSISDN; //Mobile number of customer
$paramList["EMAIL"] = $EMAIL; //Email ID of customer
$paramList["VERIFIED_BY"] = "EMAIL"; //
$paramList["IS_USER_VERIFIED"] = "YES"; //



//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);

?>
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
    <center><h1>Please do not refresh this page...</h1></center>
        <form method="post" action="<?php echo PAYTM_TXN_URL ?>" name="f1">
        <table border="1">
            <tbody>
            <?php
            foreach($paramList as $name => $value) {
                echo '<input type="hidden" name="' . $name .'" value="' . $value . '">';
            }
            ?>
            <input type="hidden" name="CHECKSUMHASH" value="<?php echo $checkSum ?>">
            </tbody>
        </table>
        <script type="text/javascript">
            document.f1.submit();
        </script>
    </form>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

您必须定义所有变量值并在foreach循环外写入INSERT语句。

答案 1 :(得分:0)

你的插入语句应如下所示。

if (isset($_POST) && count($_POST)>0 )
{  //here iam trying to store it but it is not working as shows undefined functions
  $sql = "INSERT INTO txn_details (MID, ORDERID, TXNAMOUNT, CURRENCY, TXNID, BANKTXNID, STATUS, RESPCODE, RESPMSG, TXNDATE, GATEWAYNAME, BANKNAME, PAYMENTMODE) 
        VALUES ('".$_POST['MID']."', '".$_POST['ORDERID']."', '".$_POST['TXNAMOUNT'].", '".$_POST['CURRENCY']."', '"..$_POST['TXNID']."', '"..$_POST['BANKTXNID']."', '".$_POST['STATUS']."', '".$_POST['RESPCODE']."', '".$_POST['RESPMSG']."', '".$_POST['TXNDATE']."', '".$_POST['GATEWAYNAME']."', '".$_POST['BANKNAME']."', '".$_POST['PAYMENTMODE']."')";  
        $result = $conn->query($sql);               

}