barion 0.4.0 → 0.5.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: 575b950187d8de272065169bce30d830c4731761b4b25b9d7533e8899b2674dd
4
- data.tar.gz: 4465db2681c4da8f1b8b4b01b6ef34158be8d7bacb02302eae779cd1fcff7985
3
+ metadata.gz: 28e8f48530892a81c10e2b8cc4711acc215a64c1798646863ed2723d133c3818
4
+ data.tar.gz: 8997771b29049b4d42d1f4f6449d54967b7b5fe41e178ead0b17cb4591e32711
5
5
  SHA512:
6
- metadata.gz: ca9acdf451e26ab69a247b8098be1db3f8f43ffada9229a9f5e0378a6db5b8c8afcf720751de5117708d2372eefd3242fbe874d2abaed5c3cf1da7930a2c15b2
7
- data.tar.gz: 5b708506775ecb6ecb647ceeafd1fcd0fb707447f78b77d922c91a1e66c9532d73b373376ec72a34c2db38e2a579166eb8ac1339ada8ee97809044484ad3e829
6
+ metadata.gz: e0e2d5affbdfb951cdedc75f9ca35e39783fb37a6d31dfb3876a98fc3f4fea0bd0da9415f8e21ca37ae503618c679256ae49ee812f77e817b369cb36379449b0
7
+ data.tar.gz: 71a40b6f41f281730d3e4d8a3056dafc216234db833a5155c82536bf11ad4eca66d8fa31e6d4242d005349913a237a4d2c523ff54e60d5254fc4e2043bf89d0f
data/README.md CHANGED
@@ -34,13 +34,13 @@ After installing the gem you have to initalize it.
34
34
  Just create a file in `config/initializers/barion.rb` with the below content:
35
35
 
36
36
  ```ruby
37
- ::Barion.config do |shop|
38
- shop.poskey = ''
39
- shop.publickey = ''
40
- shop.pixel_id = ''
41
- shop.sandbox = true
42
- shop.acronym = ''
43
- shop.default_payee = ''
37
+ ::Barion.config do |conf|
38
+ conf.poskey = ''
39
+ conf.publickey = ''
40
+ conf.pixel_id = ''
41
+ conf.sandbox = true
42
+ conf.acronym = ''
43
+ conf.default_payee = ''
44
44
  end
45
45
  ```
46
46
 
@@ -62,8 +62,6 @@ You have to open the shop Details from the `Action` dropdown of your shop. Pleas
62
62
 
63
63
  Your Barion Pixel ID can be found in the Details page of your Barion shop. Every webshop (with a unique POSKey) has a different Barion Pixel ID. You can find your Barion Pixel ID in your Barion wallet: click `Manage my shops` menu, `Actions` next to your shop and then `Details`.
64
64
 
65
-
66
-
67
65
  #### Sandbox (default: true)
68
66
 
69
67
  It is **highly recommended** to use a Test shop first to tune the code first. That's why `sandbox` is set to **true** by default.
@@ -74,7 +72,7 @@ Acronym is used to generate the `payment_request_id` Barion requires to identify
74
72
 
75
73
  ```ruby
76
74
  def create_payment_request_id
77
- self.payment_request_id = "#{::Barion.acronym}#{::Time.now.to_f.to_s.gsub('.', '')}" if payment_request_id.nil?
75
+ self.payment_request_id = "#{::Barion.config.acronym}#{::Time.now.to_f.to_s.gsub('.', '')}" if payment_request_id.nil?
78
76
  end
79
77
  ```
80
78
 
@@ -16,7 +16,7 @@ module Barion
16
16
  scriptElement.async = true;
17
17
  scriptElement.src = 'https://pixel.barion.com/bp.js';
18
18
  firstScript.parentNode.insertBefore(scriptElement, firstScript);
19
- window['barion_pixel_id'] = '#{::Barion.pixel_id}';
19
+ window['barion_pixel_id'] = '#{::Barion.config.pixel_id}';
20
20
  // Send init event
21
21
  bp('init', 'addBarionPixelId', window['barion_pixel_id']);'
22
22
  ).gsub!(/^#{[/\A\s*/]}/, '')
@@ -27,7 +27,7 @@ module Barion
27
27
  tag.img height: 1, width: 1,
28
28
  style: 'display:none',
29
29
  alt: 'Barion Pixel',
30
- src: "https://pixel.barion.com/a.gif?ba_pixel_id='#{::Barion.pixel_id}'&ev=contentView&noscript=1"
30
+ src: "https://pixel.barion.com/a.gif?ba_pixel_id='#{::Barion.config.pixel_id}'&ev=contentView&noscript=1"
31
31
  end
32
32
  end
33
33
 
@@ -167,7 +167,7 @@ module Barion
167
167
  before_validation :refresh_checksum
168
168
 
169
169
  def poskey=(value = nil)
170
- value = ::Barion.poskey if value.nil?
170
+ value = ::Barion.config.poskey if value.nil?
171
171
  super(value)
172
172
  end
173
173
 
@@ -210,7 +210,7 @@ module Barion
210
210
 
211
211
  def execute
212
212
  if valid?
213
- ::Barion.endpoint['v2/Payment/Start'].post(
213
+ ::Barion.config.endpoint['v2/Payment/Start'].post(
214
214
  as_json.to_json,
215
215
  { content_type: :json, accept: :json }
216
216
  ) { |response, request, _result| handle_response(response, request) }
@@ -220,7 +220,7 @@ module Barion
220
220
  end
221
221
 
222
222
  def refresh_state
223
- ::Barion.endpoint['v2/Payment/GetPaymentState'].get(
223
+ ::Barion.config.endpoint['v2/Payment/GetPaymentState'].get(
224
224
  {
225
225
  params: {
226
226
  POSKey: poskey,
@@ -316,13 +316,16 @@ module Barion
316
316
  end
317
317
 
318
318
  def set_defaults
319
- self.poskey = ::Barion.poskey if poskey.nil?
319
+ self.poskey = ::Barion.config.poskey if poskey.nil?
320
320
  self.callback_url = ::Barion::Engine.routes.url_helpers.gateway_callback_url
321
321
  self.redirect_url = ::Barion::Engine.routes.url_helpers.gateway_back_url
322
322
  end
323
323
 
324
324
  def create_payment_request_id
325
- self.payment_request_id = "#{::Barion.acronym}#{::Time.now.to_f.to_s.gsub('.', '')}" if payment_request_id.nil?
325
+ return unless payment_request_id.nil?
326
+
327
+ self.payment_request_id = "#{::Barion.config.acronym}#{::Time.now.to_f.to_s.gsub('.',
328
+ '')}"
326
329
  end
327
330
 
328
331
  def gen_checksum
@@ -80,7 +80,7 @@ module Barion
80
80
 
81
81
  def set_defaults
82
82
  self.currency = payment&.currency if currency.nil?
83
- self.payee = ::Barion.default_payee if payee.nil?
83
+ self.payee = ::Barion.config.default_payee if payee.nil?
84
84
  end
85
85
 
86
86
  def total=(value)
@@ -0,0 +1,105 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ module Barion
6
+ # Encloses all Barion related configuration
7
+ class Config
8
+ include Singleton
9
+
10
+ attr_accessor :publickey, :default_payee
11
+ attr_writer :acronym
12
+ attr_reader :pixel_id
13
+
14
+ def poskey
15
+ @_poskey || nil
16
+ end
17
+
18
+ def acronym
19
+ @acronym || ''
20
+ end
21
+
22
+ def poskey=(key)
23
+ unless key.is_a?(String)
24
+ raise ArgumentError,
25
+ "::Barion::Config.poskey must be set to a ::String, got #{key.inspect}"
26
+ end
27
+
28
+ @_poskey = key
29
+ end
30
+
31
+ def sandbox
32
+ sandbox?
33
+ end
34
+
35
+ def sandbox?
36
+ @_sandbox = true if @_sandbox.nil?
37
+ @_sandbox
38
+ end
39
+
40
+ def sandbox=(val)
41
+ @_sandbox = !!val
42
+ end
43
+
44
+ def pixel_id=(id)
45
+ unless id.is_a?(String)
46
+ raise ArgumentError,
47
+ "::Barion::Config.pixel_id must be set to a ::String, got #{id.inspect}"
48
+ end
49
+
50
+ if PIXELID_PATTERN.match(id).nil?
51
+ raise ::ArgumentError,
52
+ "String:'#{id}' is not in Barion Pixel ID format: 'BP-0000000000-00'"
53
+ end
54
+
55
+ @pixel_id = id
56
+ end
57
+
58
+ def endpoint
59
+ env = sandbox? ? :test : :prod
60
+ rest_client_class.new ::Barion::BASE_URL[env]
61
+ end
62
+
63
+ def user_class=(class_name)
64
+ unless class_name.is_a?(String)
65
+ raise ArgumentError, "::Barion:.config.user_class must be set to a ::String, got #{class_name.inspect}"
66
+ end
67
+
68
+ @_user_class = class_name
69
+ end
70
+
71
+ def user_class
72
+ # This is nil before the initializer is installed.
73
+ return nil if @_user_class.nil?
74
+
75
+ @_user_class.constantize
76
+ end
77
+
78
+ def item_class=(class_name)
79
+ unless class_name.is_a?(String)
80
+ raise ArgumentError, "::Barion.config.item_class must be set to a ::String, got #{class_name.inspect}"
81
+ end
82
+
83
+ @_item_class = class_name
84
+ end
85
+
86
+ def item_class
87
+ # This is nil before the initializer is installed.
88
+ return nil if @_item_class.nil?
89
+
90
+ @_item_class.constantize
91
+ end
92
+
93
+ def rest_client_class
94
+ (@_rest_client_class || '::RestClient::Resource').constantize
95
+ end
96
+
97
+ def rest_client_class=(class_name)
98
+ unless class_name.is_a?(String)
99
+ raise ArgumentError, "::Barion::Config.rest_client_class must be set to a ::String, got #{class_name.inspect}"
100
+ end
101
+
102
+ @_rest_client_class = class_name
103
+ end
104
+ end
105
+ end
data/lib/barion/engine.rb CHANGED
@@ -18,4 +18,8 @@ module Barion
18
18
  # so we can call .include
19
19
  include ::Barion::PixelHelper
20
20
  end
21
+
22
+ def self.deprecator
23
+ @deprecator ||= ActiveSupport::Deprecation.new('1.0', 'Barion')
24
+ end
21
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Barion
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
data/lib/barion.rb CHANGED
@@ -1,99 +1,177 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'barion/engine' if defined?(Rails::Engine)
4
+ require 'barion/config'
4
5
 
5
6
  # Main module of Barion engine
7
+ # rubocop:disable Metrics/ModuleLength
6
8
  module Barion
7
9
  BASE_URL = {
8
10
  test: 'https://api.test.barion.com',
9
11
  prod: 'https://api.barion.com'
10
12
  }.freeze
11
13
 
12
- PIXELID_PATTERN = ::Regexp.new('BP-\d{10}-\d{2}').freeze
14
+ PIXELID_PATTERN = ::Regexp.new('BP-.{10}-\d{2}').freeze
13
15
 
14
- # rubocop:disable Style/ClassVars
15
- mattr_accessor :poskey, default: nil
16
- mattr_accessor :publickey, default: nil
17
- mattr_accessor :acronym, default: ''
18
- mattr_accessor :pixel_id, default: ''
19
- mattr_accessor :sandbox, default: true
20
- mattr_accessor :default_payee
21
- mattr_accessor :user_class
22
- mattr_accessor :item_class
23
- mattr_accessor :rest_client_class, default: '::RestClient::Resource'
16
+ def self.deprecator
17
+ @deprecator ||= ActiveSupport::Deprecation.new('1.0', 'Barion')
18
+ end
19
+
20
+ def self.config
21
+ ::Barion::Config.instance
22
+ end
24
23
 
25
- def self.poskey=(key)
26
- raise ArgumentError, "::Barion.poskey must be set to a String, got #{key.inspect}" unless key.is_a?(String)
24
+ def self.sandbox
25
+ config.sandbox
26
+ deprecator.warn(
27
+ "#{__method__} is deprecated. " \
28
+ "Use ::Barion.config.#{__method__} instead."
29
+ )
30
+ end
27
31
 
28
- @@poskey = key
32
+ def self.sandbox=(val)
33
+ config.sandbox = val
34
+ deprecator.warn(
35
+ "#{__method__} is deprecated. " \
36
+ "Use ::Barion.config.#{__method__} instead."
37
+ )
29
38
  end
30
39
 
31
40
  def self.sandbox?
32
- sandbox
41
+ config.sandbox?
42
+ deprecator.warn(
43
+ "#{__method__} is deprecated. " \
44
+ "Use ::Barion.config.#{__method__} instead."
45
+ )
33
46
  end
34
47
 
35
- def self.sandbox=(val)
36
- @@sandbox = !!val
48
+ def self.poskey
49
+ config.poskey
50
+ deprecator.warn(
51
+ "#{__method__} is deprecated. " \
52
+ "Use ::Barion.config.#{__method__} instead."
53
+ )
37
54
  end
38
55
 
39
- def self.pixel_id=(id)
40
- raise ArgumentError, "::Barion.pixel_id must be set to a String, got #{id.inspect}" unless id.is_a?(String)
56
+ def self.poskey=(val)
57
+ config.poskey = (val)
58
+ deprecator.warn(
59
+ "#{__method__} is deprecated. " \
60
+ "Use ::Barion.config.#{__method__} instead."
61
+ )
62
+ end
41
63
 
42
- if PIXELID_PATTERN.match(id).nil?
43
- raise ::ArgumentError,
44
- "String:'#{id}' is not in Barion Pixel ID format: 'BP-0000000000-00'"
45
- end
64
+ def self.publickey
65
+ config.publickey
66
+ deprecator.warn(
67
+ "#{__method__} is deprecated. " \
68
+ "Use ::Barion.config.#{__method__} instead."
69
+ )
70
+ end
46
71
 
47
- @@pixel_id = id
72
+ def self.publickey=(val)
73
+ config.publickey = (val)
74
+ deprecator.warn(
75
+ "#{__method__} is deprecated. " \
76
+ "Use ::Barion.config.#{__method__} instead."
77
+ )
48
78
  end
49
79
 
50
- def self.endpoint
51
- env = sandbox? ? :test : :prod
52
- rest_client_class.new BASE_URL[env]
80
+ def self.acronym
81
+ config.acronym
82
+ deprecator.warn(
83
+ "#{__method__} is deprecated. " \
84
+ "Use ::Barion.config.#{__method__} instead."
85
+ )
53
86
  end
54
87
 
55
- def self.user_class=(class_name)
56
- unless class_name.is_a?(String)
57
- raise ArgumentError, "Barion.user_class must be set to a String, got #{class_name.inspect}"
58
- end
88
+ def self.acronym=(val)
89
+ config.acronym = val
90
+ deprecator.warn(
91
+ "#{__method__} is deprecated. " \
92
+ "Use ::Barion.config.#{__method__} instead."
93
+ )
94
+ end
59
95
 
60
- @@user_class = class_name
96
+ def self.pixel_id
97
+ config.pixel_id
98
+ deprecator.warn(
99
+ "#{__method__} is deprecated. " \
100
+ "Use ::Barion.config.#{__method__} instead."
101
+ )
61
102
  end
62
103
 
63
- def self.user_class
64
- # This is nil before the initializer is installed.
65
- return nil if @@user_class.nil?
104
+ def self.pixel_id=(val)
105
+ config.pixel_id = val
106
+ deprecator.warn(
107
+ "#{__method__} is deprecated. " \
108
+ "Use ::Barion.config.#{__method__} instead."
109
+ )
110
+ end
66
111
 
67
- @@user_class.constantize
112
+ def self.default_payee
113
+ config.default_payee
114
+ deprecator.warn(
115
+ "#{__method__} is deprecated. " \
116
+ "Use ::Barion.config.#{__method__} instead."
117
+ )
68
118
  end
69
119
 
70
- def self.item_class=(class_name)
71
- unless class_name.is_a?(String)
72
- raise ArgumentError, "Barion.item_class must be set to a String, got #{class_name.inspect}"
73
- end
120
+ def self.default_payee=(val)
121
+ config.default_payee = val
122
+ deprecator.warn(
123
+ "#{__method__} is deprecated. " \
124
+ "Use ::Barion.config.#{__method__} instead."
125
+ )
126
+ end
127
+
128
+ def self.user_class
129
+ config.user_class
130
+ deprecator.warn(
131
+ "#{__method__} is deprecated. " \
132
+ "Use ::Barion.config.#{__method__} instead."
133
+ )
134
+ end
74
135
 
75
- @@item_class = class_name
136
+ def self.user_class=(val)
137
+ config.user_class = val
138
+ deprecator.warn(
139
+ "#{__method__} is deprecated. " \
140
+ "Use ::Barion.config.#{__method__} instead."
141
+ )
76
142
  end
77
143
 
78
144
  def self.item_class
79
- # This is nil before the initializer is installed.
80
- return nil if @@item_class.nil?
145
+ config.item_class
146
+ deprecator.warn(
147
+ "#{__method__} is deprecated. " \
148
+ "Use ::Barion.config.#{__method__} instead."
149
+ )
150
+ end
81
151
 
82
- @@item_class.constantize
152
+ def self.item_class=(val)
153
+ config.item_class = val
154
+ deprecator.warn(
155
+ "#{__method__} is deprecated. " \
156
+ "Use ::Barion.config.#{__method__} instead."
157
+ )
83
158
  end
84
159
 
85
160
  def self.rest_client_class
86
- @@rest_client_class.constantize
161
+ config.rest_client_class
162
+ deprecator.warn(
163
+ "#{__method__} is deprecated. " \
164
+ "Use ::Barion.config.#{__method__} instead."
165
+ )
87
166
  end
88
167
 
89
- def self.rest_client_class=(class_name)
90
- unless class_name.is_a?(String)
91
- raise ArgumentError, "Barion.rest_client_class must be set to a String, got #{class_name.inspect}"
92
- end
93
-
94
- @@rest_client_class = class_name
168
+ def self.rest_client_class=(val)
169
+ config.rest_client_class = val
170
+ deprecator.warn(
171
+ "#{__method__} is deprecated. " \
172
+ "Use ::Barion.config.#{__method__} instead."
173
+ )
95
174
  end
96
- # rubocop:enable Style/ClassVars
97
175
 
98
176
  # Error to signal the data in the db has been changed since saving it
99
177
  class TamperedData < RuntimeError
@@ -118,3 +196,4 @@ module Barion
118
196
  end
119
197
  end
120
198
  end
199
+ # rubocop:enable Metrics/ModuleLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Péter Nagy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-22 00:00:00.000000000 Z
11
+ date: 2024-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,6 +79,7 @@ files:
79
79
  - db/migrate/20210128220347_create_barion_items.rb
80
80
  - db/migrate/20210201120609_create_barion_gift_card_purchases.rb
81
81
  - lib/barion.rb
82
+ - lib/barion/config.rb
82
83
  - lib/barion/engine.rb
83
84
  - lib/barion/version.rb
84
85
  - lib/tasks/auto_annotate_models.rake