nexio_activemerchant 0.1.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f44a453d72f2121e52164b85b924aa086d441558aa3f22cc7d2241511010032
4
- data.tar.gz: dc4d091cdfa3c9bb022a8c14174e6cf90f475269064d318fc22c3f7f77bc5b51
3
+ metadata.gz: aa463661c8db5f5568825ac31a6bd4c42d5997bd4df1fef6f7afb92f0d72501a
4
+ data.tar.gz: 33e492999b3bdd59a53d764ef1d4e0ba46d7ada66e16b89a378b2c891139d73c
5
5
  SHA512:
6
- metadata.gz: 1a2ec833d7ccfb02324d692692a748ab6d800119b4fe8601c17df38f8c8bafad80afb07a1531a69155d33785f7361d9ba63535ae2e70e326977a6607eb1be665
7
- data.tar.gz: 5915f09f6038a1861d103e4dcdfdb8b961eb518f4f8dfbacc2139f4607f8d8f963256a2b79f211b0bf127c0d623c3e86adedd06e4c8f385dfbd1c0d2bc0eeda9
6
+ metadata.gz: 9815bde8e3cf49027550eb1bfe25f112ed17e1fb2e557c6ec14ddff479a1ad66ad01c95eef099988d611e106bc770f4c952754bdf570412c1cb496a8366d82b0
7
+ data.tar.gz: ce430b0a30c7608a97a3377a80eff3bf5a67b3116e00066b616213abb7aa2e85d3d6c7009c3f65547a06014cea5ebb3abc9123a0f2a763087f82d68c6ab60a16
@@ -18,8 +18,8 @@ module ActiveMerchant
18
18
 
19
19
  if empty?(brand)
20
20
  errors << [:brand, 'is required'] if own_form
21
- els
22
- errors << [:brand, 'is invalid'] unless self.class.card_companies.include?(brand)
21
+ elsif !self.class.card_companies.include?(brand)
22
+ errors << [:brand, 'is invalid']
23
23
  end
24
24
 
25
25
  errors << [:encrypted_number, 'is required'] if empty?(encrypted_number)
@@ -40,6 +40,9 @@ module ActiveMerchant
40
40
  post = build_payload(options)
41
41
  post[:processingOptions] ||= {}
42
42
  post[:processingOptions][:verboseResponse] = true if test?
43
+ post[:processingOptions][:customerRedirectUrl] = options[:three_d_callback_url] if options.key?(:three_d_callback_url)
44
+ post[:processingOptions][:check3ds] = options[:three_d_secure]
45
+ post[:processingOptions][:paymentType] = options[:payment_type] if options.key?(:payment_type)
43
46
  add_invoice(post, money, options)
44
47
  add_payment(post, payment, options)
45
48
  add_order_data(post, options)
@@ -89,6 +92,31 @@ module ActiveMerchant
89
92
  resp.params.fetch('token', {}).fetch('token', nil)
90
93
  end
91
94
 
95
+ def set_webhooks(data)
96
+ post = { merchantId: options[:merchant_id].to_s }
97
+ if data.is_a?(String)
98
+ post[:webhooks] = {
99
+ TRANSACTION_AUTHORIZED: { url: data },
100
+ TRANSACTION_CAPTURED: { url: data }
101
+ }
102
+ else
103
+ webhooks = {}
104
+ webhooks[:TRANSACTION_AUTHORIZED] = { url: data[:authorized] } if data.key?(:authorized)
105
+ webhooks[:TRANSACTION_CAPTURED] = { url: data[:captured] } if data.key?(:captured)
106
+ post[:webhooks] = webhooks
107
+ end
108
+ commit('webhook', post)
109
+ end
110
+
111
+ def set_secret
112
+ commit('secret', { merchantId: options[:merchant_id].to_s }).params['secret']
113
+ end
114
+
115
+ def get_transaction(id)
116
+ parse(ssl_get(action_url("/transaction/v3/paymentId/#{id}"), base_headers))
117
+ rescue ResponseError => e
118
+ end
119
+
92
120
  private
93
121
 
94
122
  def add_invoice(post, money, options)
@@ -97,7 +125,7 @@ module ActiveMerchant
97
125
  end
98
126
 
99
127
  def add_currency(post, options)
100
- post[:data][:currency] = options[:currency] || currency(money)
128
+ post[:data][:currency] = options[:currency] if options.key?(:currency)
101
129
  end
102
130
 
103
131
  def add_order_data(post, options)
@@ -156,6 +184,12 @@ module ActiveMerchant
156
184
 
157
185
  def add_payment(post, payment, options)
158
186
  post[:tokenex] = token_from(payment)
187
+ if payment.is_a?(Spree::CreditCard)
188
+ post[:card] = {
189
+ cardHolderName: payment.name,
190
+ cardType: payment.brand
191
+ }
192
+ end
159
193
  post[:processingOptions] ||= {}
160
194
  post[:processingOptions][:merchantId] = self.options[:merchant_id].to_s
161
195
  post[:processingOptions][:saveCardToken] = options[:save_credit_card] if options.key?(:save_credit_card)
@@ -166,7 +200,8 @@ module ActiveMerchant
166
200
 
167
201
  {
168
202
  token: payment.gateway_payment_profile_id,
169
- lastFour: payment.last_digits
203
+ lastFour: payment.last_digits,
204
+ cardType: payment.brand
170
205
  }
171
206
  end
172
207
 
@@ -205,11 +240,10 @@ module ActiveMerchant
205
240
  end
206
241
 
207
242
  def commit(action, parameters)
208
- payload = parse(ssl_post(action_url(action, parameters), post_data(action, parameters),
209
- Authorization: "Basic #{options[:auth_token]}"))
243
+ payload = parse(ssl_post(commit_action_url(action, parameters), post_data(action, parameters), base_headers))
210
244
 
211
245
  Response.new(
212
- true,
246
+ response_status(action, payload),
213
247
  nil,
214
248
  payload,
215
249
  authorization: authorization_from(payload),
@@ -229,6 +263,14 @@ module ActiveMerchant
229
263
  )
230
264
  end
231
265
 
266
+ def response_status(action, payload)
267
+ case action
268
+ when 'process' then authorization_from(payload).present?
269
+ else
270
+ true
271
+ end
272
+ end
273
+
232
274
  def authorization_from(payload)
233
275
  payload.fetch('id', nil)
234
276
  end
@@ -237,8 +279,17 @@ module ActiveMerchant
237
279
  parameters.to_json
238
280
  end
239
281
 
240
- def action_url(action, _parameters)
241
- path = "/pay/v3/#{action}"
282
+ def commit_action_url(action, _parameters)
283
+ path = case action
284
+ when 'webhook' then '/webhook/v3/config'
285
+ when 'secret' then '/webhook/v3/secret'
286
+ else
287
+ "/pay/v3/#{action}"
288
+ end
289
+ action_url(path)
290
+ end
291
+
292
+ def action_url(path)
242
293
  "#{test? ? test_url : live_url}#{path}"
243
294
  end
244
295
 
@@ -257,6 +308,10 @@ module ActiveMerchant
257
308
  def build_payload(options)
258
309
  { data: { customer: {} } }.merge!(options.fetch(:payload, {}))
259
310
  end
311
+
312
+ def base_headers(custom = {})
313
+ { Authorization: "Basic #{options[:auth_token]}" }
314
+ end
260
315
  end
261
316
  end
262
317
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'activemerchant'
4
+ require 'active_merchant/billing/rails'
4
5
  require 'active_merchant/billing/encrypted_nexio_card'
5
6
  require 'active_merchant/billing/gateways/nexio'
6
7
  require 'nexio_activemerchant/version'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NexioActivemerchant
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexio_activemerchant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Whitespectre
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-20 00:00:00.000000000 Z
11
+ date: 2021-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant