barion 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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +158 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/config/barion_manifest.js +1 -0
  6. data/app/assets/stylesheets/barion/application.css +15 -0
  7. data/app/assets/stylesheets/barion/main.css +4 -0
  8. data/app/controllers/barion/application_controller.rb +7 -0
  9. data/app/controllers/barion/main_controller.rb +28 -0
  10. data/app/helpers/barion/application_helper.rb +7 -0
  11. data/app/helpers/barion/main_helper.rb +7 -0
  12. data/app/models/barion/address.rb +60 -0
  13. data/app/models/barion/application_record.rb +10 -0
  14. data/app/models/barion/gift_card_purchase.rb +66 -0
  15. data/app/models/barion/item.rb +88 -0
  16. data/app/models/barion/payer_account.rb +119 -0
  17. data/app/models/barion/payment.rb +348 -0
  18. data/app/models/barion/payment_transaction.rb +134 -0
  19. data/app/models/barion/purchase.rb +107 -0
  20. data/app/models/concerns/barion/currencies.rb +11 -0
  21. data/app/models/concerns/barion/data_formats.rb +12 -0
  22. data/app/models/concerns/barion/json_serializer.rb +106 -0
  23. data/app/views/barion/main/land.html.erb +7 -0
  24. data/config/initializers/barion.rb +9 -0
  25. data/config/routes.rb +10 -0
  26. data/db/migrate/20201222235354_create_barion_payments.rb +59 -0
  27. data/db/migrate/20201223001557_create_barion_addresses.rb +21 -0
  28. data/db/migrate/20201223002427_create_barion_payment_transactions.rb +28 -0
  29. data/db/migrate/20201223003219_create_barion_purchases.rb +24 -0
  30. data/db/migrate/20210111051233_create_barion_payer_accounts.rb +28 -0
  31. data/db/migrate/20210128220347_create_barion_items.rb +21 -0
  32. data/db/migrate/20210201120609_create_barion_gift_card_purchases.rb +14 -0
  33. data/lib/barion.rb +100 -0
  34. data/lib/barion/engine.rb +14 -0
  35. data/lib/barion/version.rb +5 -0
  36. data/lib/tasks/auto_annotate_models.rake +59 -0
  37. data/lib/tasks/barion_tasks.rake +4 -0
  38. metadata +207 -0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates Barion::Address record persistency
4
+ class CreateBarionAddresses < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :barion_addresses do |t|
7
+ t.string :country, limit: 2, default: 'zz', null: false, index: true
8
+ t.string :zip, limit: 16, index: true
9
+ t.string :city, limit: 50, index: true
10
+ t.string :region, limit: 2
11
+ t.string :street, limit: 50
12
+ t.string :street2, limit: 50
13
+ t.string :street3, limit: 50
14
+ t.string :full_name, limit: 45
15
+ t.belongs_to :payment
16
+
17
+ t.timestamps
18
+ end
19
+ add_index :barion_addresses, :full_name
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates Barion::Transaction record persistency
4
+ class CreateBarionPaymentTransactions < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :barion_payment_transactions do |t|
7
+ t.string :pos_transaction_id, null: false, index: true
8
+ t.string :payee, null: false, index: true
9
+ t.decimal :total, null: false
10
+ t.string :comment
11
+ t.references :payee_transactions,
12
+ references: :barion_payment_transactions,
13
+ foreign_key: { to_table: :barion_payment_transactions }
14
+ t.references :payment,
15
+ references: :barion_payments,
16
+ foreign_key: { to_table: :barion_payments }
17
+ t.integer :status, default: 0, null: false, index: true
18
+ t.string :transaction_id, index: true
19
+ t.string :currency, limit: 3
20
+ t.timestamp :transaction_time
21
+ t.string :payer
22
+ t.integer :transaction_type
23
+ t.string :related_id
24
+
25
+ t.timestamps
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates Barion:Purchase record persistency layer
4
+ class CreateBarionPurchases < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :barion_purchases do |t|
7
+ t.integer :delivery_timeframe
8
+ t.string :delivery_email_address
9
+ t.datetime :pre_order_date
10
+ t.integer :availability_indicator
11
+ t.integer :re_order_indicator
12
+ t.integer :shipping_address_indicator
13
+ t.datetime :recurring_expiry
14
+ t.integer :recurring_frequency, limit: 4
15
+ t.integer :purchase_type
16
+ t.datetime :purchase_date
17
+ t.belongs_to :payment
18
+
19
+ t.timestamps
20
+ end
21
+ add_index :barion_purchases, :delivery_timeframe
22
+ add_index :barion_purchases, :delivery_email_address
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates Barion::PayerAccount record persistency
4
+ class CreateBarionPayerAccounts < ActiveRecord::Migration[6.0]
5
+ def change
6
+ create_table :barion_payer_accounts do |t|
7
+ t.string :account_id, limit: 64, null: true, index: true
8
+ t.datetime :account_created, null: true
9
+ t.integer :account_creation_indicator, limit: 3, null: true
10
+ t.datetime :account_last_changed, null: true
11
+ t.integer :account_change_indicator, limit: 3, null: true
12
+ t.datetime :password_last_changed, null: true
13
+ t.integer :password_change_indicator, limit: 3, null: true
14
+ t.integer :purchases_in_the_last_6_months, null: true
15
+ t.datetime :shipping_address_added, null: true
16
+ t.integer :shipping_address_usage_indicator, limit: 3, null: true
17
+ t.integer :provision_attempts, null: true
18
+ t.integer :transactional_activity_per_day, null: true
19
+ t.integer :transactional_activity_per_year, null: true
20
+ t.datetime :payment_method_added, null: true
21
+ t.integer :suspicious_activity_indicator, limit: 1, null: true, default: 0
22
+
23
+ t.references :payment
24
+
25
+ t.timestamps
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Creates Barion::Item record persistency
4
+ class CreateBarionItems < ActiveRecord::Migration[6.1]
5
+ def change
6
+ create_table :barion_items do |t|
7
+ t.string :name, limit: 250, null: false
8
+ t.string :description, limit: 500, null: false
9
+ t.string :image_url
10
+ t.decimal :quantity, null: false
11
+ t.string :unit, limit: 50, null: false
12
+ t.decimal :unit_price, null: false
13
+ t.decimal :item_total, null: false
14
+ t.string :sku, limit: 100
15
+
16
+ t.references :payment_transaction,
17
+ references: :barion_payment_transactions,
18
+ foreign_key: { to_table: :barion_payment_transactions }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Create Barion::GiftCardPurchase record persistency
4
+ class CreateBarionGiftCardPurchases < ActiveRecord::Migration[6.1]
5
+ def change
6
+ create_table :barion_gift_card_purchases do |t|
7
+ t.decimal :amount, null: false
8
+ t.integer :count, null: false
9
+ t.belongs_to :purchase
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
data/lib/barion.rb ADDED
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'barion/engine'
4
+
5
+ # Main module of Barion engine
6
+ module Barion
7
+ BASE_URL = {
8
+ test: 'https://api.test.barion.com',
9
+ prod: 'https://api.barion.com'
10
+ }.freeze
11
+
12
+ mattr_accessor :poskey, default: nil
13
+ mattr_accessor :publickey, default: nil
14
+ mattr_accessor :acronym, default: ''
15
+ mattr_accessor :sandbox, default: true
16
+ mattr_accessor :default_payee
17
+ mattr_accessor :user_class
18
+ mattr_accessor :item_class
19
+ mattr_accessor :rest_client_class, default: '::RestClient::Resource'
20
+
21
+ def self.sandbox?
22
+ !!sandbox
23
+ end
24
+
25
+ def sandbox=(val)
26
+ super(!!val)
27
+ end
28
+
29
+ def self.endpoint
30
+ env = sandbox? ? :test : :prod
31
+ rest_client_class.new BASE_URL[env]
32
+ end
33
+
34
+ # rubocop:disable Style/ClassVars
35
+ def self.user_class=(class_name)
36
+ unless class_name.is_a?(String)
37
+ raise ArgumentError, "Barion.user_class must be set to a String, got #{class_name.inspect}"
38
+ end
39
+
40
+ @@user_class = class_name
41
+ end
42
+
43
+ def self.user_class
44
+ # This is nil before the initializer is installed.
45
+ return nil if @@user_class.nil?
46
+
47
+ @@user_class.constantize
48
+ end
49
+
50
+ def self.item_class=(class_name)
51
+ unless class_name.is_a?(String)
52
+ raise ArgumentError, "Barion.item_class must be set to a String, got #{class_name.inspect}"
53
+ end
54
+
55
+ @@item_class = class_name
56
+ end
57
+
58
+ def self.item_class
59
+ # This is nil before the initializer is installed.
60
+ return nil if @@item_class.nil?
61
+
62
+ @@item_class.constantize
63
+ end
64
+
65
+ def self.rest_client_class
66
+ @@rest_client_class.constantize
67
+ end
68
+
69
+ def self.rest_client_class=(class_name)
70
+ unless class_name.is_a?(String)
71
+ raise ArgumentError, "Barion.rest_client_class must be set to a String, got #{class_name.inspect}"
72
+ end
73
+
74
+ @@rest_client_class = class_name
75
+ end
76
+ # rubocop:enable Style/ClassVars
77
+
78
+ # Error to signal the data in the db has been changed since saving it
79
+ class TamperedData < RuntimeError
80
+ end
81
+
82
+ # Generic error class for Barion module
83
+ class Error < StandardError
84
+ attr_reader :title, :error_code, :happened_at, :auth_data, :endpoint, :errors
85
+
86
+ def initialize(params)
87
+ @title = params[:Title]
88
+ @error_code = params[:ErrorCode]
89
+ @happened_at = params[:HappenedAt]
90
+ @auth_data = params[:AuthData]
91
+ @endpoint = params[:Endpoint]
92
+ @errors = Array(params[:Errors]).map { |e| Barion::Error.new(e) } if params.key? :Errors
93
+ super(params[:Description])
94
+ end
95
+
96
+ def all_errors
97
+ Array(@errors).map(&:message).join("\n")
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Barion
4
+ # Barion engine main class
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Barion
7
+ engine_name 'barion'
8
+
9
+ config.generators do |g|
10
+ g.fixture_replacement :factory_bot
11
+ g.factory_bot dir: 'test/factories'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Barion
4
+ VERSION = '0.2.0'
5
+ end
@@ -0,0 +1,59 @@
1
+ # NOTE: only doing this in development as some production environments (Heroku)
2
+ # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
+ # NOTE: to have a dev-mode tool do its thing in production.
4
+ if Rails.env.development?
5
+ require 'annotate'
6
+ task :set_annotation_options do
7
+ # You can override any of these by setting an environment variable of the
8
+ # same name.
9
+ Annotate.set_defaults(
10
+ 'active_admin' => 'false',
11
+ 'additional_file_patterns' => [],
12
+ 'routes' => 'false',
13
+ 'models' => 'true',
14
+ 'position_in_routes' => 'before',
15
+ 'position_in_class' => 'before',
16
+ 'position_in_test' => 'before',
17
+ 'position_in_fixture' => 'before',
18
+ 'position_in_factory' => 'before',
19
+ 'position_in_serializer' => 'before',
20
+ 'show_foreign_keys' => 'true',
21
+ 'show_complete_foreign_keys' => 'false',
22
+ 'show_indexes' => 'true',
23
+ 'simple_indexes' => 'false',
24
+ 'model_dir' => 'app/models',
25
+ 'root_dir' => '',
26
+ 'include_version' => 'false',
27
+ 'require' => '',
28
+ 'exclude_tests' => 'false',
29
+ 'exclude_fixtures' => 'false',
30
+ 'exclude_factories' => 'false',
31
+ 'exclude_serializers' => 'false',
32
+ 'exclude_scaffolds' => 'true',
33
+ 'exclude_controllers' => 'true',
34
+ 'exclude_helpers' => 'true',
35
+ 'exclude_sti_subclasses' => 'false',
36
+ 'ignore_model_sub_dir' => 'false',
37
+ 'ignore_columns' => nil,
38
+ 'ignore_routes' => nil,
39
+ 'ignore_unknown_models' => 'false',
40
+ 'hide_limit_column_types' => 'integer,bigint,boolean',
41
+ 'hide_default_column_types' => 'json,jsonb,hstore',
42
+ 'skip_on_db_migrate' => 'false',
43
+ 'format_bare' => 'true',
44
+ 'format_rdoc' => 'false',
45
+ 'format_yard' => 'false',
46
+ 'format_markdown' => 'false',
47
+ 'sort' => 'false',
48
+ 'force' => 'false',
49
+ 'frozen' => 'false',
50
+ 'classified_sort' => 'true',
51
+ 'trace' => 'false',
52
+ 'wrapper_open' => nil,
53
+ 'wrapper_close' => nil,
54
+ 'with_comment' => 'true'
55
+ )
56
+ end
57
+
58
+ Annotate.load_tasks
59
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :barion do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Péter Nagy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '13.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '13.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '6.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '6.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.12'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.12'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ description: |2
140
+ Barion Payment Zrt. established in 2015 serve customers across the EEA.
141
+ See https://barion.com for details.
142
+ email:
143
+ - peter@nagy.consulting
144
+ executables: []
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - MIT-LICENSE
149
+ - README.md
150
+ - Rakefile
151
+ - app/assets/config/barion_manifest.js
152
+ - app/assets/stylesheets/barion/application.css
153
+ - app/assets/stylesheets/barion/main.css
154
+ - app/controllers/barion/application_controller.rb
155
+ - app/controllers/barion/main_controller.rb
156
+ - app/helpers/barion/application_helper.rb
157
+ - app/helpers/barion/main_helper.rb
158
+ - app/models/barion/address.rb
159
+ - app/models/barion/application_record.rb
160
+ - app/models/barion/gift_card_purchase.rb
161
+ - app/models/barion/item.rb
162
+ - app/models/barion/payer_account.rb
163
+ - app/models/barion/payment.rb
164
+ - app/models/barion/payment_transaction.rb
165
+ - app/models/barion/purchase.rb
166
+ - app/models/concerns/barion/currencies.rb
167
+ - app/models/concerns/barion/data_formats.rb
168
+ - app/models/concerns/barion/json_serializer.rb
169
+ - app/views/barion/main/land.html.erb
170
+ - config/initializers/barion.rb
171
+ - config/routes.rb
172
+ - db/migrate/20201222235354_create_barion_payments.rb
173
+ - db/migrate/20201223001557_create_barion_addresses.rb
174
+ - db/migrate/20201223002427_create_barion_payment_transactions.rb
175
+ - db/migrate/20201223003219_create_barion_purchases.rb
176
+ - db/migrate/20210111051233_create_barion_payer_accounts.rb
177
+ - db/migrate/20210128220347_create_barion_items.rb
178
+ - db/migrate/20210201120609_create_barion_gift_card_purchases.rb
179
+ - lib/barion.rb
180
+ - lib/barion/engine.rb
181
+ - lib/barion/version.rb
182
+ - lib/tasks/auto_annotate_models.rake
183
+ - lib/tasks/barion_tasks.rake
184
+ homepage: https://www.nagy.consulting
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: 2.5.0
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.2.3
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Barion payment engine for Ruby on Rails
207
+ test_files: []