class ActiveMerchant::Billing::CtPaymentGateway
Constants
- CARD_BRAND
- 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/ct_payment.rb, line 29 def initialize(options = {}) requires!(options, :api_key, :company_number, :merchant_number) super end
Public Instance Methods
capture(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 62 def capture(money, authorization, options = {}) requires!(options, :order_id) post = {} add_invoice(post, money, options) add_money(post, money) add_customer_data(post, options) transaction_number, authorization_number, invoice_number = split_authorization(authorization) post[:OriginalTransactionNumber] = transaction_number post[:OriginalAuthorizationNumber] = authorization_number post[:OriginalInvoiceNumber] = invoice_number commit('completion', post) end
credit(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 89 def credit(money, payment, options = {}) requires!(options, :order_id) post = {} add_terminal_number(post, options) add_money(post, money) add_operator_id(post, options) add_invoice(post, money, options) add_payment(post, payment) add_address(post, payment, options) add_customer_data(post, options) payment.is_a?(String) ? commit('refundWithToken', post) : commit('refund', post) end
purchase(money, payment, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 34 def purchase(money, payment, options = {}) requires!(options, :order_id) post = {} add_terminal_number(post, options) add_money(post, money) add_operator_id(post, options) add_invoice(post, money, options) add_payment(post, payment) add_address(post, payment, options) add_customer_data(post, options) payment.is_a?(String) ? commit('purchaseWithToken', post) : commit('purchase', post) end
refund(money, authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 76 def refund(money, authorization, options = {}) requires!(options, :order_id) post = {} add_invoice(post, money, options) add_money(post, money) add_customer_data(post, options) transaction_number, _, invoice_number = split_authorization(authorization) post[:OriginalTransactionNumber] = transaction_number post[:OriginalInvoiceNumber] = invoice_number commit('refundWithoutCard', post) end
scrub(transcript)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 147 def scrub(transcript) transcript. gsub(%r((&?auth-api-key=)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?payload=)[a-zA-Z%0-9=]+)i, '\1[FILTERED]'). gsub(%r((&?token:)[^&]*)i, '\1[FILTERED]'). gsub(%r((&?cardNumber:)[^&]*)i, '\1[FILTERED]') end
store(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 129 def store(credit_card, options = {}) requires!(options, :email) post = { LanguageCode: 'E', Name: credit_card.name.rjust(50, ' '), Email: options[:email].rjust(240, ' ') } add_operator_id(post, options) add_payment(post, credit_card) add_customer_data(post, options) commit('recur/AddUser', post) end
supports_scrubbing?()
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 143 def supports_scrubbing? true end
verify(credit_card, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 116 def verify(credit_card, options = {}) requires!(options, :order_id) post = {} add_terminal_number(post, options) add_operator_id(post, options) add_invoice(post, 0, options) add_payment(post, credit_card) add_address(post, credit_card, options) add_customer_data(post, options) commit('verifyAccount', post) end
void(authorization, options = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 103 def void(authorization, options = {}) post = {} post[:InputType] = 'I' post[:LanguageCode] = 'E' transaction_number, _, invoice_number = split_authorization(authorization) post[:OriginalTransactionNumber] = transaction_number post[:OriginalInvoiceNumber] = invoice_number add_operator_id(post, options) add_customer_data(post, options) commit('void', post) end
Private Instance Methods
add_address(post, creditcard, options)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 173 def add_address(post, creditcard, options) if address = options[:billing_address] || options[:address] post[:CardHolderAddress] = "#{address[:address1]} #{address[:address2]} #{address[:city]} #{address[:state]}".rjust(20, ' ') post[:CardHolderPostalCode] = address[:zip].gsub(/\s+/, '').rjust(9, ' ') end end
add_customer_data(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 169 def add_customer_data(post, options) post[:CustomerNumber] = options[:customer_number] || '0' * 8 end
add_invoice(post, money, options)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 180 def add_invoice(post, money, options) post[:CurrencyCode] = options[:currency] || (currency(money) if money) post[:InvoiceNumber] = options[:order_id].rjust(12, '0') post[:InputType] = 'I' post[:LanguageCode] = 'E' end
add_money(post, money)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 161 def add_money(post, money) post[:Amount] = money.to_s.rjust(11, '0') end
add_operator_id(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 165 def add_operator_id(post, options) post[:OperatorID] = options[:operator_id] || '0' * 8 end
add_payment(post, payment)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 187 def add_payment(post, payment) if payment.is_a?(String) post[:Token] = split_authorization(payment)[3].strip else post[:CardType] = CARD_BRAND[payment.brand] || ' ' post[:CardNumber] = payment.number.rjust(40, ' ') post[:ExpirationDate] = expdate(payment) post[:Cvv2Cvc2Number] = payment.verification_value end end
add_terminal_number(post, options)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 157 def add_terminal_number(post, options) post[:MerchantTerminalNumber] = options[:merchant_terminal_number] || ' ' * 5 end
commit(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 222 def commit(action, parameters) if action == 'void' commit_raw(action, parameters) else MultiResponse.run(true) do |r| r.process { commit_raw(action, parameters) } r.process { split_auth = split_authorization(r.authorization) auth = (action.include?('recur') ? split_auth[4] : split_auth[0]) action.include?('recur') ? commit_raw('recur/ack', { ID: auth }) : commit_raw('ack', { TransactionNumber: auth }) } end end end
commit_raw(action, parameters)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 206 def commit_raw(action, parameters) url = (test? ? test_url : live_url) + action response = parse(ssl_post(url, post_data(action, parameters))) Response.new( success_from(response), message_from(response), response, authorization: authorization_from(response), avs_result: AVSResult.new(code: response['avsStatus']), cvv_result: CVVResult.new(response['cvv2Cvc2Status']), test: test?, error_code: error_code_from(response) ) end
error_code_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 264 def error_code_from(response) STANDARD_ERROR_CODE_MAPPING[response['returnCode'].strip || response['recurReturnCode'.strip]] unless success_from(response) end
message_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 245 def message_from(response) response['errorDescription'] || response['terminalDisp']&.strip end
parse(body)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 198 def parse(body) JSON.parse(body) end
post_data(action, parameters = {})
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 254 def post_data(action, parameters = {}) parameters[:CompanyNumber] = @options[:company_number] parameters[:MerchantNumber] = @options[:merchant_number] parameters = parameters.collect do |key, value| "#{key}=#{value}" unless value.nil? || value.empty? end.join('&') payload = Base64.strict_encode64(parameters) "auth-api-key=#{@options[:api_key]}&payload=#{payload}".strip end
success_from(response)
click to toggle source
# File lib/active_merchant/billing/gateways/ct_payment.rb, line 237 def success_from(response) return true if response['returnCode'] == ' 00' return true if response['returnCode'] == 'true' return true if response['recurReturnCode'] == ' 00' return false end