Hash Secure not working in MIGS payment - php

I have implemented MIGS payment service in my magento installation and it is using a vpc_php_serverhost_do.php. These are the values Im passing to that file
<input type="hidden" name="virtualPaymentClientURL" size="63" value="https://migs.mastercard.com.au/vpcpay" maxlength="250">
<input type="hidden" name="vpc_Version" value="1" size="20" maxlength="8">
<input type="hidden" name="vpc_Command" value="pay" size="20" maxlength="16">
<input type="hidden" name="vpc_MerchTxnRef" value="<?php echo $orderId; ?>" size="20" maxlength="40">
<input type="hidden" name="vpc_AccessCode" value="<?php echo $access_code; ?>" size="20" maxlength="8">
<input type="hidden" name="vpc_Merchant" value="<?php echo $merchant; ?>" size="20" maxlength="16">
<input type="hidden" name="vpc_OrderInfo" value="<?php echo $orderId; ?>" size="20" maxlength="34">
<input type="hidden" name="vpc_Amount" value="<?php echo $amountInFils; ?>" size="20" maxlength="10">
<input type="hidden" name="vpc_Locale" value="en" size="20" maxlength="5">
<input type="hidden" name="vpc_ReturnURL" size="63" value="<?php echo $url;?>" maxlength="350">
<input type="hidden" name="vpc_user_SessionId" size="63" value="<?php echo $sessionId;?>" maxlength="350">
I have give secure secret provided by the client and the rest of the code looks like the one below
$vpcURL = $_POST["virtualPaymentClientURL"] . "?";
unset($_POST["virtualPaymentClientURL"]);
unset($_POST["SubButL"]);
$md5HashData = $SECURE_SECRET;
ksort ($_POST);
$appendAmp = 0;
foreach($_POST as $key => $value) {
if (strlen($value) > 0) {
if ($appendAmp == 0) {
$vpcURL .= urlencode($key) . '=' . urlencode($value);
$appendAmp = 1;
} else {
$vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
}
$md5HashData .= $value;
}
}
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}
header("Location: ".$vpcURL);
It is redirecting to the payment gateway as it should be. The problem is that the response i get after payment is not encoded. the response link is like this (for security reasons i have changed the numerals with x)
https://xxxxxx/site_test/vpc_php_serverhost_dr.php?vpc_Amount=xx&vpc_BatchNo=x&vpc_Command=pay&vpc_Locale=en&vpc_MerchTxnRef=xxxxx&vpc_Merchant=xxxxx&vpc_Message=Cancelled&vpc_OrderInfo=xxxxx&vpc_SecureHash=xxxxxxxx&vpc_TransactionNo=x&vpc_TxnResponseCode=C&vpc_Version=xx
What should I do to make the response url encoded?

Have you tried using:
<?php
$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
echo '<a href="mycgi?' . htmlentities($query_string) . '">';
?>
http://php.net/manual/en/function.urlencode.php

Related

how to run a form with parameter in codeigniter?

I am new to codeigniter and i want to run my sms web service code in view when user insert number.
but the post method is empty! can anyone help me?
var_dump($_POST['sendSms']);exit;
if(array_key_exists('sendSms', $_POST)) {
sendSms();
}
function sendSms(){ //my sms web service code}
echo '<form method="Post" action= "http://crm.oynarco.ir/admin/settings?group=sms">';
?>
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value="09172030433"/><br />';
echo '<input type="hidden" name="password" value="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value="5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value="'._l('send_test_sms').'" />';
echo '</form>';
in action root to controller then in controller get the post method and add your sms function.
?>
<form method="Post" action= "settings/sendSms">
<input type="hidden"
name="<?php echo $this->security->get_csrf_token_name()?>"
value="<?php echo $this->security->get_csrf_hash()?>">
<?php
echo '<input type="hidden" name="username" value = "09172030433"/><br />';
echo '<input type="hidden" name="password" value ="Oynar1234" /><br />';
echo '<input type="text" name="to" class="form-control test-phone" placeholder="'._l('staff_add_edit_phonenumber').'" /><br />';
echo '<textarea type="text" name="text" class="form-control sms-gateway-test-message" placeholder="'._l('test_sms_message').'" ></textarea><br />';
echo '<input type="text" name="From" class="form-control" value = "5000203069627" /><br />';
echo '<input type ="submit" name="sendSms" class="btn btn-info send-test-sms" value = "'._l('send_test_sms').'" />';
echo '</form>';
in controller:
public function sendSms(){
//var_dump($_POST);exit;
if (isset($_POST) ){
//send sms
}

Unable to get value in payumoney success response, which is passed from controller method

I have integrated payumoney payment gateway in my project and it was working fine, but I have additional requirements so I want to pass is an id. I am getting the ID like this '$this->input->post('id'), and assign it the variable $plan_info and pass it to the confirmation page(view page), when the user clicks on the confirm button, the payment will be done by debit/netbanking. In the success page, I am not getting $plan_info value however I am passing to the confirmation page.
Code written in controller
$product_info = 'testTransaction';
$customer_name = $this->input->post('customer_name');
$customer_email = $this->input->post('customer_email');
$customer_mobile = $this->input->post('mobile_number');
$id = $this->input->post('id');
$customer_address = $this->input->post('customer_address');
$MERCHANT_KEY = "xyz";
$SALT = "xyzxyz";
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
//optional udf values
$udf1 = '';
$udf2 = '';
$udf3 = '';
$udf4 = '';
$udf5 = '';
$hashstring = $MERCHANT_KEY . '|' . $txnid . '|' . $amount . '|' . $product_info . '|' . $customer_name . '|' . $customer_email . '|'. $udf1 . '|' . $udf2 . '|' . $udf3 . '|' . $udf4 . '|' . $udf5 . '||||||' . $SALT;
$hash = strtolower(hash('sha512', $hashstring));
$success = base_url() . 'Success';
$fail = base_url() . 'Success';
$cancel = base_url() . 'Success';
$data = array(
'mkey' => $MERCHANT_KEY,
'tid' => $txnid,
'hash' => $hash,
'amount' => $amount,
'name' => $customer_name,
'productinfo' => $product_info,
'mailid' => $customer_email,
'phoneno' => $customer_mobile,
'address' => $customer_address,
'action' => "https://test.payu.in", //for live change action
https://secure.payu.in
'sucess' => $success,
'failure' => $fail,
'cancel' => $cancel,
'plan_info'=>$id // This value which is passed to confirm page should get back in payment success response
);
$this->load->view('confirmation', $data);
code written in view file
<div class="card-body">
<form action="<?php echo $action; ?>/_payment" method="post" id="payuForm" name="payuForm">
<input type="hidden" name="key" value="<?php echo $mkey; ?>" />
<input type="hidden" name="hash" value="<?php echo $hash; ?>"/>
<input type="hidden" name="txnid" value="<?php echo $tid; ?>" />
<div class="form-group">
<label class="control-label">Total Payable Amount</label>
<input class="form-control" name="amount" value="<?php echo $amount; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Your Name</label>
<input class="form-control" name="firstname" id="firstname" value="<?php echo $name; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Email</label>
<input class="form-control" name="email" id="email" value="<?php echo $mailid; ?>" readonly/>
</div>
<div class="form-group">
<label class="control-label">Phone</label>
<input class="form-control" name="phone" value="<?php echo $phoneno; ?>" readonly />
</div>
<div class="form-group">
<label class="control-label"> Booking Info</label>
<input class="form-control" name="productinfo" value="<?php echo $productinfo; ?>" readonly />
<input type="hidden" class="form-control" name="plan_info" value="<?php echo $plan_info; ?>" />
</div>
<div class="form-group">
<label class="control-label">Address</label>
<input class="form-control" name="address1" value="<?php echo $address; ?>" readonly/>
</div>
<div class="form-group">
<input name="surl" value="<?php echo $sucess; ?>" size="64" type="hidden" />
<input name="furl" value="<?php echo $failure; ?>" size="64" type="hidden" />
<!--for test environment comment service provider -->
<input type="hidden" name="service_provider" value="payu_paisa" size="64" />
<input name="curl" value="<?php echo $cancel; ?> " type="hidden" />
</div>
<div class="form-group float-right">
<input type="submit" value="Pay Now" class="btn btn-success" />
</div>
</form>
</div>
My requirement
1) How do I pass the value inside udf1 (If I pass in $udf1 then I am getting a checksum error).
2) If the $planinfo variable passed separately (not in $udf1) then how to get that value in success page (I have tried echo '<pre>'; print_r($_POST); exit();) all values are getting except $plan_info value.
So how do I get plan info value and how can I pass in any value in uf1 without getting a checksum error
assign the $udf1 = $id before $hashstring
Pass the $udf1 value in $data array eg
$data =array('udf1' => $id,..)
Add/Pass the udf1 value in view page also.

how do i integration of payumoney payment gateway using isset function in php?

I have tried to integration of payumoney payment gateway. I have a page cart.php and i have done following code for the same:
if(isset($_POST['image-pay']){
$MERCHANT_KEY = "rjQUPktU";
$SALT = "e5iIg1jwi8";
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$key = $MERCHANT_KEY;
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
$productinfo = 'photos';
$firstname = $_POST['firstname'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$success_url = 'http://example.com/checkout/final-success.php';
$failure_url = 'http://example.com/checkout/failure.php';
$cancel_url = 'http://example.com/checkout/cancel.php';
$service_provider = "payu_paisa";
$hash = '';
$hasTemp = $key."|".$txnid."|".$amount."|".$productinfo."|".$firstname."|".$email."|||||||||||".$SALT;
$hash = strtolower(hash('sha512', $hasTemp));
$action = $PAYU_BASE_URL . '/_payment';
}
<form action="<?php echo $action; ?>" method="post" name="payuForm" id="jps_payuform">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY; ?>" />
<input type="hidden" name="hash" value="<?php echo $hash; ?>"/>
<input type="hidden" name="hash_temp" value="<?php echo $hasTemp; ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid; ?>" />
<input type="hidden" name="amount" value="<?php echo $amount; ?>" />
<input type="hidden" name="surl" value="<?php echo $success_url; ?>" size="64" />
<input type="hidden" name="furl" value="<?php echo $failure_url; ?>" size="64" />
<input type ="hidden" name="curl" value="<?php echo $cancel_url; ?>" />
<input type="hidden" name="service_provider" value="<?php echo $service_provider; ?>" size="64" />
<input type="hidden" name="productinfo" value="<?php echo $productinfo; ?>" />
<input type="hidden" name="udf1" value="<?php echo $numberPics; ?>" />
<h3 class="att_heading" style="text-align: center;">Your Personal Details</h3>
<label><span class="required_jps_field">*</span> Mandatory Parameters</b></label>
<label><span class="required_jps_field">*</span> Name: </label>
<input name="firstname" class="form-control" value="<?php echo $firstname; ?>" required />
<label><span class="required_jps_field">*</span> Email:</label>
<input name="email" id="email" class="form-control" value="<?php echo $email; ?>" required />
<label><span class="required_jps_field">*</span> Phone: </label>
<input name="phone" class="form-control" value="<?php echo $phone; ?>" required />
<input type="submit" class="btn btn-info" name="image-pay" value="Process" />
</form>
It's working fine but problem is when i use isset($_POST['image-pay']) function then i have to click twice on submit button and then it redirect payumoney page and if i remove this (isset($_POST['image-pay']) function then submit button works in single click but then it does not pass name, email and phone to payumoney.
Please help and tell me where am i doing wrong?

php repeat one value twice in the while loop (if possible)

I have this table:
emailtype:
emailtypeID emailtype
1 primary
2 secondary
3 old
I have this code to show emails in the input form:
$sql = "SELECT * from emailtype";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />'; }
GOAL:
I would like to repeat twice the emailtypeID = 2 or emailtype = secondary, so that I can enter two email addresses with the secondary ID.
Is it possible in the while loop?
Thanks!
SOLUTION:
For anybody who needs it, this is the new code as per the Marc B suggestion.
while($row = $result->fetch_assoc()) {
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
if($row["emailtype"] == 'secondario'){
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
}
}
Please use this:
while($row = $result->fetch_assoc()) {
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
if($row["emailtype"] == 'secondario' || $row["emailtypeID"]==2){
echo 'Email <input type="hidden" name="emailtype[]" id="" value="' . $row["emailtypeID"] . '"/>' . $row["emailtype"];
echo '<input type="text" name="email[]" id="" /><br />';
}
}

Undefined offset notice with array within foreach loop

i have a form.php with an array posting to update.php to update a mysql db.
The relevant parts of each are:
form.php
if ($type == "1") {echo '
<input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/>
<input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/>
<input type="text" name="serialnum[]" value="'. $row['SerialNumber'] .'"/>
<input type="text" name="unitsize[]" value="'. $row['UnitSize'] .'"/>
<input type="text" name="prop1[]" value="'. $row['Prop1'] .'"/>
<input type="text" name="latitude[]" value="'. $row['Latitude'] .'"/>
<input type="text" name="longitude[]" value="'. $row['Longitude'] .'"/>
';}
if ($type == "2") {echo '
<input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/>
<input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/>
<input type="text" name="serialnum[]" value="'. $row['SerialNumber'] .'"/>
<input type="text" name="unitsize[]" value="'. $row['UnitSize'] .'"/>
<input type="text" name="prop2[]" value="'. $row['Prop2'] .'"/>
<input type="text" name="latitude[]" value="'. $row['Latitude'] .'"/>
<input type="text" name="longitude[]" value="'. $row['Longitude'] .'"/>
';}
Update.php
foreach ($_POST['aid'] as $key=>$assetid) {
$atype = $_POST['atype'][$key];
if ($atype == "1") {
$stmt = $mysqli->stmt_init();
$query = "UPDATE asset SET
SerialNumber=?,UnitSize=?,Prop1=?,Latitude=?,Longitude=? WHERE AID = ?";
if($stmt->prepare($query)) {
$stmt->bind_param('sdddds', $serialnum, $unitsize, $prop1, $lat, $long, $assetid);
$assetid = $_POST['aid'][$key];
$serialnum = $_POST['serialnum'][$key];
$unitsize = $_POST['unitsize'][$key];
$prop1 = $_POST['prop1'][$key];
$lat = $_POST['latitude'][$key];
$long = $_POST['longitude'][$key];
$stmt->execute();
$stmt->close();
}
}
elseif ($atype == "2") {
$stmt = $mysqli->stmt_init();
$query = "UPDATE asset SET
SerialNumber=?,Prop2=?, Latitude=?,Longitude=? WHERE AID = ?";
if($stmt->prepare($query)) {
$stmt->bind_param('ssdds', $serialnum, $prop2, $lat, $long, $assetid);
$assetid = $_POST['aid'][$key];
$serialnum = $_POST['serialnum'][$key];
$prop2 = $_POST['prop2'][$key];
$lat = $_POST['latitude'][$key];
$long = $_POST['longitude'][$key];
$stmt->execute();
$stmt->close();
}
}}
This works great for all but one of the inputs in the array.
I keep getting the following:
Notice: Undefined offset: 3
relating to the following line:
$prop2 = $_POST['prop2'][$key];
All the other DB fields are updating fine except for this one. Can anyone point me in the right direction please?
You should use same name for this array input field. ie prop[] , but you used prop1[] and prop2[].
if ($type == "1") {echo '
<input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/>
<input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/>
<input type="text" name="serialnum[]" value="'. $row['SerialNumber'] .'"/>
<input type="text" name="unitsize[]" value="'. $row['UnitSize'] .'"/>
<input type="text" name="prop[]" value="'. $row['Prop1'] .'"/>
<input type="text" name="latitude[]" value="'. $row['Latitude'] .'"/>
<input type="text" name="longitude[]" value="'. $row['Longitude'] .'"/>
';}
if ($type == "2") {echo '
<input type="hidden" id="assettype" name="atype[]" value="'. $row['AType'] .'"/>
<input type="hidden" id="assetid" name="aid[]" value="'. $row['AID'] .'"/>
<input type="text" name="serialnum[]" value="'. $row['SerialNumber'] .'"/>
<input type="text" name="unitsize[]" value="'. $row['UnitSize'] .'"/>
<input type="text" name="prop[]" value="'. $row['Prop2'] .'"/>
<input type="text" name="latitude[]" value="'. $row['Latitude'] .'"/>
<input type="text" name="longitude[]" value="'. $row['Longitude'] .'"/>
';}
And in action page update like this:
$prop2 = $_POST['prop'][$key];
I don't know what logic you used, If there is a logical error use,
$prop2 = !empty($_POST['prop2'][$key]) ? $_POST['prop2'][$key] : '';

Categories