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'
}

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

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.



39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 39

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

Instance Method Details

#acquire_access_tokenObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 142

def acquire_access_token
  post = {}
  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 = live_url + '/oauth/token'
  oauth_headers = {
    'Accept'            => '*/*',
    'Content-Type'      => 'application/x-www-form-urlencoded'
  }
  response = ssl_post(url, data, oauth_headers)
  json_response = JSON.parse(response)

  @options[:access_token] = json_response['access_token'] if json_response['access_token']
  response
end

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 61

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 = ENDPOINTS[:customer_id_auth]
  else
    add_payment(post, payment_or_customer_id)
    add_address(post, payment_or_customer_id, options)
    add_customer_data(post, options)
    endpoint = ENDPOINTS[:keyed_auth]
  end
  response = commit(endpoint, post)
  check_token_response(response, endpoint, post, options)
end

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



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 77

def capture(money, authorization, options = {})
  if visa_or_mastercard?(options)
    MultiResponse.run 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)
    response = commit(ENDPOINTS[:capture], post)
    check_token_response(response, ENDPOINTS[:capture], post, options)
  end
end

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



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

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)
    post[:customer_id] ? endpoint = ENDPOINTS[:customer_id_sale] : endpoint = ENDPOINTS[:keyed_sale]
    response = commit(endpoint, post)
    check_token_response(response, endpoint, post, options)
  end
end

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



90
91
92
93
94
95
96
97
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 90

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)
  post[:transaction_id] = authorization
  response = commit(ENDPOINTS[:transaction_refund], post)
  check_token_response(response, ENDPOINTS[:transaction_refund], post, options)
end

#scrub(transcript) ⇒ Object



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

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Bearer )[a-zA-Z0-9:_]+), '\1[FILTERED]').
    gsub(%r(("credit_card\\?":{\\?"number\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]').
    gsub(%r(("username\\?":\\?")\w+@+\w+.+\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



112
113
114
115
116
117
118
119
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 112

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)


128
129
130
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 128

def supports_scrubbing?
  true
end

#unstore(customer_id) ⇒ Object



121
122
123
124
125
126
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 121

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



107
108
109
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 107

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

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



99
100
101
102
103
104
105
# File 'lib/active_merchant/billing/gateways/pay_trace.rb', line 99

def void(authorization, options = {})
  post = {}
  post[:transaction_id] = authorization

  response = commit(ENDPOINTS[:transaction_void], post)
  check_token_response(response, ENDPOINTS[:transaction_void], post, options)
end