Welcome Guest, Not a member yet? Register   Sign In
jQuery form submit problem
#1

[eluser]Unknown[/eluser]
I am new in here. I integreted a payment gateway thist is Payza. When i Submit form using jQuery (Internal Submit) it works good. But when Payza return me Instant Payment Notification then i call a function name is "addmachinery_suc". I save all return data in a text file.

But i think this function call 2 time. Because when i check text file i got 2 rows 1st row filled by right information but 2nd row is empty.

The main problem is i save data to my db and redirect another page with message. But when this function call 2nd time then it's error because it' empty. But i don't know why call this function 2 times.

Form Information

I think form is ok. Because one time change return url in another location line(www.mywebsite.com/payza/index.php) then its work fine.


addmachinery_suc Function is

Code:
<?php
function addmachinery_suc()
{
  $idUrl = $this->uri->segment(4);
  
  if($idUrl)
  {
  
  $sq = 'oZ9qLQqtW99JhQjk';
  $me = '[email protected]';
  
  define("IPN_SECURITY_CODE", "oZ9qLQqtW99JhQjk");  

  //Setting information about the transaction
  $receivedSecurityCode = $_POST['ap_securitycode'];
  $receivedMerchantEmailAddress = $_POST['ap_merchant'];
  $transactionStatus = $_POST['ap_status'];
  $testModeStatus = $_POST['ap_test'];  
  $purchaseType = $_POST['ap_purchasetype'];
  $totalAmountReceived = $_POST['ap_totalamount'];
  $feeAmount = $_POST['ap_feeamount'];
  $netAmount = $_POST['ap_netamount'];
  $transactionReferenceNumber = $_POST['ap_referencenumber'];
  $currency = $_POST['ap_currency'];  
  $transactionDate= $_POST['ap_transactiondate'];
  $transactionType= $_POST['ap_transactiontype'];
  
  //Setting the customer's information from the IPN post variables
  $customerFirstName = $_POST['ap_custfirstname'];
  $customerLastName = $_POST['ap_custlastname'];
  $customerAddress = $_POST['ap_custaddress'];
  $customerCity = $_POST['ap_custcity'];
  $customerState = $_POST['ap_custstate'];
  $customerCountry = $_POST['ap_custcountry'];
  $customerZipCode = $_POST['ap_custzip'];
  $customerEmailAddress = $_POST['ap_custemailaddress'];
  
  //Setting information about the purchased item from the IPN post variables
  $myItemName = $_POST['ap_itemname'];
  $myItemCode = $_POST['ap_itemcode'];
  $myItemDescription = $_POST['ap_description'];
  $myItemQuantity = $_POST['ap_quantity'];
  $myItemAmount = $_POST['ap_amount'];
  
  //Setting extra information about the purchased item from the IPN post variables
  $additionalCharges = $_POST['ap_additionalcharges'];
  $shippingCharges = $_POST['ap_shippingcharges'];
  $taxAmount = $_POST['ap_taxamount'];
  $discountAmount = $_POST['ap_discountamount'];
  
  //Setting your customs fields received from the IPN post variables
  $myCustomField_1 = $_POST['apc_1'];
  $myCustomField_2 = $_POST['apc_2'];
  $myCustomField_3 = $_POST['apc_3'];
  $myCustomField_4 = $_POST['apc_4'];
  $myCustomField_5 = $_POST['apc_5'];
  $myCustomField_6 = $_POST['apc_6'];
  
   if($receivedSecurityCode!=''){    
    if($receivedSecurityCode!=IPN_SECURITY_CODE)
    {
    
     //STAGE ONE
    
     $status = 'Mail MissMatch'." ".$receivedSecurityCode." ".$transactionStatus." ".$testModeStatus.$receivedMerchantEmailAddress." ".$me." ".$receivedSecurityCode." ".$sq;
     $myFile = "payza.txt";
     $fh = fopen($myFile, 'a') or die("can't open file");
    
     fwrite($fh, '<<'.$status.$receivedMerchantEmailAddress.'1>>');
     fclose($fh);
     $data=array('suc_message' => 'Unable to process your transaction right now, Please try again later1');
     $val = 1;
     $this->session->set_userdata($data);
     echo "[removed][removed]='".site_url('myfavorite/addmachinery')."/".$val."';[removed]";
     exit();
    }
    else
    {
    
     //STAGE TWO
    
     $status = $myItemCode." ".$transactionStatus." ".$myItemName." ".$currency." Goooooooooo ".$receivedMerchantEmailAddress." ".$me." ".$receivedSecurityCode." ".$sq;
    
     $sql = "select *from temp_machinery where machinery_id='".$myItemCode."'";
     $data['searchdata'] = $this->db->query($sql)->result_array();
    
     $myFile = "payza.txt";
     $fh = fopen($myFile, 'a') or die("can't open file");
    
     fwrite($fh, '<<'.$status.$receivedMerchantEmailAddress." ".$data['searchdata']['0']['user_id'].' 2 >>');
     fclose($fh);
     $data=array('suc_message' => 'Machinery added successfully!1');
     $val = 1;
     $this->session->set_userdata($data);
     echo "[removed][removed]='".site_url('myfavorite/addmachinery')."/".$val."';[removed]";
     exit();
    
    }
   }
  
  
   //STAGE THREE
  
   $myFile = "payza.txt";
   $fh = fopen($myFile, 'a') or die("can't open file");
  
   fwrite($fh, '<<Security Code Blank>>');
   fclose($fh);
   $val = 0;
   echo "[removed][removed]='".site_url('myfavorite/addmachinery')."/".$val."';[removed]";
  
  }
}
?&gt;


I need to redirect form "Stage One" or "Stage Two". But Unfortunately after complete "Stage One" or "Stage Two" this function aumatically call "Stage Three".

PLEASE GIVE A IDEA..............




Theme © iAndrew 2016 - Forum software by © MyBB