I am trying to implement Pay U payment gateway in my web application.
I using a sample form to post payment values in the PayU form.
Please see my code below.
<form method="post" action="https://gateway.payulatam.com/ppp-web-gateway/">
<input name="merchantId" type="hidden" value="XXXXXX">
<input name="accountId" type="hidden" value="XXXXXX">
<input name="description" type="hidden" value="Test PAYU">
<input name="referenceCode" type="hidden" value="payment_test_00000001">
<input name="amount" type="hidden" value="3">
<input name="tax" type="hidden" value="0">
<input name="taxReturnBase" type="hidden" value="0">
<input name="currency" type="hidden" value="USD">
<input name="signature" type="hidden" value="be2f083cb3391c84fdf5fd6176801278">
<input name="test" type="hidden" value="1">
<input name="buyerEmail" type="hidden" value="[email protected]">
<input name="responseUrl" type="hidden" value="http://www.test.com/response">
<input name="confirmationUrl" type="hidden" value="http://www.test.com/confirmation">
<input name="Submit" type="submit" value="Enviar">
but I getting this error:
It's my mistake. Because the signature is not a MD5 string.
<input name="signature" type="hidden" value="be2f083cb3391c84fdf5fd6176801278">
it's need to write a new function for create MD5 string.
public static string CalculateMD5Hash(string input)
{
// step 1, calculate MD5 hash from input
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
then call this function like below.
string Signature = CommonHelper.CalculateMD5Hash(ApiKey + "~" + MerchantId + "~" + ReferenceCode + "~" + Amount + "~" + Currency);
(Please keep the parameter order in above function.)
Now the signature is created.
pass this signature in the form.
Works fine.
:)
y