solidus_nexio 0.7.10 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/decorators/models/solidus_nexio/payment_decorator.rb +37 -8
- data/app/jobs/solidus_nexio/payment_confirmation_job.rb +9 -0
- data/app/services/solidus_nexio/payment_confirmation_service.rb +38 -0
- data/db/migrate/20230509093147_add_auth_confirmation_required_to_spree_payment.rb +5 -0
- data/lib/solidus_nexio/version.rb +1 -1
- data/lib/solidus_nexio.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b8b26c32f6aadcf7970abe96f50a80c434ab4dbfa8d3fee871b2fca6addb14c
|
4
|
+
data.tar.gz: d43e6cd590a8b93d2920f2e8bebb571823be7bfbd666601559016d5dcb61cad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a32db735b15b242878bdb8a30e1a4c80223bd6ad3ebb82b6ec3be65f4499d66aa39c8cfee285f482136c471d52f2b97750e2304d72127a44cff5e0415f5c6fc
|
7
|
+
data.tar.gz: 99f7045179675543de2420dc5dd6e300eb08942552550754349e49052f2288bcb28d771c76c985d1ffc720077170641fc4c37f12b903f5afa434f0ccb959460e
|
@@ -13,15 +13,36 @@ module SolidusNexio
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def authorize!
|
16
|
-
|
16
|
+
authorize_apm_safely or clean_nexio_after { super }
|
17
17
|
end
|
18
18
|
|
19
19
|
def purchase!
|
20
|
-
fetch_nexio_amp_transaction or clean_nexio_after { super }
|
20
|
+
fetch_nexio_amp_transaction('Purchase') or clean_nexio_after { super }
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_payment_state_from_nexio(action = nil)
|
24
|
+
return unless response_code.present?
|
25
|
+
|
26
|
+
transaction = payment_method.gateway.get_transaction(response_code)
|
27
|
+
unless transaction
|
28
|
+
error_message = "#{action}: The transaction is not found."
|
29
|
+
record_response(build_response(false, error_message))
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
message = "#{action}: The transaction #{transaction.data['id']} is updated."
|
34
|
+
record_response(build_response(true, message, transaction.data))
|
35
|
+
self.state = SolidusNexio::Mappings.payment_state(transaction.status)
|
36
|
+
self.amount = failed? || void? ? 0 : transaction.amount
|
37
|
+
save
|
21
38
|
end
|
22
39
|
|
23
40
|
private
|
24
41
|
|
42
|
+
def build_response(success, message, params = {})
|
43
|
+
ActiveMerchant::Billing::Response.new(success, message, params, test: payment_method.gateway.test?)
|
44
|
+
end
|
45
|
+
|
25
46
|
def save_nexio_amp_id
|
26
47
|
self.response_code = nexio_apm_transaction_id if nexio_apm_transaction_id.present?
|
27
48
|
end
|
@@ -34,14 +55,10 @@ module SolidusNexio
|
|
34
55
|
source.clean_nexio_cvv if nexio_card?
|
35
56
|
end
|
36
57
|
|
37
|
-
def fetch_nexio_amp_transaction
|
58
|
+
def fetch_nexio_amp_transaction(action = nil)
|
38
59
|
return unless response_code.present? && nexio_apm?
|
39
60
|
|
40
|
-
|
41
|
-
if transaction
|
42
|
-
self.amount = transaction.amount
|
43
|
-
self.state = SolidusNexio::Mappings.payment_state(transaction.status)
|
44
|
-
save!
|
61
|
+
if update_payment_state_from_nexio(action)
|
45
62
|
return true if completed? || pending?
|
46
63
|
else
|
47
64
|
invalidate!
|
@@ -50,6 +67,18 @@ module SolidusNexio
|
|
50
67
|
raise Spree::Core::GatewayError, I18n.t('spree.payment_processing_failed')
|
51
68
|
end
|
52
69
|
|
70
|
+
def authorize_apm_safely
|
71
|
+
return unless nexio_apm?
|
72
|
+
|
73
|
+
if update_payment_state_from_nexio('Authorize')
|
74
|
+
return true if completed? || pending?
|
75
|
+
elsif response_code.present?
|
76
|
+
self.auth_confirmation_required = true
|
77
|
+
pend! unless completed? || pending?
|
78
|
+
PaymentConfirmationJob.set(wait: SolidusNexio.config.payment_confirmation_timeout.minutes).perform_later(self)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
53
82
|
Spree::Payment.include self
|
54
83
|
# source set after other attribute assignments
|
55
84
|
Spree::Payment.before_validation :save_nexio_amp_id, on: :create, if: :nexio_apm?
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolidusNexio
|
4
|
+
PaymentConfirmationService = Struct.new(:payment) do
|
5
|
+
class << self
|
6
|
+
def call(payment)
|
7
|
+
return unless payment.nexio_apm? && payment.auth_confirmation_required
|
8
|
+
|
9
|
+
new(payment).confirm_payment_auth!
|
10
|
+
clear_auth_confirmation(payment)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def clear_auth_confirmation(payment)
|
16
|
+
payment.update!(auth_confirmation_required: false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def confirm_payment_auth!
|
21
|
+
return unless auth_confirmed
|
22
|
+
|
23
|
+
invalidate_payment unless update_payment_state_from_nexio('Auth Confirmation') && auth_confirmed
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
delegate :update_payment_state_from_nexio, to: :payment
|
29
|
+
|
30
|
+
def auth_confirmed
|
31
|
+
payment.completed? || payment.pending?
|
32
|
+
end
|
33
|
+
|
34
|
+
def invalidate_payment
|
35
|
+
payment.order&.cancel! or payment.void!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/solidus_nexio.rb
CHANGED
@@ -11,7 +11,7 @@ module SolidusNexio
|
|
11
11
|
'solidus_nexio_solidus_nexio_'
|
12
12
|
end
|
13
13
|
|
14
|
-
@config = OpenStruct.new(merchant_secrets: [], save_webhooks: false, webhooks: [])
|
14
|
+
@config = OpenStruct.new(merchant_secrets: [], save_webhooks: false, webhooks: [], payment_confirmation_timeout: 3)
|
15
15
|
|
16
16
|
def self.config
|
17
17
|
yield @config if block_given?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solidus_nexio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Whitespectre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nexio_activemerchant
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- app/decorators/models/solidus_nexio/credit_card_decorator.rb
|
105
105
|
- app/decorators/models/solidus_nexio/payment_decorator.rb
|
106
106
|
- app/helpers/solidus_nexio/checkout_helper.rb
|
107
|
+
- app/jobs/solidus_nexio/payment_confirmation_job.rb
|
107
108
|
- app/models/solidus_nexio/alternative_payment_method.rb
|
108
109
|
- app/models/solidus_nexio/apm_source.rb
|
109
110
|
- app/models/solidus_nexio/nexio_payment_commons.rb
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- app/services/solidus_nexio/encryption_service.rb
|
113
114
|
- app/services/solidus_nexio/mappings.rb
|
114
115
|
- app/services/solidus_nexio/nexio_data.rb
|
116
|
+
- app/services/solidus_nexio/payment_confirmation_service.rb
|
115
117
|
- app/views/solidus_nexio/payment_states/capture.html.erb
|
116
118
|
- app/views/spree/admin/payments/source_forms/_nexio_apm.html.erb
|
117
119
|
- app/views/spree/admin/payments/source_forms/_nexio_own_form.html.erb
|
@@ -128,6 +130,7 @@ files:
|
|
128
130
|
- config/routes.rb
|
129
131
|
- db/migrate/20210723155452_create_solidus_nexio_solidus_nexio_webhooks.rb
|
130
132
|
- db/migrate/20211109171335_add_solidus_nexio_apm_source.rb
|
133
|
+
- db/migrate/20230509093147_add_auth_confirmation_required_to_spree_payment.rb
|
131
134
|
- lib/solidus_nexio.rb
|
132
135
|
- lib/solidus_nexio/engine.rb
|
133
136
|
- lib/solidus_nexio/version.rb
|