Module: Paygate
- Defined in:
- lib/paygate.rb,
lib/paygate/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
Class Method Details
.initiate_transaction(paygate_id, encription_key, reference_number, amount, currency, return_url, locale, country, recepient, pay_method) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/paygate.rb', line 8 def self.initiate_transaction(paygate_id, encription_key, reference_number, amount, currency, return_url, locale, country, recepient, pay_method) d = DateTime.now current_time = d.strftime("%Y-%m-%d %H:%M:%S") data = { PAYGATE_ID: paygate_id, REFERENCE: "#{reference_number}", AMOUNT: amount.to_i * 100, CURRENCY: currency, RETURN_URL: "#{return_url}", TRANSACTION_DATE: current_time, LOCALE: "#{locale}", COUNTRY: "#{country}", EMAIL: "#{recepient}", PAY_METHOD: "#{pay_method}" } a = data.map{|k,v| "#{v}"}.join('') checksum = Digest::MD5.hexdigest("#{a}#{encription_key}") data[:CHECKSUM] = checksum fields_string = data.to_query response = HTTParty.post("https://secure.paygate.co.za/payweb3/initiate.trans", { body: fields_string, headers: { 'Content-Type' => 'application/x-www-form-urlencoded', 'charset' => 'utf-8' } }) pay_request_id = response.split("&PAY_REQUEST_ID=")[1].split("&REFERENCE")[0] checkusm_from_response = response.split("&CHECKSUM=")[1] paygate_response = { :pay_request_id => pay_request_id, :checkusm_from_response => checkusm_from_response } end |