nexio_activemerchant 0.1.1 → 0.2.0

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: b04b87b2ac1b4c597f9317e421d181f22e5664d9086d1d4e257c65ab9dfb7a14
4
+ data.tar.gz: 62d6982b454d32c4416127656b7505c8ab3b3395e93af51d584c7dfbeb0fae58
5
5
  SHA512:
6
- metadata.gz: 1a2ec833d7ccfb02324d692692a748ab6d800119b4fe8601c17df38f8c8bafad80afb07a1531a69155d33785f7361d9ba63535ae2e70e326977a6607eb1be665
7
- data.tar.gz: 5915f09f6038a1861d103e4dcdfdb8b961eb518f4f8dfbacc2139f4607f8d8f963256a2b79f211b0bf127c0d623c3e86adedd06e4c8f385dfbd1c0d2bc0eeda9
6
+ metadata.gz: b2fd9ba7715e2e9bed79bf6a3632ac483f7cb415b1854057137fa2d1f92c2fc9bd87b272af1d03df44eee8950b0c75e6e646527d256367eafe14aa3bdb67f0e9
7
+ data.tar.gz: 8f51de8cba7f9acb2cb489c07363246e1e5abcc1a57e71dfd559e81dcc2e6b1c9d84c7e28fe96a4baa9c1a3c36163b4bec4d1c5051f3b65a378af36f41526337
@@ -40,6 +40,8 @@ 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]
43
45
  add_invoice(post, money, options)
44
46
  add_payment(post, payment, options)
45
47
  add_order_data(post, options)
@@ -89,6 +91,26 @@ module ActiveMerchant
89
91
  resp.params.fetch('token', {}).fetch('token', nil)
90
92
  end
91
93
 
94
+ def set_webhooks(data)
95
+ post = { merchantId: options[:merchant_id].to_s }
96
+ if data.is_a?(String)
97
+ post[:webhooks] = {
98
+ TRANSACTION_AUTHORIZED: { url: data },
99
+ TRANSACTION_CAPTURED: { url: data }
100
+ }
101
+ else
102
+ webhooks = {}
103
+ webhooks[:TRANSACTION_AUTHORIZED] = { url: data[:authorized] } if data.key?(:authorized)
104
+ webhooks[:TRANSACTION_CAPTURED] = { url: data[:captured] } if data.key?(:captured)
105
+ post[:webhooks] = webhooks
106
+ end
107
+ commit('webhook', post)
108
+ end
109
+
110
+ def set_secret
111
+ commit('secret', { merchantId: options[:merchant_id].to_s }).params['secret']
112
+ end
113
+
92
114
  private
93
115
 
94
116
  def add_invoice(post, money, options)
@@ -156,6 +178,12 @@ module ActiveMerchant
156
178
 
157
179
  def add_payment(post, payment, options)
158
180
  post[:tokenex] = token_from(payment)
181
+ if payment.is_a?(Spree::CreditCard)
182
+ post[:card] = {
183
+ cardHolderName: payment.name,
184
+ cardType: payment.brand
185
+ }
186
+ end
159
187
  post[:processingOptions] ||= {}
160
188
  post[:processingOptions][:merchantId] = self.options[:merchant_id].to_s
161
189
  post[:processingOptions][:saveCardToken] = options[:save_credit_card] if options.key?(:save_credit_card)
@@ -166,7 +194,8 @@ module ActiveMerchant
166
194
 
167
195
  {
168
196
  token: payment.gateway_payment_profile_id,
169
- lastFour: payment.last_digits
197
+ lastFour: payment.last_digits,
198
+ cardType: payment.brand
170
199
  }
171
200
  end
172
201
 
@@ -205,11 +234,11 @@ module ActiveMerchant
205
234
  end
206
235
 
207
236
  def commit(action, parameters)
208
- payload = parse(ssl_post(action_url(action, parameters), post_data(action, parameters),
209
- Authorization: "Basic #{options[:auth_token]}"))
237
+ payload = parse(ssl_post(commit_action_url(action, parameters), post_data(action, parameters),
238
+ Authorization: "Basic #{options[:auth_token]}"))
210
239
 
211
240
  Response.new(
212
- true,
241
+ response_status(action, payload),
213
242
  nil,
214
243
  payload,
215
244
  authorization: authorization_from(payload),
@@ -229,6 +258,14 @@ module ActiveMerchant
229
258
  )
230
259
  end
231
260
 
261
+ def response_status(action, payload)
262
+ case action
263
+ when 'process' then authorization_from(payload).present?
264
+ else
265
+ true
266
+ end
267
+ end
268
+
232
269
  def authorization_from(payload)
233
270
  payload.fetch('id', nil)
234
271
  end
@@ -237,8 +274,13 @@ module ActiveMerchant
237
274
  parameters.to_json
238
275
  end
239
276
 
240
- def action_url(action, _parameters)
241
- path = "/pay/v3/#{action}"
277
+ def commit_action_url(action, _parameters)
278
+ path = case action
279
+ when 'webhook' then '/webhook/v3/config'
280
+ when 'secret' then '/webhook/v3/secret'
281
+ else
282
+ "/pay/v3/#{action}"
283
+ end
242
284
  "#{test? ? test_url : live_url}#{path}"
243
285
  end
244
286
 
@@ -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.0'
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.0
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-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemerchant