Reputation: 47
For online payment I have to send parameters to an URL. Calculations in my site written in Javascript, Online payment company requires PHP parameters like MD5 hashing.
I tried creating hidden form and put required javascript values into input fields. And succeded.
My hidden form:
<form action="https://test.millikart.az:7444/gateway/payment/register" method="get" id="hiddenForm">
<input name="mid" value="unicopy" type="hidden">
<input name="amount" id="amount" value="" type="hidden">
<input name="currency" value="944" type="hidden">
<input name="description" value="" id="description" type="hidden">
<input name="reference" value="UNICSH3195319" type="hidden">
<input name="language" value="az" type="hidden">
<input name="signature" value="<?php echo htmlspecialchars($signature); ?>" type="hidden">
<button type="button" class="btn btn-secondary" data-dismiss="modal" onClick="clearList()" >Reset</button>
<button class="btn btn-primary" id="odenis" >Pay</button>
</form>
<script>
document.getElementById("amount").value= parseInt(yekunMeblegArray.reduce(myFunc));
document.getElementById("description").value= description;
//AJAX
$.ajax({
type: 'POST',
url: "index.php",
data: $("#hiddenForm").serialize(),
success: function(response) {
alert("succeed")},
});
</script>
But before sending the URL I have to prepare $signature with PHP that should include value from javascript
My PHP:
<?php
$mid="unicopy";
$amount=$_POST['amount'];
$currency="944";
$description=$_POST['desc'];
$reference="UNICSH3195319";
$language="az";
$key="123456qwerty";
$signature=strtoupper(md5(strlen($mid).$mid.strlen($amount).$amount.strlen($currency).$currency.(!empty($description)? strlen($description).$description :"0").strlen($reference).$reference.strlen($language).$language.$key));
?>
As you can see $signature includes $amount and $description variables that should get its values from javascript. I tried sending form data with AJAX but couldn't succeed. How can I achieve this? Any kind of help is appreciated.
Upvotes: 1
Views: 85
Reputation: 5874
My guess is that either:
1) document.getElementById("amount").value= parseInt(yekunMeblegArray.reduce(myFunc));
does not set a proper value (you can debug with console.log
statement underneath value being set.
Or
2) $("#hiddenForm").serialize()
this function call does not generate data in the way you think it does. You should console.log
to investigate.
I recommend you look at contentType
and dataType
properties of the ajax
object in:
Upvotes: 1