1

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.

12
  • 1
    Where is the ajax? Commented Sep 11, 2019 at 12:21
  • @mplungjan edited my question and added AJAX Commented Sep 11, 2019 at 12:28
  • I also tried sending only two values (amount and description) with AJAX but still couldn't succeed Commented Sep 11, 2019 at 12:29
  • You are not doing anything with the ajax response and you do nt have an error function to see if it failed Commented Sep 11, 2019 at 12:29
  • Have you checked response from the call? If you are getting response without errors, try to var_dump($_POST) to see if the values were passed to the server side. Commented Sep 11, 2019 at 12:35

1 Answer 1

1

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:

https://inweb.notesalong.com/id/5d78e9b04818060013b15b19/https://api.jquery.com/jquery.ajax/#notesalong:5d78e97645e451000020ae70;

Sign up to request clarification or add additional context in comments.

1 Comment

The first point works because I see correct amount value in the URL when sending, and I changed $("#hiddenForm").serialize to "amount=" + amount to see if problem is in this line, still get array(0) when var_dump($_POST)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.