activemerchant 1.60.0 → 1.61.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +64 -0
  3. data/lib/active_merchant/billing/gateways/authorize_net.rb +1 -1
  4. data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +12 -1
  5. data/lib/active_merchant/billing/gateways/blue_pay.rb +1 -1
  6. data/lib/active_merchant/billing/gateways/blue_snap.rb +1 -1
  7. data/lib/active_merchant/billing/gateways/braintree_blue.rb +8 -0
  8. data/lib/active_merchant/billing/gateways/card_stream.rb +2 -0
  9. data/lib/active_merchant/billing/gateways/citrus_pay.rb +24 -0
  10. data/lib/active_merchant/billing/gateways/clearhaus.rb +12 -4
  11. data/lib/active_merchant/billing/gateways/conekta.rb +6 -1
  12. data/lib/active_merchant/billing/gateways/credorax.rb +234 -0
  13. data/lib/active_merchant/billing/gateways/cyber_source.rb +39 -52
  14. data/lib/active_merchant/billing/gateways/element.rb +13 -2
  15. data/lib/active_merchant/billing/gateways/fat_zebra.rb +12 -3
  16. data/lib/active_merchant/billing/gateways/firstdata_e4.rb +5 -0
  17. data/lib/active_merchant/billing/gateways/global_collect.rb +3 -1
  18. data/lib/active_merchant/billing/gateways/jetpay.rb +11 -3
  19. data/lib/active_merchant/billing/gateways/linkpoint.rb +2 -0
  20. data/lib/active_merchant/billing/gateways/litle.rb +28 -12
  21. data/lib/active_merchant/billing/gateways/mastercard.rb +261 -0
  22. data/lib/active_merchant/billing/gateways/migs.rb +23 -1
  23. data/lib/active_merchant/billing/gateways/monei.rb +1 -1
  24. data/lib/active_merchant/billing/gateways/moneris.rb +13 -0
  25. data/lib/active_merchant/billing/gateways/netbanx.rb +245 -0
  26. data/lib/active_merchant/billing/gateways/nmi.rb +5 -0
  27. data/lib/active_merchant/billing/gateways/openpay.rb +7 -0
  28. data/lib/active_merchant/billing/gateways/opp.rb +362 -0
  29. data/lib/active_merchant/billing/gateways/orbital.rb +13 -0
  30. data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +190 -0
  31. data/lib/active_merchant/billing/gateways/payflow.rb +6 -0
  32. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
  33. data/lib/active_merchant/billing/gateways/paymill.rb +10 -0
  34. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +1 -1
  35. data/lib/active_merchant/billing/gateways/payu_latam.rb +386 -0
  36. data/lib/active_merchant/billing/gateways/pin.rb +1 -3
  37. data/lib/active_merchant/billing/gateways/redsys.rb +2 -0
  38. data/lib/active_merchant/billing/gateways/sage.rb +22 -0
  39. data/lib/active_merchant/billing/gateways/sage_pay.rb +12 -0
  40. data/lib/active_merchant/billing/gateways/securion_pay.rb +2 -2
  41. data/lib/active_merchant/billing/gateways/stripe.rb +29 -8
  42. data/lib/active_merchant/billing/gateways/telr.rb +275 -0
  43. data/lib/active_merchant/billing/gateways/tns.rb +12 -230
  44. data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +1 -1
  45. data/lib/active_merchant/billing/gateways/vanco.rb +12 -8
  46. data/lib/active_merchant/billing/gateways/worldpay.rb +18 -0
  47. data/lib/active_merchant/country.rb +6 -2
  48. data/lib/active_merchant/version.rb +1 -1
  49. metadata +11 -3
@@ -0,0 +1,261 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ module MastercardGateway
4
+
5
+ def initialize(options={})
6
+ requires!(options, :userid, :password)
7
+ super
8
+ end
9
+
10
+ def purchase(amount, payment_method, options={})
11
+ MultiResponse.run do |r|
12
+ r.process { authorize(amount, payment_method, options) }
13
+ r.process { capture(amount, r.authorization, options) }
14
+ end
15
+ end
16
+
17
+ def authorize(amount, payment_method, options={})
18
+ post = new_post
19
+ add_invoice(post, amount, options)
20
+ add_reference(post, *new_authorization)
21
+ add_payment_method(post, payment_method)
22
+ add_customer_data(post, payment_method, options)
23
+
24
+ commit('authorize', post)
25
+ end
26
+
27
+ def capture(amount, authorization, options={})
28
+ post = new_post
29
+ add_invoice(post, amount, options, :transaction)
30
+ add_reference(post, *next_authorization(authorization))
31
+ add_customer_data(post, nil, options)
32
+
33
+ commit('capture', post)
34
+ end
35
+
36
+ def refund(amount, authorization, options={})
37
+ post = new_post
38
+ add_invoice(post, amount, options, :transaction)
39
+ add_reference(post, *next_authorization(authorization))
40
+ add_customer_data(post, nil, options)
41
+
42
+ commit('refund', post)
43
+ end
44
+
45
+ def void(authorization, options={})
46
+ post = new_post
47
+ add_reference(post, *next_authorization(authorization), :targetTransactionId)
48
+
49
+ commit('void', post)
50
+ end
51
+
52
+ def verify(credit_card, options={})
53
+ MultiResponse.run(:use_first_response) do |r|
54
+ r.process { authorize(100, credit_card, options) }
55
+ r.process(:ignore_result) { void(r.authorization, options) }
56
+ end
57
+ end
58
+
59
+ def verify_credentials
60
+ url = build_url(SecureRandom.uuid, "nonexistent")
61
+ begin
62
+ ssl_get(url, headers)
63
+ rescue ResponseError => e
64
+ return false if e.response.code.to_i == 401
65
+ end
66
+
67
+ true
68
+ end
69
+
70
+ def supports_scrubbing?
71
+ true
72
+ end
73
+
74
+ def scrub(transcript)
75
+ transcript.
76
+ gsub(%r((Authorization: Basic ).*\\r\\n), '\1[FILTERED]').
77
+ gsub(%r(("number"?\\?":"?\\?")\d*), '\1[FILTERED]').
78
+ gsub(%r(("securityCode"?\\?":"?\\?")\d*), '\1[FILTERED]')
79
+ end
80
+
81
+ private
82
+ def new_post
83
+ {
84
+ order: {},
85
+ sourceOfFunds: {
86
+ provided: {
87
+ card: {
88
+ }
89
+ }
90
+ },
91
+ customer: {},
92
+ billing: {},
93
+ device: {},
94
+ shipping: {},
95
+ transaction: {},
96
+ }
97
+ end
98
+
99
+ def add_invoice(post, amount, options, node=:order)
100
+ post[node][:amount] = amount(amount)
101
+ post[node][:currency] = (options[:currency] || currency(amount))
102
+ end
103
+
104
+ def add_reference(post, orderid, transactionid, transaction_reference, reference_key=:reference)
105
+ post[:orderid] = orderid
106
+ post[:transactionid] = transactionid
107
+ post[:transaction][reference_key] = transaction_reference if transaction_reference
108
+ end
109
+
110
+ def add_payment_method(post, payment_method)
111
+ card = {}
112
+ card[:expiry] = {}
113
+ card[:number] = payment_method.number
114
+ card[:securityCode] = payment_method.verification_value
115
+ card[:expiry][:year] = format(payment_method.year, :two_digits)
116
+ card[:expiry][:month] = format(payment_method.month, :two_digits)
117
+
118
+ post[:sourceOfFunds][:type] = 'CARD'
119
+ post[:sourceOfFunds][:provided][:card].merge!(card)
120
+ end
121
+
122
+ def add_customer_data(post, payment_method, options)
123
+ billing = {}
124
+ shipping = {}
125
+ customer = {}
126
+ device = {}
127
+
128
+ customer[:firstName] = payment_method.first_name if payment_method
129
+ customer[:lastName] = payment_method.last_name if payment_method
130
+ customer[:email] = options[:email] if options[:email]
131
+ device[:ipAddress] = options[:ip] if options[:ip]
132
+
133
+ if (billing_address = options[:billing_address])
134
+ billing[:address] = {}
135
+ billing[:address][:street] = billing_address[:address1]
136
+ billing[:address][:street2] = billing_address[:address2]
137
+ billing[:address][:city] = billing_address[:city]
138
+ billing[:address][:stateProvince] = billing_address[:state]
139
+ billing[:address][:postcodeZip] = billing_address[:zip]
140
+ billing[:address][:country] = country_code(billing_address[:country])
141
+ customer[:phone] = billing_address[:phone]
142
+ end
143
+
144
+ if (shipping_address = options[:shipping_address])
145
+ shipping[:address] = {}
146
+ shipping[:address][:street] = shipping_address[:address1]
147
+ shipping[:address][:street2] = shipping_address[:address2]
148
+ shipping[:address][:city] = shipping_address[:city]
149
+ shipping[:address][:stateProvince] = shipping_address[:state]
150
+ shipping[:address][:postcodeZip] = shipping_address[:zip]
151
+ shipping[:address][:shipcountry] = country_code(shipping_address[:country])
152
+
153
+ first_name, last_name = split_names(shipping_address[:name])
154
+ shipping[:firstName] = first_name if first_name
155
+ shipping[:lastName] = last_name if last_name
156
+ end
157
+ post[:billing].merge!(billing)
158
+ post[:shipping].merge!(shipping)
159
+ post[:device].merge!(device)
160
+ post[:customer].merge!(customer)
161
+ end
162
+
163
+ def country_code(country)
164
+ if country
165
+ country = ActiveMerchant::Country.find(country)
166
+ country.code(:alpha3).value
167
+ end
168
+ rescue InvalidCountryCodeError
169
+ end
170
+
171
+ def headers
172
+ {
173
+ 'Authorization' => 'Basic ' + Base64.encode64("merchant.#{@options[:userid]}:#{@options[:password]}").strip.delete("\r\n"),
174
+ 'Content-Type' => 'application/json',
175
+ }
176
+ end
177
+
178
+ def commit(action, post)
179
+ url = build_url(post.delete(:orderid), post.delete(:transactionid))
180
+ post[:apiOperation] = action.upcase
181
+ begin
182
+ raw = parse(ssl_request(:put, url, build_request(post), headers))
183
+ rescue ResponseError => e
184
+ raw = parse(e.response.body)
185
+ end
186
+ succeeded = success_from(raw)
187
+ Response.new(
188
+ succeeded,
189
+ message_from(succeeded, raw),
190
+ raw,
191
+ :authorization => authorization_from(post, raw),
192
+ :test => test?
193
+ )
194
+ end
195
+
196
+ def build_url(orderid, transactionid)
197
+ "#{base_url}merchant/#{@options[:userid]}/order/#{orderid}/transaction/#{transactionid}"
198
+ end
199
+
200
+ def base_url
201
+ if test?
202
+ @options[:region] == 'asia_pacific' ? test_ap_url : test_na_url
203
+ else
204
+ @options[:region] == 'asia_pacific' ? live_ap_url : live_na_url
205
+ end
206
+ end
207
+
208
+ def build_request(post = {})
209
+ post.to_json
210
+ end
211
+
212
+ def parse(body)
213
+ JSON.parse(body)
214
+ end
215
+
216
+ def success_from(response)
217
+ response['result'] == "SUCCESS"
218
+ end
219
+
220
+ def message_from(succeeded, response)
221
+ if succeeded
222
+ 'Succeeded'
223
+ else
224
+ [
225
+ response['result'],
226
+ response['response'] && response['response']['gatewayCode'],
227
+ response['error'] && response['error']['cause'],
228
+ response['error'] && response['error']['explanation']
229
+ ].compact.join(' - ')
230
+ end
231
+ end
232
+
233
+ def authorization_from(request, response)
234
+ [response['order']['id'], response['transaction']['id']].join('|') if response['order']
235
+ end
236
+
237
+ def split_authorization(authorization)
238
+ authorization.split('|')
239
+ end
240
+
241
+ def new_authorization
242
+ # Must be unique within a merchant id.
243
+ orderid = SecureRandom.uuid
244
+
245
+ # Must be unique within an order id.
246
+ transactionid = '1'
247
+
248
+ # New transactions have no previous reference.
249
+ transaction_reference = nil
250
+ [orderid, transactionid, transaction_reference]
251
+ end
252
+
253
+ def next_authorization(authorization)
254
+ orderid, prev_transactionid = split_authorization(authorization)
255
+ next_transactionid = SecureRandom.uuid
256
+ [orderid, next_transactionid, prev_transactionid]
257
+ end
258
+
259
+ end
260
+ end
261
+ end
@@ -25,6 +25,7 @@ module ActiveMerchant #:nodoc:
25
25
  self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
26
26
 
27
27
  self.money_format = :cents
28
+ self.currencies_without_fractions = %w(IDR)
28
29
 
29
30
  # The homepage URL of the gateway
30
31
  self.homepage_url = 'http://mastercard.com/mastercardsps'
@@ -63,6 +64,7 @@ module ActiveMerchant #:nodoc:
63
64
  add_invoice(post, options)
64
65
  add_creditcard(post, creditcard)
65
66
  add_standard_parameters('pay', post, options[:unique_id])
67
+ add_3ds(post, options)
66
68
 
67
69
  commit(post)
68
70
  end
@@ -103,6 +105,17 @@ module ActiveMerchant #:nodoc:
103
105
  commit(post)
104
106
  end
105
107
 
108
+ def void(authorization, options = {})
109
+ requires!(@options, :advanced_login, :advanced_password)
110
+
111
+ post = options.merge(:TransNo => authorization)
112
+
113
+ add_advanced_user(post)
114
+ add_standard_parameters('voidAuthorisation', post, options[:unique_id])
115
+
116
+ commit(post)
117
+ end
118
+
106
119
  def credit(money, authorization, options = {})
107
120
  ActiveMerchant.deprecated CREDIT_DEPRECATION_MESSAGE
108
121
  refund(money, authorization, options)
@@ -189,7 +202,7 @@ module ActiveMerchant #:nodoc:
189
202
  private
190
203
 
191
204
  def add_amount(post, money, options)
192
- post[:Amount] = amount(money)
205
+ post[:Amount] = localized_amount(money, options[:currency])
193
206
  post[:Currency] = options[:currency] if options[:currency]
194
207
  end
195
208
 
@@ -202,6 +215,15 @@ module ActiveMerchant #:nodoc:
202
215
  post[:OrderInfo] = options[:order_id]
203
216
  end
204
217
 
218
+ def add_3ds(post, options)
219
+ post[:VerType] = options[:ver_type] if options[:ver_type]
220
+ post[:VerToken] = options[:ver_token] if options[:ver_token]
221
+ post["3DSXID"] = options[:three_ds_xid] if options[:three_ds_xid]
222
+ post["3DSECI"] = options[:three_ds_eci] if options[:three_ds_eci]
223
+ post["3DSenrolled"] = options[:three_ds_enrolled] if options[:three_ds_enrolled]
224
+ post["3DSstatus"] = options[:three_ds_status] if options[:three_ds_status]
225
+ end
226
+
205
227
  def add_creditcard(post, creditcard)
206
228
  post[:CardNum] = creditcard.number
207
229
  post[:CardSecurityCode] = creditcard.verification_value if creditcard.verification_value?
@@ -14,7 +14,7 @@ module ActiveMerchant #:nodoc:
14
14
  self.test_url = 'https://test.monei-api.net/payment/ctpe'
15
15
  self.live_url = 'https://monei-api.net/payment/ctpe'
16
16
 
17
- self.supported_countries = ['ES']
17
+ self.supported_countries = ['AD', 'AT', 'BE', 'BG', 'CH', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FO', 'FR', 'GB', 'GI', 'GR', 'HU', 'IE', 'IL', 'IS', 'IT', 'LI', 'LT', 'LU', 'LV', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK', 'TR', 'VA']
18
18
  self.default_currency = 'EUR'
19
19
  self.supported_cardtypes = [:visa, :master, :maestro, :jcb, :american_express]
20
20
 
@@ -162,6 +162,19 @@ module ActiveMerchant #:nodoc:
162
162
  commit('res_update_cc', post)
163
163
  end
164
164
 
165
+ def supports_scrubbing?
166
+ true
167
+ end
168
+
169
+ def scrub(transcript)
170
+ transcript.
171
+ gsub(%r((<store_id>).+(</store_id>)), '\1[FILTERED]\2').
172
+ gsub(%r((<api_token>).+(</api_token>)), '\1[FILTERED]\2').
173
+ gsub(%r((<pan>).+(</pan>)), '\1[FILTERED]\2').
174
+ gsub(%r((<cvd_value>).+(</cvd_value>)), '\1[FILTERED]\2').
175
+ gsub(%r((<cavv>).+(</cavv>)), '\1[FILTERED]\2')
176
+ end
177
+
165
178
  private # :nodoc: all
166
179
 
167
180
  def expdate(creditcard)
@@ -0,0 +1,245 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class NetbanxGateway < Gateway
4
+ # Netbanx is the new REST based API for Optimal Payments / Paysafe
5
+ self.test_url = 'https://api.test.netbanx.com/'
6
+ self.live_url = 'https://api.netbanx.com/'
7
+
8
+ self.supported_countries = ['CA', 'US', 'GB']
9
+ self.default_currency = 'CAD'
10
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
11
+ self.money_format = :cents
12
+
13
+ self.homepage_url = 'https://processing.paysafe.com/'
14
+ self.display_name = 'Netbanx by PaySafe'
15
+
16
+ STANDARD_ERROR_CODE_MAPPING = {}
17
+
18
+ def initialize(options={})
19
+ requires!(options, :account_number, :api_key)
20
+ super
21
+ end
22
+
23
+ def purchase(money, payment, options={})
24
+ post = {}
25
+ add_invoice(post, money, options)
26
+ add_settle_with_auth(post)
27
+ add_payment(post, payment)
28
+
29
+ commit(:post, 'auths', post)
30
+ end
31
+
32
+ def authorize(money, payment, options={})
33
+ post = {}
34
+ add_invoice(post, money, options)
35
+ add_payment(post, payment)
36
+
37
+ commit(:post, 'auths', post)
38
+ end
39
+
40
+ def capture(money, authorization, options={})
41
+ post = {}
42
+ add_invoice(post, money, options)
43
+
44
+ commit(:post, "auths/#{authorization}/settlements", post)
45
+ end
46
+
47
+ def refund(money, authorization, options={})
48
+ post = {}
49
+ add_invoice(post, money, options)
50
+
51
+ commit(:post, "settlements/#{authorization}/refunds", post)
52
+ end
53
+
54
+ def void(authorization, options={})
55
+ post = {}
56
+ add_order_id(post, options)
57
+
58
+ commit(:post, "auths/#{authorization}/voidauths", post)
59
+ end
60
+
61
+ def verify(credit_card, options={})
62
+ post = {}
63
+ add_payment(post, credit_card)
64
+ add_order_id(post, options)
65
+
66
+ commit(:post, 'verifications', post)
67
+ end
68
+
69
+ # note: when passing options[:customer] we only attempt to add the
70
+ # card to the profile_id passed as the options[:customer]
71
+ def store(credit_card, options={})
72
+ # locale can only be one of en_US, fr_CA, en_GB
73
+ requires!(options, :locale)
74
+ post = {}
75
+ add_credit_card(post, credit_card, options)
76
+ add_customer_data(post, options)
77
+
78
+ commit(:post, 'customervault/v1/profiles', post)
79
+ end
80
+
81
+ def unstore(identification, options = {})
82
+ customer_id, card_id = identification.split('|')
83
+
84
+ if card_id.nil?
85
+ # deleting the profile
86
+ commit(:delete, "customervault/v1/profiles/#{CGI.escape(customer_id)}", nil)
87
+ else
88
+ # deleting the card from the profile
89
+ commit(:delete, "customervault/v1/profiles/#{CGI.escape(customer_id)}/cards/#{CGI.escape(card_id)}", nil)
90
+ end
91
+ end
92
+
93
+ def supports_scrubbing?
94
+ true
95
+ end
96
+
97
+ def scrub(transcript)
98
+ transcript.
99
+ gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
100
+ gsub(%r(("card\\?":{\\?"cardNum\\?":\\?")\d+), '\1[FILTERED]').
101
+ gsub(%r(("cvv\\?":\\?")\d+), '\1[FILTERED]')
102
+ end
103
+
104
+ private
105
+
106
+ def add_settle_with_auth(post)
107
+ post[:settleWithAuth] = true
108
+ end
109
+
110
+ def add_customer_data(post, options)
111
+ post[:merchantCustomerId] = (options[:merchant_customer_id] || SecureRandom.uuid)
112
+ post[:locale] = options[:locale]
113
+ # if options[:billing_address]
114
+ # post[:address] = map_address(options[:billing_address])
115
+ # end
116
+ end
117
+
118
+ def add_credit_card(post, credit_card, options = {})
119
+ post[:card] ||= {}
120
+ post[:card][:cardNum] = credit_card.number
121
+ post[:card][:holderName] = credit_card.name
122
+ post[:card][:cvv] = credit_card.verification_value
123
+ post[:card][:cardExpiry] = expdate(credit_card)
124
+ if options[:billing_address]
125
+ post[:card][:billingAddress] = map_address(options[:billing_address])
126
+ end
127
+ end
128
+
129
+ def add_invoice(post, money, options)
130
+ post[:amount] = amount(money)
131
+ post[:currencyCode] = options[:currency] if options[:currency]
132
+ add_order_id(post, options)
133
+
134
+ if options[:billing_address]
135
+ post[:billingDetails] = map_address(options[:billing_address])
136
+ end
137
+
138
+ end
139
+
140
+ def add_payment(post, credit_card_or_reference, options = {})
141
+ post[:card] ||= {}
142
+ if credit_card_or_reference.is_a?(String)
143
+ post[:card][:paymentToken] = credit_card_or_reference
144
+ else
145
+ post[:card][:cardNum] = credit_card_or_reference.number
146
+ post[:card][:cvv] = credit_card_or_reference.verification_value
147
+ post[:card][:cardExpiry] = expdate(credit_card_or_reference)
148
+ end
149
+ end
150
+
151
+ def expdate(credit_card)
152
+ year = format(credit_card.year, :four_digits)
153
+ month = format(credit_card.month, :two_digits)
154
+
155
+ # returns a hash (necessary in the card JSON object)
156
+ { :month => month, :year => year }
157
+ end
158
+
159
+ def add_order_id(post, options)
160
+ post[:merchantRefNum] = (options[:order_id] || SecureRandom.uuid)
161
+ end
162
+
163
+ def map_address(address)
164
+ return {} if address.nil?
165
+ country = Country.find(address[:country]) if address[:country]
166
+ mapped = {
167
+ :street => address[:address1],
168
+ :city => address[:city],
169
+ :zip => address[:zip],
170
+ }
171
+ mapped.merge!({:country => country.code(:alpha2).value}) unless country.blank?
172
+
173
+ mapped
174
+ end
175
+
176
+ def parse(body)
177
+ body.blank? ? {} : JSON.parse(body)
178
+ end
179
+
180
+ def commit(method, uri, parameters)
181
+ params = parameters.to_json unless parameters.nil?
182
+ response = begin
183
+ parse(ssl_request(method, get_url(uri), params, headers))
184
+ rescue ResponseError => e
185
+ return Response.new(false, 'Invalid Login') if(e.response.code == '401')
186
+ parse(e.response.body)
187
+ end
188
+
189
+ success = success_from(response)
190
+ Response.new(
191
+ success,
192
+ message_from(success, response),
193
+ response,
194
+ :test => test?,
195
+ :authorization => authorization_from(success, get_url(uri), method, response)
196
+ )
197
+ end
198
+
199
+ def get_url(uri)
200
+ url = (test? ? test_url : live_url)
201
+ if uri =~ /^customervault/
202
+ "#{url}#{uri}"
203
+ else
204
+ "#{url}cardpayments/v1/accounts/#{@options[:account_number]}/#{uri}"
205
+ end
206
+ end
207
+
208
+ def success_from(response)
209
+ response.blank? || !response.key?('error')
210
+ end
211
+
212
+ def message_from(success, response)
213
+ success ? 'OK' : (response['error']['message'] || "Unknown error - please contact Netbanx-Paysafe")
214
+ end
215
+
216
+ def authorization_from(success, url, method, response)
217
+ if success && response.present? && url.match(/cardpayments\/v1\/accounts\/.*\//)
218
+ response['id']
219
+ elsif method == :post && url.match(/customervault\/.*\//)
220
+ # auth for tokenised customer vault is returned as
221
+ # customer_profile_id|card_id|payment_method_token
222
+ #
223
+ # customer_profile_id is the uuid that identifies the customer
224
+ # card_id is the uuid that identifies the card
225
+ # payment_method_token is the token that needs to be used when
226
+ # calling purchase with a token
227
+ #
228
+ # both id's are used to unstore, the payment token is only used for
229
+ # purchase transactions
230
+ [response['id'], response['cards'].first['id'], response['cards'].first['paymentToken']].join("|")
231
+ end
232
+ end
233
+
234
+ # Builds the auth and U-A headers for the request
235
+ def headers
236
+ {
237
+ 'Accept' => 'application/json',
238
+ 'Content-type' => 'application/json',
239
+ 'Authorization' => "Basic #{Base64.strict_encode64(@options[:api_key].to_s).strip}",
240
+ 'User-Agent' => "Netbanx-Paysafe v1.0/ActiveMerchant #{ActiveMerchant::VERSION}"
241
+ }
242
+ end
243
+ end
244
+ end
245
+ end