class ActiveMerchant::Billing::CardConnectGateway
Constants
- SCHEDULED_PAYMENT_TYPES
- 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/card_connect.rb, line 66 def initialize(options = {}) requires!(options, :merchant_id, :username, :password) require_valid_domain!(options, :domain) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 114 def capture(money, authorization, options = {}) post = {} add_money(post, money) add_reference(post, authorization) add_additional_data(post, options) commit('capture', post) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 78 def purchase(money, payment, options = {}) if options[:po_number] MultiResponse.run do |r| r.process { authorize(money, payment, options) } r.process { capture(money, r.authorization, options) } end else post = {} add_invoice(post, options) add_money(post, money) add_payment(post, payment) add_currency(post, money, options) add_address(post, options) add_customer_data(post, options) add_three_ds_mpi_data(post, options) add_additional_data(post, options) add_stored_credential(post, options) post[:capture] = 'Y' commit('auth', post) end end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 122 def refund(money, authorization, options = {}) post = {} add_money(post, money) add_reference(post, authorization) commit('refund', post) end
require_valid_domain!(options, param)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 72 def require_valid_domain!(options, param) if options[param] raise ArgumentError.new('not a valid cardconnect domain') unless /https:\/\/\D*cardconnect.com/ =~ options[param] end end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 161 def scrub(transcript) transcript. gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]'). gsub(%r(("cvv2\\":\\")\d*), '\1[FILTERED]'). gsub(%r(("merchid\\":\\")\d*), '\1[FILTERED]'). gsub(%r((&?"account\\":\\")\d*), '\1[FILTERED]'). gsub(%r((&?"token\\":\\")\d*), '\1[FILTERED]') end
store(payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 139 def store(payment, options = {}) post = {} add_payment(post, payment) add_address(post, options) add_customer_data(post, options) commit('profile', post) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 157 def supports_scrubbing? true end
unstore(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 147 def unstore(authorization, options = {}) account_id, profile_id = authorization.split('|') commit( 'profile', {}, verb: :delete, path: "/#{profile_id}/#{account_id}/#{@options[:merchant_id]}" ) end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 135 def verify(credit_card, options = {}) authorize(0, credit_card, options) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 129 def void(authorization, options = {}) post = {} add_reference(post, authorization) commit('void', post) end
Private Instance Methods
add_additional_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 232 def add_additional_data(post, options) post[:ponumber] = options[:po_number] post[:taxamnt] = options[:tax_amount] if options[:tax_amount] post[:frtamnt] = options[:freight_amount] if options[:freight_amount] post[:dutyamnt] = options[:duty_amount] if options[:duty_amount] post[:orderdate] = options[:order_date] if options[:order_date] post[:shipfromzip] = options[:ship_from_zip] if options[:ship_from_zip] if (shipping_address = options[:shipping_address]) post[:shiptozip] = shipping_address[:zip] post[:shiptocountry] = shipping_address[:country] end if options[:items] post[:items] = options[:items].map do |item| updated = {} item.each_pair do |k, v| updated.merge!(k.to_s.delete('_') => v) end updated end end post[:userfields] = options[:user_fields] if options[:user_fields] end
add_address(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 176 def add_address(post, options) if address = options[:billing_address] || options[:address] post[:address] = address[:address1] if address[:address1] post[:address2] = address[:address2] if address[:address2] post[:city] = address[:city] if address[:city] post[:region] = address[:state] if address[:state] post[:country] = address[:country] if address[:country] post[:postal] = address[:zip] if address[:zip] post[:phone] = address[:phone] if address[:phone] end end
add_currency(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 192 def add_currency(post, money, options) post[:currency] = (options[:currency] || currency(money)) end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 172 def add_customer_data(post, options) post[:email] = options[:email] if options[:email] end
add_echeck(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 222 def add_echeck(post, payment) post[:accttype] = 'ECHK' post[:account] = payment.account_number post[:bankaba] = payment.routing_number end
add_invoice(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 196 def add_invoice(post, options) post[:orderid] = options[:order_id] post[:ecomind] = if options[:ecomind] options[:ecomind].capitalize else (options[:recurring] ? 'R' : 'E') end end
add_money(post, money)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 188 def add_money(post, money) post[:amount] = amount(money) end
add_payment(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 205 def add_payment(post, payment) if payment.is_a?(String) account_id, profile_id = payment.split('|') post[:profile] = profile_id post[:acctid] = account_id else post[:name] = payment.name if card_brand(payment) == 'check' add_echeck(post, payment) else post[:account] = payment.number post[:expiry] = expdate(payment) post[:cvv2] = payment.verification_value end end end
add_reference(post, authorization)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 228 def add_reference(post, authorization) post[:retref] = authorization end
add_stored_credential(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 263 def add_stored_credential(post, options) return unless stored_credential = options[:stored_credential] post[:cof] = stored_credential[:initiator] == 'merchant' ? 'M' : 'C' post[:cofscheduled] = SCHEDULED_PAYMENT_TYPES.include?(stored_credential[:reason_type]) ? 'Y' : 'N' post[:cofpermission] = stored_credential[:initial_transaction] ? 'Y' : 'N' end
add_three_ds_mpi_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 255 def add_three_ds_mpi_data(post, options) return unless three_d_secure = options[:three_d_secure] post[:secureflag] = three_d_secure[:eci] post[:securevalue] = three_d_secure[:cavv] post[:securedstid] = three_d_secure[:ds_transaction_id] end
commit(action, parameters, verb: :put, path: '')
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 294 def commit(action, parameters, verb: :put, path: '') parameters[:frontendid] = application_id parameters[:merchid] = @options[:merchant_id] url = url(action, path) response = parse(ssl_request(verb, url, post_data(parameters), headers)) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), avs_result: AVSResult.new(code: response['avsresp']), cvv_result: CVVResult.new(response['cvvresp']), test: test?, error_code: error_code_from(response) ) rescue ResponseError => e return Response.new(false, 'Unable to authenticate. Please check your credentials.', {}, test: test?) if e.response.code == '401' raise end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 336 def error_code_from(response) STANDARD_ERROR_CODE_MAPPING[response['respcode']] unless success_from(response) end
expdate(credit_card)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 278 def expdate(credit_card) "#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}" end
headers()
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 271 def headers { 'Authorization' => 'Basic ' + Base64.strict_encode64("#{@options[:username]}:#{@options[:password]}"), 'Content-Type' => 'application/json' } end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 320 def message_from(response) response['setlstat'] ? "#{response['resptext']} #{response['setlstat']}" : response['resptext'] end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 282 def parse(body) JSON.parse(body) end
post_data(parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 332 def post_data(parameters = {}) parameters.to_json end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 316 def success_from(response) response['respstat'] == 'A' end
url(action, path)
click to toggle source
# File lib/active_merchant/billing/gateways/card_connect.rb, line 286 def url(action, path) if test? test_url + action + path else (@options[:domain] || live_url) + action + path end end