class ActiveMerchant::Billing::CamsGateway
Constants
- STANDARD_ERROR_CODE_MAPPING
Public Class Methods
new(options={})
click to toggle source
Calls superclass method
ActiveMerchant::Billing::Gateway::new
# File lib/active_merchant/billing/gateways/cams.rb, line 70 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/cams.rb, line 98 def capture(money, authorization, options={}) post = {} add_reference(post, authorization) add_invoice(post, money, options) commit('capture', post) end
purchase(money, payment, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 75 def purchase(money, payment, options={}) post = {} add_invoice(post, money, options) if payment.respond_to?(:number) add_payment(post, payment) add_address(post, payment, options) elsif payment.kind_of?(String) post[:transactionid] = split_authorization(payment)[0] end commit('sale', post) end
refund(money, authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 106 def refund(money, authorization, options={}) post = {} add_reference(post, authorization) add_invoice(post, money, options) commit('refund', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 131 def scrub(transcript) %w(ccnumber cvv password).each do |field| transcript = transcript.gsub(%r((#{field}=)[^&]+), '\1[FILTERED]\2') end transcript end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 127 def supports_scrubbing? true end
verify(credit_card, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 119 def verify(credit_card, options={}) post = {} add_invoice(post, 0, options) add_payment(post, credit_card) add_address(post, credit_card, options) commit('verify', post) end
void(authorization, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 113 def void(authorization, options={}) post = {} add_reference(post, authorization) commit('void', post) end
Private Instance Methods
add_address(post, creditcard, options={})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 141 def add_address(post, creditcard, options={}) post[:firstname] = creditcard.first_name post[:lastname] = creditcard.last_name return unless options[:billing_address] address = options[:billing_address] 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
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 163 def add_invoice(post, money, options) post[:amount] = amount(money) post[:currency] = (options[:currency] || default_currency) end
add_payment(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 168 def add_payment(post, payment) post[:ccnumber] = payment.number post[:ccexp] = "#{payment.month.to_s.rjust(2, "0")}#{payment.year.to_s[-2..-1]}" post[:cvv] = payment.verification_value end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 157 def add_reference(post, authorization) transaction_id, authcode = split_authorization(authorization) post['transactionid'] = transaction_id post['authcode'] = authcode end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 184 def commit(action, parameters) url = live_url parameters[:type] = action response_body = ssl_post(url, post_data(parameters)) response = parse(response_body) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), test: test?, error_code: error_code_from(response) ) end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 225 def error_code_from(response) STANDARD_ERROR_CODE_MAPPING[response['response_code']] end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 205 def message_from(response) response['responsetext'] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 174 def parse(body) kvs = body.split('&') kvs.inject({}) { |h, kv| k, v = kv.split('=') h[k] = v h } end
post_data(parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 218 def post_data(parameters = {}) parameters[:password] = @options[:password] parameters[:username] = @options[:username] parameters.collect { |k, v| "#{k}=#{v}" }.join('&') end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/cams.rb, line 201 def success_from(response) response['response_code'] == '100' end