class ActiveMerchant::Billing::FederatedCanadaGateway
Constants
- ERROR
Public Class Methods
new(options = {})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 23 def initialize(options = {}) requires!(options, :login, :password) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 46 def capture(money, authorization, options = {}) options[:transactionid] = authorization commit('capture', money, options) end
credit(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 60 def credit(money, authorization, options = {}) ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE refund(money, authorization, options) end
purchase(money, creditcard, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 28 def purchase(money, creditcard, options = {}) post = {} add_invoice(post, options) add_creditcard(post, creditcard) add_address(post, options) add_customer_data(post, options) commit('sale', money, post) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 56 def refund(money, authorization, options = {}) commit('refund', money, options.merge(transactionid: authorization)) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 51 def void(authorization, options = {}) options[:transactionid] = authorization commit('void', nil, options) end
Private Instance Methods
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 74 def add_address(post, options) if address = (options[:billing_address] || options[:address]) post[:company] = address[:company] post[:address1] = address[:address1] post[:address2] = address[:address2] post[:city] = address[:city] post[:state] = address[:state] post[:zip] = address[:zip] post[:country] = address[:country] post[:phone] = address[:phone] end if address = options[:shipping_address] post[:shipping_firstname] = address[:first_name] post[:shipping_lastname] = address[:last_name] post[:shipping_company] = address[:company] post[:shipping_address1] = address[:address1] post[:shipping_address2] = address[:address2] post[:shipping_city] = address[:city] post[:shipping_state] = address[:state] post[:shipping_zip] = address[:zip] post[:shipping_country] = address[:country] post[:shipping_email] = address[:email] end end
add_creditcard(post, creditcard)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 104 def add_creditcard(post, creditcard) post[:ccnumber] = creditcard.number post[:ccexp] = expdate(creditcard) post[:cvv] = creditcard.verification_value end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 67 def add_customer_data(post, options) post[:firstname] = options[:first_name] post[:lastname] = options[:last_name] post[:email] = options[:email] end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 99 def add_invoice(post, options) post[:orderid] = options[:order_id] post[:orderdescription] = options[:description] end
commit(action, money, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 118 def commit(action, money, parameters) parameters[:amount] = amount(money) data = ssl_post(self.live_url, post_data(action, parameters)) response = parse(data) message = message_from(response) Response.new( success?(response), message, response, test: test?, authorization: response['transactionid'], avs_result: { code: response['avsresponse'] }, cvv_result: response['cvvresponse'] ) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 143 def message_from(response) case response['response'].to_i when APPROVED 'Transaction Approved' when DECLINED 'Transaction Declined' else 'Error in transaction data or system error' end end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 110 def parse(body) body.split('&').inject({}) do |memo, x| k, v = x.split('=') memo[k] = v memo end end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 154 def post_data(action, parameters = {}) parameters[:type] = action parameters[:username] = @options[:login] parameters[:password] = @options[:password] parameters.map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&') end
success?(response)
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 135 def success?(response) response['response'] == '1' end
test?()
click to toggle source
# File lib/active_merchant/billing/gateways/federated_canada.rb, line 139 def test? @options[:login].eql?('demo') && @options[:password].eql?('password') end