Class: ActiveMerchant::Billing::PayTraceGateway

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

Constant Summary collapse

STANDARD_ERROR_CODE_MAPPING =

Response codes based on API Response Codes found here: developers.paytrace.com/support/home#14000041297

{
  '1'   => STANDARD_ERROR_CODE[:error_occurred],
  '102' => STANDARD_ERROR_CODE[:declined],
  '103' => STANDARD_ERROR_CODE[:auto_voided],
  '107' => STANDARD_ERROR_CODE[:unsuccessful_refund],
  '108' => STANDARD_ERROR_CODE[:test_refund],
  '110' => STANDARD_ERROR_CODE[:unsuccessful_void],
  '113' => STANDARD_ERROR_CODE[:unsuccessful_capture]
}
ENDPOINTS =
{
  customer_id_sale: 'transactions/sale/by_customer',
  keyed_sale: 'transactions/sale/keyed',
  customer_id_auth: 'transactions/authorization/by_customer',
  keyed_auth: 'transactions/authorization/keyed',
  capture: 'transactions/authorization/capture',
  transaction_refund: 'transactions/refund/for_transaction',
  transaction_void: 'transactions/void',
  store: 'customer/create',
  redact: 'customer/delete',
  level_3_visa: 'level_three/visa',
  level_3_mastercard: 'level_three/mastercard',
  ach_sale: 'checks/sale/by_account',
  ach_customer_sale: 'checks/sale/by_customer',
  ach_authorize: 'checks/hold/by_account',
  ach_customer_authorize: 'checks/hold/by_customer',
  ach_refund: 'checks/refund/by_transaction',
  ach_capture: 'checks/manage/fund',
  ach_void: 'checks/manage/void'
}

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 = {}) ⇒ PayTraceGateway

Returns a new instance of PayTraceGateway.



46
47
48
49
50
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 46

def initialize(options = {})
  requires!(options, :username, :password, :integrator_id)
  super
  acquire_access_token unless options[:access_token]
end

Instance Method Details

#acquire_access_tokenObject



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 179

def acquire_access_token
  post = {}
  base_url = (test? ? test_url : live_url)
  post[:grant_type] = 'password'
  post[:username] = @options[:username]
  post[:password] = @options[:password]
  data = post.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
  url = base_url + '/oauth/token'
  oauth_headers = {
    'Accept'            => '*/*',
    'Content-Type'      => 'application/x-www-form-urlencoded'
  }
  response = ssl_post(url, data, oauth_headers)
  json_response = parse(response)

  if json_response.include?('error')
    oauth_response = Response.new(false, json_response['error_description'])
    raise OAuthResponseError.new(oauth_response)
  else
    @options[:access_token] = json_response['access_token'] if json_response['access_token']
    response
  end
end

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



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 76

def authorize(money, payment_or_customer_id, options = {})
  post = {}
  add_amount(post, money, options)
  if customer_id?(payment_or_customer_id)
    post[:customer_id] = payment_or_customer_id
    endpoint = if options[:check_transaction]
                 ENDPOINTS[:ach_customer_authorize]
               else
                 ENDPOINTS[:customer_id_auth]
               end
  else
    add_payment(post, payment_or_customer_id)
    add_address(post, payment_or_customer_id, options)
    add_customer_data(post, options)
    endpoint = payment_or_customer_id.kind_of?(Check) ? ENDPOINTS[:ach_authorize] : ENDPOINTS[:keyed_auth]
  end
  response = commit(endpoint, post)
  check_token_response(response, endpoint, post, options)
end

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



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 96

def capture(money, authorization, options = {})
  if visa_or_mastercard?(options)
    MultiResponse.run(:use_first_response) do |r|
      r.process { commit(ENDPOINTS[:capture], build_capture_request(money, authorization, options)) }
      r.process { commit(ENDPOINTS[:"level_3_#{options[:visa_or_mastercard]}"], send_level_3_data(r, options)) }
    end
  else
    post = build_capture_request(money, authorization, options)
    endpoint = if options[:check_transaction]
                 ENDPOINTS[:ach_capture]
               else
                 ENDPOINTS[:capture]
               end
    response = commit(endpoint, post)
    check_token_response(response, endpoint, post, options)
  end
end

#purchase(money, payment_or_customer_id, options = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 52

def purchase(money, payment_or_customer_id, options = {})
  if visa_or_mastercard?(options)
    MultiResponse.run(:use_first_response) do |r|
      endpoint = customer_id?(payment_or_customer_id) ? ENDPOINTS[:customer_id_sale] : ENDPOINTS[:keyed_sale]

      r.process { commit(endpoint, build_purchase_request(money, payment_or_customer_id, options)) }
      r.process { commit(ENDPOINTS[:"level_3_#{options[:visa_or_mastercard]}"], send_level_3_data(r, options)) }
    end
  else
    post = build_purchase_request(money, payment_or_customer_id, options)
    endpoint = if payment_or_customer_id.kind_of?(Check)
                 ENDPOINTS[:ach_sale]
               elsif options[:check_transaction]
                 ENDPOINTS[:ach_customer_sale]
               elsif post[:customer_id]
                 ENDPOINTS[:customer_id_sale]
               else
                 ENDPOINTS[:keyed_sale]
               end
    response = commit(endpoint, post)
    check_token_response(response, endpoint, post, options)
  end
end

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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 114

def refund(money, authorization, options = {})
  # currently only support full and partial refunds of settled transactions via a transaction ID
  post = {}
  add_amount(post, money, options)
  if options[:check_transaction]
    post[:check_transaction_id] = authorization
    endpoint = ENDPOINTS[:ach_refund]
  else
    post[:transaction_id] = authorization
    endpoint = ENDPOINTS[:transaction_refund]
  end
  response = commit(endpoint, post)
  check_token_response(response, endpoint, post, options)
end

#scrub(transcript) ⇒ Object



168
169
170
171
172
173
174
175
176
177
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 168

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Bearer )[a-zA-Z0-9:_]+), '\1[FILTERED]').
    gsub(%r(("credit_card\\?":{\\?"number\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("csc\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("username\\?":\\?")\w+@+\w+.+\w+), '\1[FILTERED]').
    gsub(%r(("username\\?":\\?")\w+), '\1[FILTERED]').
    gsub(%r(("password\\?":\\?")\w+), '\1[FILTERED]').
    gsub(%r(("integrator_id\\?":\\?")\w+), '\1[FILTERED]')
end

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

The customer_IDs that come from storing cards can be used for auth and purchase transaction types



148
149
150
151
152
153
154
155
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 148

def store(credit_card, options = {})
  post = {}
  post[:customer_id] = options[:customer_id] || SecureRandom.hex(12)
  add_payment(post, credit_card)
  add_address(post, credit_card, options)
  response = commit(ENDPOINTS[:store], post)
  check_token_response(response, ENDPOINTS[:store], post, options)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 164

def supports_scrubbing?
  true
end

#unstore(customer_id) ⇒ Object



157
158
159
160
161
162
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 157

def unstore(customer_id)
  post = {}
  post[:customer_id] = customer_id
  response = commit(ENDPOINTS[:redact], post)
  check_token_response(response, ENDPOINTS[:redact], post, options)
end

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



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

def verify(credit_card, options = {})
  authorize(0, credit_card, options)
end

#void(authorization, options = {}) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 129

def void(authorization, options = {})
  post = {}
  if options[:check_transaction]
    post[:check_transaction_id] = authorization
    endpoint = ENDPOINTS[:ach_void]
  else
    post[:transaction_id] = authorization
    endpoint = ENDPOINTS[:transaction_void]
  end

  response = commit(endpoint, post)
  check_token_response(response, endpoint, post, options)
end