class ActiveMerchant::Billing::MerchantOneGateway
Constants
- BASE_URL
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 21 def initialize(options = {}) requires!(options, :username, :password) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 46 def capture(money, authorization, options = {}) post = {} post[:transactionid] = authorization add_amount(post, money, options) commit('capture', money, post) end
new_connection(endpoint)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 53 def new_connection(endpoint) MerchantOneSslConnection.new(endpoint) end
purchase(money, creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 36 def purchase(money, creditcard, options = {}) post = {} add_customer_data(post, options) add_creditcard(post, creditcard) add_address(post, creditcard, options) add_customer_data(post, options) add_amount(post, money, options) commit('sale', money, post) end
Private Instance Methods
add_address(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 68 def add_address(post, creditcard, options) post['address1'] = options[:billing_address][:address1] post['city'] = options[:billing_address][:city] post['state'] = options[:billing_address][:state] post['zip'] = options[:billing_address][:zip] post['country'] = options[:billing_address][:country] end
add_amount(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 64 def add_amount(post, money, options) post['amount'] = amount(money) end
add_creditcard(post, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 76 def add_creditcard(post, creditcard) post['cvv'] = creditcard.verification_value post['ccnumber'] = creditcard.number post['ccexp'] = "#{sprintf('%02d', creditcard.month)}#{creditcard.year.to_s[-2, 2]}" end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 59 def add_customer_data(post, options) post['firstname'] = options[:billing_address][:first_name] post['lastname'] = options[:billing_address][:last_name] end
commit(action, money, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 82 def commit(action, money, parameters = {}) parameters['username'] = @options[:username] parameters['password'] = @options[:password] parse(ssl_post(BASE_URL, post_data(action, parameters))) end
parse(data)
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 98 def parse(data) responses = CGI.parse(data).inject({}) { |h, (k, v)| h[k] = v.first; h } Response.new( (responses['response'].to_i == 1), responses['responsetext'], responses, test: test?, authorization: responses['transactionid'] ) end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/merchant_one.rb, line 88 def post_data(action, parameters = {}) parameters[:type] = action ret = '' for key in parameters.keys ret += "#{key}=#{CGI.escape(parameters[key].to_s)}" ret += '&' if key != parameters.keys.last end ret.to_s end