To generate the payment request form using Ruby on Rails please see the code below:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Hosted Checkout Payment Form Example - Ruby on Rails
</title>
</head>
<body>
<h1>
Hosted Checkout Payment Form Example - Ruby on Rails
</h1>
<p>
Disclaimer: this sample program is meant for guidance. There are no warranties about its functionality.
</p>
<p>
Click the "Pay" button to submit a test request to https://checkout.e-xact.com/pay.
</p>
<%= form_tag "https://checkout.e-xact.com/pay", :method=>:post %>
<%
# The payment data.
x_amount = "595.99"
x_login = "WSP-#####-##" # Take from Payment Page ID in Payment Pages interface
transaction_key = "########################" # Take from Payment Pages configuration interface
x_currency_code = "USD" # Needs to agree with the currency of the payment page
x_fp_sequence = ((rand*100000).to_i + 2000).to_s
x_fp_timestamp = Time.now.to_i.to_s # needs to be in UTC. Make sure webserver produces UTC
# The values that contribute to x_fp_hash
hmac_data = "#{x_login}^#{x_fp_sequence}^#{x_fp_timestamp}^#{x_amount}^#{x_currency_code}"
# calculate HMAC-SHA1
x_fp_hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("sha1"),transaction_key, hmac_data)
# or, to calculate HMAC-MD5, comment out above and uncomment below
#x_fp_hash = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new("md5"),transaction_key, hmac_data)
%>
<%= hidden_field_tag 'x_amount', x_amount %>
<%= hidden_field_tag 'x_login', x_login %>
<%= hidden_field_tag 'x_fp_sequence', x_fp_sequence %>
<%= hidden_field_tag :x_fp_timestamp, x_fp_timestamp %>
<%= hidden_field_tag :x_currency_code, x_currency_code %>
<%= hidden_field_tag :x_fp_hash, x_fp_hash %>
<%= hidden_field_tag :x_show_form, "PAYMENT_FORM" %>
<%= hidden_field_tag :x_test_request, "TRUE" %>
<%= hidden_field_tag :x_line_item, "1<|>Photo Plus Camera<|>Photo Plus Camera, 1 Year Warranty<|>1<|>595.99<|>NO" %>
<%= submit_tag "Pay with E-xact Transactions" %>
</form>
<body>
</html>
0 Comments