Class: ActiveMerchant::Billing::CtPaymentGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/ct_payment.rb

Constant Summary collapse

STANDARD_ERROR_CODE_MAPPING =
{
  '14' => STANDARD_ERROR_CODE[:invalid_number],
  '05' => STANDARD_ERROR_CODE[:card_declined],
  'M6' => STANDARD_ERROR_CODE[:card_declined],
  '9068' => STANDARD_ERROR_CODE[:incorrect_number],
  '9067' => STANDARD_ERROR_CODE[:incorrect_number]
}
CARD_BRAND =
{
  'american_express' => 'A',
  'master' => 'M',
  'diners_club' => 'I',
  'visa' => 'V',
  'discover' => 'O'
}

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

Constructor Details

#initialize(options = {}) ⇒ CtPaymentGateway

Returns a new instance of CtPaymentGateway.



29
30
31
32
# File 'lib/active_merchant/billing/gateways/ct_payment.rb', line 29

def initialize(options = {})
  requires!(options, :api_key, :company_number, :merchant_number)
  super
end

Instance Method Details

#authorize(money, payment, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/active_merchant/billing/gateways/ct_payment.rb', line 48

def authorize(money, payment, options = {})
  requires!(options, :order_id)
  post = {}
  add_money(post, money)
  add_terminal_number(post, options)
  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('preAuthorizationWithToken', post) : commit('preAuthorization', post)
end

#capture(money, authorization, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# 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 = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# 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 = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# 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 = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
# 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) ⇒ Object



147
148
149
150
151
152
153
# 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 = {}) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# 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?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/active_merchant/billing/gateways/ct_payment.rb', line 143

def supports_scrubbing?
  true
end

#verify(credit_card, options = {}) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
# 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 = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# 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