Php 付款成功后如何将数据插入数据库

Php 付款成功后如何将数据插入数据库,php,mysql,payment-gateway,Php,Mysql,Payment Gateway,我想在成功付款后将表单数据保存到数据库中。我在支付网关代码之间插入了insert查询,它在支付失败时也存储数据。我正在使用payumoney网关。这是我的代码,请给我建议解决方案 <?php $MERCHANT_KEY = ""; $SALT = ""; // Merchant Key and Salt as provided by Payu. //$PAYU_BASE_URL = "https://sandboxsecure.payu.in"; // For Sandbox M

我想在成功付款后将表单数据保存到数据库中。我在支付网关代码之间插入了insert查询,它在支付失败时也存储数据。我正在使用payumoney网关。这是我的代码,请给我建议解决方案

<?php

$MERCHANT_KEY = "";
$SALT = "";
// Merchant Key and Salt as provided by Payu.
//$PAYU_BASE_URL = "https://sandboxsecure.payu.in";     // For Sandbox Mode
$PAYU_BASE_URL = "https://secure.payu.in";          // For Production Mode

$action = '';

$posted = array();
if(!empty($_POST)) {
    //print_r($_POST);
  foreach($_POST as $key => $value) {    
    $posted[$key] = $value; 

  }
}
$formError = 0;

if(empty($posted['txnid'])) {
  // Generate random transaction id
  $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
  $txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
  if(
          empty($posted['key'])
          || empty($posted['txnid'])
          || empty($posted['amount'])
          || empty($posted['firstname'])
          || empty($posted['email'])
          || empty($posted['phone'])
          || empty($posted['productinfo'])
          || empty($posted['surl'])
          || empty($posted['furl'])
          || empty($posted['service_provider'])
  ) {
    $formError = 1;
  } else {
    //$posted['productinfo'] = json_encode(json_decode('[{"name":"tutionfee","description":"","value":"500","isRequired":"false"},{"name":"developmentfee","description":"monthly tution fee","value":"1500","isRequired":"false"}]'));
    $hashVarsSeq = explode('|', $hashSequence);
    $hash_string = '';  
    foreach($hashVarsSeq as $hash_var) {
      $hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
      $hash_string .= '|';
    }
    $hash_string .= $SALT;
    $hash = strtolower(hash('sha512', $hash_string));
    $action = $PAYU_BASE_URL . '/_payment';
    date_default_timezone_set('Asia/Kolkata');
    $timestamp = date("Y-m-d h:i:s");  
    $conn = mysqli_connect("localhost","root","","hoysalat_temple");

    $result= mysqli_query($conn,"INSERT INTO temp_donor_list(`donor_name`, `email`, `donor_no`, `amount`, `date_time`,`cuid`,`web_user_id`) VALUES ('".$posted['firstname']."', '".$posted['email']."', '".$posted['phone']."', '".$posted['amount']."','".$timestamp."','".$uniqeid."','".$uniqeid."')"); 
  }
} elseif(!empty($posted['hash'])) { 
  $hash = $posted['hash'];
  $action = $PAYU_BASE_URL . '/_payment';
}
?>

您应该在下面提到成功或失败的URL名称文件:

<input name="surl" value="Success URL Example: success.php" />
<input name="furl" value="Failure URL Example: failure.php" />

Update my table set my_column='success',其中my_transaction_id=last_insert_id()
在支付网关代码之间插入查询
只需在收到响应(我在代码paymnoey请求中找不到)时将其写在末尾,它应该类似于`$response=request($params)`您将收到
$response
类似于
{“errorCode”:“message”:“所有TXNID都有效”,“responseCode”:“result”:{“amount”:“106.1”,“merchantTransactionId”:“396132-58876806”,“paymentId”:“58876806”,“status”:“Money with Payumoney”},“status”:“0”}
只要写一个if,看看有什么
errorCode
是空的,然后写到dbGood idea。但登录用户在刷新或打开成功页面时。同样,插入查询将正确执行?您可以设置if条件,如果数据不为null,则在需要的页面上插入else重定向。
$result= mysqli_query($conn,"INSERT INTO temp_donor_list(`donor_name`, `email`, `donor_no`, `amount`, `date_time`,`cuid`,`web_user_id`) VALUES ('".$posted['firstname']."', '".$posted['email']."', '".$posted['phone']."', '".$posted['amount']."','".$timestamp."','".$uniqeid."','".$uniqeid."')");