spree_vpago 2.2.0 → 2.2.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/app/controllers/spree/vpago_payments_controller.rb +6 -6
- data/app/controllers/spree/webhook/payways_controller.rb +1 -3
- data/app/jobs/vpago/payment_processor_job.rb +42 -25
- data/app/lib/vpago/timing_helper.rb +7 -0
- data/lib/spree_vpago/version.rb +1 -1
- data/lib/vpago_logger.rb +21 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c798525a2a23d0f61689431f2e4c630a6a947ce683339fa416f38d1a457cc403
|
|
4
|
+
data.tar.gz: 35f0e6cf960e666fcf1a25afe8afc32bf8c91e680dd35e9d5fcf2da3f4e644ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0152b17d28c14ae4204bfafb6f80799fb1118e2354155de84de3f0f1431e61778c085a3ee378f1f55c5f30def318f5e96570d4c756a7e48e6f07616a98461e35
|
|
7
|
+
data.tar.gz: 76b6bd5ab261e6497b89288ded4fac0a9fe28e61116a139db5c67da8a960f26ccea6e1f679f199e9c168ec13cb28d45b166a723a628f7a2c0148fa24d129f629
|
data/Gemfile.lock
CHANGED
|
@@ -102,9 +102,9 @@ module Spree
|
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
def log_enqueue_start(payment, enqueued_at, return_params = {})
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
VpagoLogger.log(
|
|
106
|
+
event: 'vpago.payment_processor_job.enqueue',
|
|
107
|
+
data: {
|
|
108
108
|
payment_number: payment.number,
|
|
109
109
|
order_number: payment.order&.number,
|
|
110
110
|
request_id: request.request_id,
|
|
@@ -118,9 +118,9 @@ module Spree
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
def log_enqueue_error(error)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
VpagoLogger.error(
|
|
122
|
+
event: 'vpago.payment_processor_job.enqueue.error',
|
|
123
|
+
data: {
|
|
124
124
|
request_id: request.request_id,
|
|
125
125
|
payment_number: @payment&.number,
|
|
126
126
|
error_class: error.class.name,
|
|
@@ -6,49 +6,66 @@ module Vpago
|
|
|
6
6
|
queue_as :payment_processing
|
|
7
7
|
|
|
8
8
|
def perform(options)
|
|
9
|
-
started_at =
|
|
10
|
-
|
|
9
|
+
started_at = Vpago::TimingHelper.current_time
|
|
11
10
|
enqueued_at = options[:enqueued_at]
|
|
12
|
-
queue_wait_ms =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
queue_wait_ms = calculate_queue_wait_ms(enqueued_at)
|
|
12
|
+
|
|
13
|
+
log_job_start(options[:payment_number], queue_wait_ms)
|
|
14
|
+
|
|
15
|
+
payment = Spree::Payment.find_by!(number: options[:payment_number])
|
|
16
|
+
Vpago::PaymentProcessor.new(payment: payment).call
|
|
17
|
+
|
|
18
|
+
log_job_finish(options[:payment_number], queue_wait_ms, started_at)
|
|
19
|
+
rescue StandardError => e
|
|
20
|
+
log_job_error(options[:payment_number], queue_wait_ms, started_at, e)
|
|
21
|
+
raise
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def calculate_queue_wait_ms(enqueued_at)
|
|
27
|
+
return nil unless enqueued_at
|
|
28
|
+
|
|
29
|
+
((Time.now.to_f - enqueued_at.to_f) * 1000.0).round(1)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def log_job_start(payment_number, queue_wait_ms)
|
|
33
|
+
VpagoLogger.log(
|
|
34
|
+
event: 'vpago.payment_processor_job.start',
|
|
35
|
+
data: {
|
|
36
|
+
payment_number: payment_number,
|
|
20
37
|
queue: self.class.queue_name,
|
|
21
38
|
queue_wait_ms: queue_wait_ms
|
|
22
39
|
}
|
|
23
40
|
)
|
|
41
|
+
end
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
Vpago::PaymentProcessor.new(payment: payment).call
|
|
27
|
-
|
|
43
|
+
def log_job_finish(payment_number, queue_wait_ms, started_at)
|
|
28
44
|
runtime_ms = Vpago::TimingHelper.elapsed_ms(started_at)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
payment_number:
|
|
45
|
+
VpagoLogger.log(
|
|
46
|
+
event: 'vpago.payment_processor_job.finish',
|
|
47
|
+
data: {
|
|
48
|
+
payment_number: payment_number,
|
|
33
49
|
queue: self.class.queue_name,
|
|
34
50
|
queue_wait_ms: queue_wait_ms,
|
|
35
51
|
runtime_ms: runtime_ms
|
|
36
52
|
}
|
|
37
53
|
)
|
|
38
|
-
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def log_job_error(payment_number, queue_wait_ms, started_at, error)
|
|
39
57
|
runtime_ms = Vpago::TimingHelper.elapsed_ms(started_at)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
payment_number:
|
|
58
|
+
VpagoLogger.error(
|
|
59
|
+
event: 'vpago.payment_processor_job.error',
|
|
60
|
+
data: {
|
|
61
|
+
payment_number: payment_number,
|
|
44
62
|
queue: self.class.queue_name,
|
|
45
63
|
queue_wait_ms: queue_wait_ms,
|
|
46
64
|
runtime_ms: runtime_ms,
|
|
47
|
-
error_class:
|
|
48
|
-
error_message:
|
|
65
|
+
error_class: error.class.name,
|
|
66
|
+
error_message: error.message
|
|
49
67
|
}
|
|
50
68
|
)
|
|
51
|
-
raise
|
|
52
69
|
end
|
|
53
70
|
end
|
|
54
71
|
end
|
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
module Vpago
|
|
2
2
|
module TimingHelper
|
|
3
|
+
# Gets the current monotonic timestamp.
|
|
4
|
+
#
|
|
5
|
+
# @return [Float] current timestamp from Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
6
|
+
def self.current_time
|
|
7
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
8
|
+
end
|
|
9
|
+
|
|
3
10
|
# Measures elapsed time in milliseconds from a given start timestamp.
|
|
4
11
|
#
|
|
5
12
|
# @param started_at [Float] timestamp from Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
data/lib/spree_vpago/version.rb
CHANGED
data/lib/vpago_logger.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module VpagoLogger
|
|
2
|
+
def self.log(event:, data: nil)
|
|
3
|
+
message = { event: event }
|
|
4
|
+
message.merge!(data) if data
|
|
5
|
+
|
|
6
|
+
Rails.logger.info(message.to_json)
|
|
7
|
+
message
|
|
8
|
+
rescue StandardError
|
|
9
|
+
message
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.error(event:, data: nil)
|
|
13
|
+
message = { event: event }
|
|
14
|
+
message.merge!(data) if data
|
|
15
|
+
|
|
16
|
+
Rails.logger.error(message.to_json)
|
|
17
|
+
message
|
|
18
|
+
rescue StandardError
|
|
19
|
+
message
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: spree_vpago
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.2.
|
|
4
|
+
version: 2.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- You
|
|
@@ -419,6 +419,7 @@ files:
|
|
|
419
419
|
- lib/vpago/wing_sdk/payment_retriever.rb
|
|
420
420
|
- lib/vpago/wing_sdk/transaction_status_checker.rb
|
|
421
421
|
- lib/vpago/wing_sdk/transaction_status_response.rb
|
|
422
|
+
- lib/vpago_logger.rb
|
|
422
423
|
- node_modules/.yarn-integrity
|
|
423
424
|
- package-lock.json
|
|
424
425
|
- package.json
|