solidus_open_pay 1.0.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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +61 -0
  3. data/.github/stale.yml +1 -0
  4. data/.gitignore +22 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +249 -0
  7. data/Gemfile +49 -0
  8. data/LICENSE +26 -0
  9. data/README.md +37 -0
  10. data/Rakefile +11 -0
  11. data/app/assets/images/solidus_open_pay/.gitkeep +0 -0
  12. data/app/assets/javascripts/spree/backend/solidus_open_pay.js +2 -0
  13. data/app/assets/javascripts/spree/frontend/solidus_open_pay.js +2 -0
  14. data/app/assets/stylesheets/spree/backend/solidus_openpay.css +3 -0
  15. data/app/assets/stylesheets/spree/frontend/solidus_openpay.css +3 -0
  16. data/app/models/concerns/solidus_open_pay/attributes_access.rb +83 -0
  17. data/app/models/solidus_open_pay/builders/charge.rb +72 -0
  18. data/app/models/solidus_open_pay/gateway.rb +98 -0
  19. data/app/models/solidus_open_pay/payment_method.rb +30 -0
  20. data/app/models/solidus_open_pay/payment_source.rb +25 -0
  21. data/app/models/solidus_open_pay/response.rb +63 -0
  22. data/app/views/checkouts/payment/_open_pay.html.erb +171 -0
  23. data/app/views/spree/admin/payments/source_views/_open_pay.html.erb +21 -0
  24. data/app/views/spree/api/payments/source_views/_open_pay.json.jbuilder +3 -0
  25. data/app/views/spree/checkout/payment/_open_pay.html.erb +183 -0
  26. data/bin/console +17 -0
  27. data/bin/rails +7 -0
  28. data/bin/rails-engine +13 -0
  29. data/bin/rails-sandbox +16 -0
  30. data/bin/rake +7 -0
  31. data/bin/sandbox +86 -0
  32. data/bin/setup +8 -0
  33. data/config/locales/en.yml +44 -0
  34. data/config/locales/es-MX.yml +44 -0
  35. data/config/locales/es.yml +44 -0
  36. data/config/routes.rb +7 -0
  37. data/db/migrate/20241120003957_add_open_pay_sources.rb +23 -0
  38. data/lib/generators/solidus_open_pay/install/install_generator.rb +113 -0
  39. data/lib/generators/solidus_open_pay/install/templates/config/initializers/solidus_open_pay.rb +6 -0
  40. data/lib/solidus_open_pay/configuration.rb +27 -0
  41. data/lib/solidus_open_pay/engine.rb +38 -0
  42. data/lib/solidus_open_pay/testing_support/factories.rb +34 -0
  43. data/lib/solidus_open_pay/version.rb +5 -0
  44. data/lib/solidus_open_pay.rb +5 -0
  45. data/lib/tasks/solidus_openpay_tasks.rake +6 -0
  46. data/solidus_open_pay.gemspec +39 -0
  47. data/spec/models/solidus_open_pay/payment_method_spec.rb +417 -0
  48. data/spec/solidus_open_pay_spec_helper.rb +5 -0
  49. data/spec/spec_helper.rb +34 -0
  50. data/spec/support/factory_bot.rb +10 -0
  51. data/spec/support/solidus.rb +18 -0
  52. data/spec/support/solidus_open_pay/gateway_helpers.rb +27 -0
  53. metadata +197 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2a77eeaba7a6f01bbbda6121509295f60486fc77a0eb96dd8abe83c799600ad9
4
+ data.tar.gz: c3f19ae015068b57cf1fdaa5cc0082004b3f1ca58dbb4b1b678c5b1ba1a956fa
5
+ SHA512:
6
+ metadata.gz: cf8148eeb07175b2222a40271f344f362f1654656e95e54df250ff86bd23e61ab6ff7ae4f4604e302b5606e58c995ab9973cf3b04799b28a1688e270a3c98eea
7
+ data.tar.gz: 85db198e931a44e60bb9c8d979e8d49fbba979ca01c9463ebc8045176c220e2e727b8dc60c96b37bbacaa2b41d78b8a8df2b5d702df4e562c69151f047e4cc10
@@ -0,0 +1,61 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ # Always take the latest version of the orb, this allows us to
5
+ # run specs against Solidus supported versions only without the need
6
+ # to change this configuration every time a Solidus version is released
7
+ # or goes EOL.
8
+ solidusio_extensions: solidusio/extensions@volatile
9
+
10
+ jobs:
11
+ run-specs:
12
+ parameters:
13
+ solidus:
14
+ type: string
15
+ default: main
16
+ db:
17
+ type: string
18
+ default: "postgres"
19
+ ruby:
20
+ type: string
21
+ default: "3.2"
22
+ executor:
23
+ name: solidusio_extensions/<< parameters.db >>
24
+ ruby_version: << parameters.ruby >>
25
+ steps:
26
+ - checkout
27
+ - solidusio_extensions/run-tests-solidus-<< parameters.solidus >>
28
+
29
+ workflows:
30
+ "Run specs on supported Solidus versions":
31
+ jobs:
32
+ - run-specs:
33
+ name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>"
34
+ matrix:
35
+ parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
36
+ - run-specs:
37
+ name: *name
38
+ matrix:
39
+ parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
40
+ - run-specs:
41
+ name: *name
42
+ matrix:
43
+ parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] }
44
+
45
+ "Weekly run specs against main":
46
+ triggers:
47
+ - schedule:
48
+ cron: "0 0 * * 4" # every Thursday
49
+ filters:
50
+ branches:
51
+ only:
52
+ - main
53
+ jobs:
54
+ - run-specs:
55
+ name: *name
56
+ matrix:
57
+ parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] }
58
+ - run-specs:
59
+ name: *name
60
+ matrix:
61
+ parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] }
data/.github/stale.yml ADDED
@@ -0,0 +1 @@
1
+ _extends: .github
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ dummy-app
11
+ Gemfile.lock
12
+ tmp
13
+ nbproject
14
+ pkg
15
+ *.swp
16
+ spec/dummy
17
+ spec/examples.txt
18
+ /sandbox
19
+ .rvmrc
20
+ .ruby-version
21
+ .ruby-gemset
22
+ coverage/*.html
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,249 @@
1
+ require:
2
+ - solidus_dev_support/rubocop
3
+
4
+ AllCops:
5
+ NewCops: disable
6
+ TargetRubyVersion: 2.5
7
+ Exclude:
8
+ - sandbox/**/*
9
+ - dummy-app/**/*
10
+ - spec/dummy/**/*
11
+ - vendor/bundle/**/*
12
+
13
+ # We use class vars and will have to continue doing so for compatability
14
+ Style/ClassVars:
15
+ Enabled: false
16
+
17
+ # We need these names for backwards compatability
18
+ Naming/PredicateName:
19
+ Enabled: false
20
+
21
+ Naming/AccessorMethodName:
22
+ Enabled: false
23
+
24
+ # This has been used for customization
25
+ Style/MutableConstant:
26
+ Enabled: false
27
+
28
+ Style/ClassAndModuleChildren:
29
+ Enabled: false
30
+
31
+ Style/GuardClause:
32
+ Enabled: false
33
+
34
+ Style/WordArray:
35
+ Enabled: false
36
+
37
+ Style/ConditionalAssignment:
38
+ Enabled: false
39
+
40
+ Style/RaiseArgs:
41
+ Enabled: false
42
+
43
+ Naming/BinaryOperatorParameterName:
44
+ Enabled: false
45
+
46
+ # We can use good judgement here
47
+ Style/RegexpLiteral:
48
+ Enabled: false
49
+
50
+ # Unicode comments are useful
51
+ Style/AsciiComments:
52
+ Enabled: false
53
+
54
+ Layout/EndAlignment:
55
+ Enabled: false
56
+
57
+ Layout/ElseAlignment:
58
+ Enabled: false
59
+
60
+ Layout/IndentationWidth:
61
+ Enabled: false
62
+
63
+ Layout/ClosingParenthesisIndentation:
64
+ Enabled: false
65
+
66
+ Layout/MultilineMethodCallIndentation:
67
+ Enabled: false
68
+
69
+ Style/Alias:
70
+ Enabled: false
71
+ StyleGuide: http://relaxed.ruby.style/#stylealias
72
+
73
+ Style/BeginBlock:
74
+ Enabled: false
75
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
76
+
77
+ Style/BlockDelimiters:
78
+ Enabled: false
79
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
80
+
81
+ Style/Documentation:
82
+ Enabled: false
83
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
84
+
85
+ Layout/DotPosition:
86
+ Enabled: false
87
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
88
+
89
+ Style/DoubleNegation:
90
+ Enabled: false
91
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
92
+
93
+ Style/EndBlock:
94
+ Enabled: false
95
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
96
+
97
+ Style/FormatString:
98
+ Enabled: false
99
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
100
+
101
+ Style/IfUnlessModifier:
102
+ Enabled: false
103
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
104
+
105
+ Style/Lambda:
106
+ Enabled: false
107
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
108
+
109
+ Style/ModuleFunction:
110
+ Enabled: false
111
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
112
+
113
+ Style/MultilineBlockChain:
114
+ Enabled: false
115
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
116
+
117
+ Style/NegatedIf:
118
+ Enabled: false
119
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
120
+
121
+ Style/NegatedWhile:
122
+ Enabled: false
123
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
124
+
125
+ Style/ParallelAssignment:
126
+ Enabled: false
127
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
128
+
129
+ Style/PercentLiteralDelimiters:
130
+ Enabled: false
131
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
132
+
133
+ Style/PerlBackrefs:
134
+ Enabled: false
135
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
136
+
137
+ Style/Semicolon:
138
+ Enabled: false
139
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
140
+
141
+ Style/SignalException:
142
+ Enabled: false
143
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
144
+
145
+ Style/SingleLineBlockParams:
146
+ Enabled: false
147
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
148
+
149
+ Style/SingleLineMethods:
150
+ Enabled: false
151
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
152
+
153
+ Layout/SpaceBeforeBlockBraces:
154
+ Enabled: false
155
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
156
+
157
+ Layout/SpaceInsideParens:
158
+ Enabled: false
159
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
160
+
161
+ Style/SpecialGlobalVars:
162
+ Enabled: false
163
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
164
+
165
+ Style/StringLiterals:
166
+ Enabled: false
167
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
168
+
169
+ Style/SymbolProc:
170
+ Enabled: false
171
+
172
+ Style/WhileUntilModifier:
173
+ Enabled: false
174
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
175
+
176
+ Lint/AmbiguousRegexpLiteral:
177
+ Enabled: false
178
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
179
+
180
+ Lint/AssignmentInCondition:
181
+ Enabled: false
182
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
183
+
184
+ Lint/SuppressedException:
185
+ Exclude:
186
+ - 'Rakefile'
187
+
188
+ Metrics/AbcSize:
189
+ Enabled: false
190
+
191
+ Metrics/BlockNesting:
192
+ Enabled: false
193
+
194
+ Metrics/ClassLength:
195
+ Enabled: false
196
+
197
+ Metrics/ModuleLength:
198
+ Enabled: false
199
+
200
+ Metrics/CyclomaticComplexity:
201
+ Enabled: false
202
+
203
+ Layout/LineLength:
204
+ Enabled: false
205
+
206
+ Metrics/MethodLength:
207
+ Enabled: false
208
+
209
+ Metrics/ParameterLists:
210
+ Enabled: false
211
+
212
+ Metrics/PerceivedComplexity:
213
+ Enabled: false
214
+
215
+ Lint/EmptyBlock:
216
+ Enabled: false
217
+
218
+ Gemspec/DevelopmentDependencies:
219
+ Enabled: false
220
+
221
+ Lint/ScriptPermission:
222
+ Enabled: false
223
+
224
+ Lint/NonDeterministicRequireOrder:
225
+ Enabled: false
226
+
227
+ Lint/ShadowingOuterLocalVariable:
228
+ Enabled: false
229
+
230
+ Gemspec/RequireMFA:
231
+ Enabled: false
232
+
233
+ Gemspec/DeprecatedAttributeAssignment:
234
+ Enabled: false
235
+
236
+ Layout/ArgumentAlignment:
237
+ Enabled: false
238
+
239
+ RSpec/AnyInstance:
240
+ Enabled: false
241
+
242
+ RSpec/MultipleMemoizedHelpers:
243
+ Enabled: false
244
+
245
+ RSpec/MultipleExpectations:
246
+ Enabled: false
247
+
248
+ RSpec/NestedGroups:
249
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
+
6
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'main')
7
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
8
+
9
+ # The solidus_frontend gem has been pulled out since v3.2
10
+ if branch >= 'v3.2'
11
+ gem 'solidus_frontend'
12
+ elsif branch == 'main'
13
+ gem 'solidus_frontend', github: 'solidusio/solidus_frontend', branch: branch
14
+ else
15
+ gem 'solidus_frontend', github: 'solidusio/solidus', branch: branch
16
+ end
17
+
18
+ # Provides basic authentication functionality for testing parts of your engine
19
+ gem 'solidus_auth_devise'
20
+
21
+ case ENV.fetch('DB', nil)
22
+ when 'mysql'
23
+ gem 'mysql2'
24
+ when 'postgresql'
25
+ gem 'pg'
26
+ else
27
+ gem 'sqlite3', '~> 1.4'
28
+ end
29
+
30
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3')
31
+ # While we still support Ruby < 3 we need to workaround a limitation in
32
+ # the 'async' gem that relies on the latest ruby, since RubyGems doesn't
33
+ # resolve gems based on the required ruby version.
34
+ gem 'async', '< 3', require: false
35
+ end
36
+
37
+ # 'net/smtp' is required by 'mail', see:
38
+ # - https://github.com/ruby/net-protocol/issues/10
39
+ # - https://stackoverflow.com/a/72474475
40
+ gem 'net-smtp', require: false
41
+
42
+ gemspec
43
+
44
+ # Use a local Gemfile to include development dependencies that might not be
45
+ # relevant for the project or for other contributors, e.g. pry-byebug.
46
+ #
47
+ # We use `send` instead of calling `eval_gemfile` to work around an issue with
48
+ # how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
49
+ send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2017 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Solidus OpenPay
2
+
3
+ [![CircleCI](https://circleci.com/gh/jtapia/solidus_open_pay.svg?style=shield)](https://circleci.com/gh/jtapia/solidus_open_pay)
4
+
5
+ Add solidus_open_pay to your Gemfile:
6
+
7
+ ```ruby
8
+ gem 'solidus_open_pay', github: 'jtapia/solidus_open_pay'
9
+ ```
10
+
11
+ Then run:
12
+
13
+ ```shell
14
+ bundle
15
+ bundle exec rails g solidus_open_pay:install
16
+ ```
17
+
18
+ ## Setup OpenPay Payments
19
+
20
+ You need to go to [Openpay](https://www.openpay.mx/), create an account and retrieve your ID, private and public api keys.
21
+
22
+ On the solidus application admin side go to:
23
+
24
+ - `/admin/payment_methods/new`
25
+
26
+ ```
27
+ In the provider box, choose one of the following options depending on your needs (freemium version only works with credit card):
28
+
29
+ SolidusOpenPay::PaymentMethod
30
+ ```
31
+
32
+ ## Source Methods
33
+
34
+ Solidus Openpay currently supports:
35
+
36
+ #### Card
37
+ > Card method will let you pay using your credit or debit card. More info: More info: [Openpay Card](https://www.openpay.mx/docs/save-card.html)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Don't build a dummy app with solidus_bolt enabled
4
+ ENV['SKIP_SOLIDUS_BOLT'] = 'true'
5
+
6
+ require 'bundler/gem_tasks'
7
+
8
+ require 'solidus_dev_support/rake_tasks'
9
+ SolidusDevSupport::RakeTasks.install
10
+
11
+ task default: 'extension:specs'
File without changes
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/backend/all.js'
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,3 @@
1
+ /*
2
+ *= require_tree .
3
+ */
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusOpenPay
4
+ module AttributesAccess
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :brand,
9
+ :device_session_id,
10
+ :expiration_month,
11
+ :expiration_year,
12
+ :number,
13
+ :token_id,
14
+ :verification_value,
15
+ :points_card,
16
+ :points_type
17
+
18
+ def brand=(value)
19
+ self[:brand] = value.to_s.gsub(/\s/, '')
20
+ end
21
+
22
+ def device_session_id=(value)
23
+ self[:device_session_id] = value.to_s.gsub(/\s/, '')
24
+ end
25
+
26
+ def number=(value)
27
+ number_value =
28
+ if value.is_a?(String)
29
+ value.gsub(/[^0-9]/, '')
30
+ end
31
+
32
+ self[:number] = if number_value.to_s.length <= 4
33
+ number_value
34
+ else
35
+ number_value.to_s.last(4)
36
+ end
37
+ end
38
+
39
+ def token_id=(value)
40
+ self[:token_id] = value.to_s.gsub(/\s/, '')
41
+ end
42
+
43
+ def points_card=(value)
44
+ self[:points_card] = value.to_s.gsub(/\s/, '')
45
+ end
46
+
47
+ def points_type=(value)
48
+ self[:points_type] = value.to_s.gsub(/\s/, '')
49
+ end
50
+
51
+ def expiration_month=(value)
52
+ self[:expiration_month] = value.to_i if value
53
+ end
54
+
55
+ def expiration_year=(value)
56
+ if value
57
+ self[:expiration_year] = "20#{value}" if value.length == 2
58
+ self[:expiration_year] = value.to_i
59
+ end
60
+ end
61
+
62
+ def brand
63
+ self[:brand]
64
+ end
65
+
66
+ def device_session_id
67
+ self[:device_session_id]
68
+ end
69
+
70
+ def number
71
+ self[:number]
72
+ end
73
+
74
+ def token_id
75
+ self[:token_id]
76
+ end
77
+
78
+ def display_number
79
+ "XXXX-XXXX-XXXX-#{number}"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidusOpenPay
4
+ module Builders
5
+ class Charge
6
+ attr_reader :source, :amount, :options
7
+
8
+ def initialize(source:, amount:, options: {})
9
+ @source = source
10
+ @amount = amount
11
+ @options = options
12
+ end
13
+
14
+ def payload
15
+ {
16
+ 'source_id' => token_id,
17
+ 'method' => 'card',
18
+ 'amount' => amount / 100,
19
+ 'currency' => 'MXN',
20
+ 'capture' => capture,
21
+ 'description' => 'Cargo inicial',
22
+ 'order_id' => order_id,
23
+ 'device_session_id' => device_session_id,
24
+ 'customer' => {
25
+ 'name' => first_name,
26
+ 'last_name' => last_name,
27
+ 'phone_number' => phone_number,
28
+ 'email' => email
29
+ }
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def token_id
36
+ @token_id ||= source.token_id
37
+ end
38
+
39
+ def email
40
+ @email ||= order&.email || 'pedidos@donmanolito.com'
41
+ end
42
+
43
+ def capture
44
+ @capture ||= options[:capture] || false
45
+ end
46
+
47
+ def order_id
48
+ @order_id ||= options[:order_id]
49
+ end
50
+
51
+ def order
52
+ @order ||= Spree::Order.find_by(number: order_id.split[0])
53
+ end
54
+
55
+ def phone_number
56
+ @phone_number ||= order&.bill_address&.phone
57
+ end
58
+
59
+ def device_session_id
60
+ @device_session_id ||= source.device_session_id
61
+ end
62
+
63
+ def first_name
64
+ @first_name ||= source.name.split[0]
65
+ end
66
+
67
+ def last_name
68
+ @last_name ||= source.name.split[1]
69
+ end
70
+ end
71
+ end
72
+ end