Skip to content

Instantly share code, notes, and snippets.

@aruprakshit
Last active August 29, 2015 14:13
Show Gist options
  • Save aruprakshit/f4742766b66135446f59 to your computer and use it in GitHub Desktop.
Save aruprakshit/f4742766b66135446f59 to your computer and use it in GitHub Desktop.
<?php
$str = 'TESTME|UATTXN0001|NA|2|NA|NA|NA|INR|NA|R|NA|NA|NA|F|Andheri|Mumbai|02240920005|support@billdesk.com|NA|NA|NA|https://www.billdesk.com';
$checksum = hash_hmac('sha256',$str,'ABCDEF1234567890', false);
$checksum = strtoupper($checksum);
echo $checksum;
?>
<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997, 08:21:57 GMT">
<style>
.bodytxt4 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color: #666666;
}
.bodytxt {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: normal;
color: #000000;
}
.bullet1 {
list-style-type: square;
list-style-position: inside;
list-style-image: none;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
color: #FF9900;
}
.bodytxt2 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8pt;
font-weight: normal;
color: #333333;
}
A.sac2 {
COLOR: #000000;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
text-decoration: none;
}
A.sac2:visited {
COLOR: #314D5A; TEXT-DECORATION: none
}
A.sac2:hover {
COLOR: #FF9900; TEXT-DECORATION: underline
}
</style>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" valign="middle" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"></td>
</tr>
<tr>
<td height="85" align="center"><br>
<table width="80%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#CCCCCC"><table width="100%" border="0" cellpadding="6" cellspacing="0" bgcolor="#FFFFFF">
<tr valign="top">
<td colspan="2" align="left"><img src="/images/opps.gif" width="20" height="20">&nbsp;&nbsp;&nbsp;&nbsp;<span class="bodytxt4">Error
</span></td>
</tr>
<tr valign="top">
<td colspan="2" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="87%" bgcolor="#cccccc" height="1" align="center"></td>
</tr>
</table></td>
</tr>
<tr>
<td width="60%" align="left" valign="bottom"><table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td width="4%" align="right" valign="top"></td>
<td width="96%" class="bodytxt">&nbsp;</td>
</tr>
<tr>
<td height="19" align="right" valign="top"><li class="bullet1"></li></td>
<td class="bodytxt2">Sorry we are uable to process your request right now - Invalid merchant details (ERRP004).</td>
</tr>
<tr>
<td align="right" valign="top"></td>
<td class="bodytxt2" >&nbsp;</td>
</tr>
<tr>
<td align="right" valign="top"></td>
<td class="bodytxt2" >&nbsp;</td>
</tr>
</table></td>
<td align="right" valign="bottom">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
require "uri"
require "net/http"
url = 'https://pgi.billdesk.com/pgidsk/PGIMerchantPayment'
hash = {
MerchantID: 'xxxx',
CustomerID: 'A1234RT56',
Key_1: 'NA',
TxnAmount: '2',
Key_2: 'NA',
Key_3: 'NA',
Key_4: 'NA',
CurrencyType: 'INR',
Key_5: 'NA',
TypeField1: 'R',
SecurityID: 'maduracol',
Key_6: 'NA',
Key_7: 'NA',
TypeField2: 'F',
Txtadditionalinfo1: ""*12,
Txtadditionalinfo2: ""*12,
Txtadditionalinfo3: ""*12,
Txtadditionalinfo4: ""*12,
Txtadditionalinfo5: ""*12,
Txtadditionalinfo6: ""*12,
Txtadditionalinfo7: ""*12,
RU: 'http://14.18.60.129/shopping_cart/checkout'
}
msg = hash.values.join("|") << "|5ZYpFMJQ"
uri = URI.parse(url)
req = Net::HTTP::Post.new(url)
req.set_form_data({'msg' => msg})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true if uri.scheme == 'https'
http.start do |h|
response = h.request req
puts "Headers: #{response.to_hash.inspect}"
puts response.body
response = h.request Net::HTTP::Get.new(URI.parse(response['location']))
File.open('out.htm', 'w') { |f| f.write response.body }
end
@alex88
Copy link

alex88 commented Jan 20, 2015

require 'openssl'

digest = OpenSSL::Digest::SHA256.new
data = 'TESTME|UATTXN0001|NA|2|NA|NA|NA|INR|NA|R|NA|NA|NA|F|Andheri|Mumbai|02240920005|support@billdesk.com|NA|NA|NA|https://www.billdesk.com'
key = 'ABCDEF1234567890'

puts OpenSSL::HMAC.hexdigest(digest, key, data).upcase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment