Class: Credomatic::Payments::Transactions
- Inherits:
-
Object
- Object
- Credomatic::Payments::Transactions
- Defined in:
- lib/credomatic/payments.rb
Instance Method Summary collapse
- #generate_transaction(type, redirect_url, ccnumber, ccexp, amount, orderid, cvv, avs, processor_id) ⇒ Object
-
#initialize(key_id, key) ⇒ Transactions
constructor
A new instance of Transactions.
- #input_hash(orderid, amount, time) ⇒ Object
- #key_id ⇒ Object
- #response_hash(orderid, amount, response, transactionid, avsresponse, cvvresponse, time) ⇒ Object
Constructor Details
#initialize(key_id, key) ⇒ Transactions
Returns a new instance of Transactions.
12 13 14 15 16 17 |
# File 'lib/credomatic/payments.rb', line 12 def initialize(key_id, key) @key_id = key_id @key = key @redirect_url = "https://credomatic.compassmerchantsolutions.com/api/transact.php" @api_url = "https://credomatic.compassmerchantsolutions.com/api/transact.php" end |
Instance Method Details
#generate_transaction(type, redirect_url, ccnumber, ccexp, amount, orderid, cvv, avs, processor_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/credomatic/payments.rb', line 30 def generate_transaction(type, redirect_url, ccnumber, ccexp, amount, orderid, cvv, avs, processor_id) @time = Time.now.getutc.to_i if type == "sale" @input_hash = input_hash("", amount, @time) else @input_hash = input_hash(orderid, amount, @time) end if redirect_url == nil uri = URI(@api_url) params = { type: type, key_id: @key_id, hash: @input_hash, time: @time, ccnumber: ccnumber, ccexp: ccexp, amount: "#{'%.2f' % amount}", orderid: orderid, cvv: cvv, avs: avs, processor_id: processor_id } response = Net::HTTP.post_form( uri, params ) if( response.is_a?( Net::HTTPSuccess ) ) # your request was successful responseValue = CGI::parse(response.body) responseValue = responseValue.each { |key, value| responseValue[key] = value.first} responseValue else # your request failed responseValue = CGI::parse(response.body) responseValue = responseValue.each { |key, value| responseValue[key] = value.first} responseValue end end end |
#input_hash(orderid, amount, time) ⇒ Object
19 20 21 22 |
# File 'lib/credomatic/payments.rb', line 19 def input_hash(orderid, amount, time) value = "#{orderid}|#{'%.2f' % amount}|#{time}|#{@key}" Digest::MD5.hexdigest(value) end |
#key_id ⇒ Object
70 71 72 |
# File 'lib/credomatic/payments.rb', line 70 def key_id @key_id end |
#response_hash(orderid, amount, response, transactionid, avsresponse, cvvresponse, time) ⇒ Object
24 25 26 27 |
# File 'lib/credomatic/payments.rb', line 24 def response_hash(orderid, amount, response, transactionid, avsresponse, cvvresponse, time) value = "#{orderid}|#{'%.2f' % amount}|#{response}|#{transactionid}|#{avsresponse}|#{cvvresponse}|#{time}|#{@key}" Digest::MD5.hexdigest(value) end |