solidus_payu_latam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +236 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +19 -0
  7. data/LICENSE +19 -0
  8. data/README.md +45 -0
  9. data/Rakefile +30 -0
  10. data/app/models/concerns/solidus_payu_latam/inject_customer_document_concern.rb +17 -0
  11. data/app/models/concerns/solidus_payu_latam/permitted_attributes_concern.rb +7 -0
  12. data/app/models/order_decorator.rb +15 -0
  13. data/app/models/payment_decorator.rb +1 -0
  14. data/app/models/permitted_attributes_decorator.rb +1 -0
  15. data/app/models/solidus/gateway/payu_latam_gateway.rb +70 -0
  16. data/app/views/spree/admin/payments/source_forms/_payu_latam.html.erb +1 -0
  17. data/app/views/spree/checkout/payment/_payu_latam.html.erb +7 -0
  18. data/bin/rails +7 -0
  19. data/config/locales/en.yml +5 -0
  20. data/config/routes.rb +3 -0
  21. data/db/migrate/20170916072806_add_customer_document_to_orders.rb +5 -0
  22. data/lib/generators/solidus_payu_latam/install/install_generator.rb +20 -0
  23. data/lib/solidus_payu_latam.rb +3 -0
  24. data/lib/solidus_payu_latam/engine.rb +17 -0
  25. data/lib/solidus_payu_latam/factories.rb +6 -0
  26. data/lib/solidus_payu_latam/version.rb +3 -0
  27. data/solidus_payu_latam.gemspec +31 -0
  28. data/spec/cassettes/Payu_Latam_checkout/with_autocapture/can_process_a_valid_payment.yml +43 -0
  29. data/spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/can_process.yml +43 -0
  30. data/spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/capture_payment.yml +80 -0
  31. data/spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/voids_a_payment.yml +80 -0
  32. data/spec/features/payu_latam_checkout_spec.rb +82 -0
  33. data/spec/models/spree/order_spec.rb +29 -0
  34. data/spec/models/spree/permitted_attributes_spec.rb +11 -0
  35. data/spec/spec_helper.rb +107 -0
  36. data/spec/support/payu_latam_helper.rb +31 -0
  37. metadata +232 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 393956b93bb8df707306173cf3ca1d67ffbcfbef
4
+ data.tar.gz: 55d413c6da222c4b0119f591b31b9a2d74fb4447
5
+ SHA512:
6
+ metadata.gz: e6ff4ccbc70c7e418a5a0eac321354e955d3c67c7d0bee204fe9b896be8a71a2b83835ba905ee589d4ce6bb188e99a54dadb2abfc505d0640aac0eb727ee2825
7
+ data.tar.gz: 6ad9a3bed649cd1c256c0a7cb2f6fa4dd68ce54d9179f1518baa1633fc2fd51805274085ffd149d26c653d92bbcd5de63142e769f06e8f3ae4a62cc1e545ab92
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ \#*
3
+ *~
4
+ .#*
5
+ .DS_Store
6
+ .idea
7
+ .project
8
+ .sass-cache
9
+ coverage
10
+ Gemfile.lock
11
+ tmp
12
+ nbproject
13
+ pkg
14
+ *.swp
15
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,236 @@
1
+ require: rubocop-rspec
2
+ # Relaxed.Ruby.Style
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - 'spec/dummy/**/*'
7
+ - 'vendor/bundle/**/*'
8
+ TargetRubyVersion: 2.1
9
+
10
+ # Sometimes I believe this reads better
11
+ # This also causes spacing issues on multi-line fixes
12
+ Style/BracesAroundHashParameters:
13
+ Enabled: false
14
+
15
+ # We use class vars and will have to continue doing so for compatability
16
+ Style/ClassVars:
17
+ Enabled: false
18
+
19
+ # We need these names for backwards compatability
20
+ Style/PredicateName:
21
+ Enabled: false
22
+
23
+ Style/AccessorMethodName:
24
+ Enabled: false
25
+
26
+ # This has been used for customization
27
+ Style/MutableConstant:
28
+ Enabled: false
29
+
30
+ Style/ClassAndModuleChildren:
31
+ Enabled: false
32
+
33
+ Style/GuardClause:
34
+ Enabled: false
35
+
36
+ Style/WordArray:
37
+ Enabled: false
38
+
39
+ Style/ConditionalAssignment:
40
+ Enabled: false
41
+
42
+ Performance/Count:
43
+ Enabled: false
44
+
45
+ Style/RaiseArgs:
46
+ Enabled: false
47
+
48
+ # We can use good judgement here
49
+ Style/RegexpLiteral:
50
+ Enabled: false
51
+
52
+ # Unicode comments are useful
53
+ Style/AsciiComments:
54
+ Enabled: false
55
+
56
+ Lint/EndAlignment:
57
+ Enabled: false
58
+
59
+ Style/ElseAlignment:
60
+ Enabled: false
61
+
62
+ Style/IndentationWidth:
63
+ Enabled: false
64
+
65
+ Style/AlignParameters:
66
+ Enabled: false
67
+
68
+ Style/ClosingParenthesisIndentation:
69
+ Enabled: false
70
+
71
+ Style/MultilineMethodCallIndentation:
72
+ Enabled: false
73
+
74
+ Style/IndentArray:
75
+ Enabled: false
76
+
77
+ Style/IndentHash:
78
+ Enabled: false
79
+
80
+ Style/AlignHash:
81
+ Enabled: false
82
+
83
+ # From http://relaxed.ruby.style/
84
+
85
+ Style/Alias:
86
+ Enabled: false
87
+ StyleGuide: http://relaxed.ruby.style/#stylealias
88
+
89
+ Style/BeginBlock:
90
+ Enabled: false
91
+ StyleGuide: http://relaxed.ruby.style/#stylebeginblock
92
+
93
+ Style/BlockDelimiters:
94
+ Enabled: false
95
+ StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
96
+
97
+ Style/Documentation:
98
+ Enabled: false
99
+ StyleGuide: http://relaxed.ruby.style/#styledocumentation
100
+
101
+ Style/DotPosition:
102
+ Enabled: false
103
+ StyleGuide: http://relaxed.ruby.style/#styledotposition
104
+
105
+ Style/DoubleNegation:
106
+ Enabled: false
107
+ StyleGuide: http://relaxed.ruby.style/#styledoublenegation
108
+
109
+ Style/EndBlock:
110
+ Enabled: false
111
+ StyleGuide: http://relaxed.ruby.style/#styleendblock
112
+
113
+ Style/FormatString:
114
+ Enabled: false
115
+ StyleGuide: http://relaxed.ruby.style/#styleformatstring
116
+
117
+ Style/IfUnlessModifier:
118
+ Enabled: false
119
+ StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
120
+
121
+ Style/Lambda:
122
+ Enabled: false
123
+ StyleGuide: http://relaxed.ruby.style/#stylelambda
124
+
125
+ Style/ModuleFunction:
126
+ Enabled: false
127
+ StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
128
+
129
+ Style/MultilineBlockChain:
130
+ Enabled: false
131
+ StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
132
+
133
+ Style/NegatedIf:
134
+ Enabled: false
135
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedif
136
+
137
+ Style/NegatedWhile:
138
+ Enabled: false
139
+ StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
140
+
141
+ Style/ParallelAssignment:
142
+ Enabled: false
143
+ StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
144
+
145
+ Style/PercentLiteralDelimiters:
146
+ Enabled: false
147
+ StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
148
+
149
+ Style/PerlBackrefs:
150
+ Enabled: false
151
+ StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
152
+
153
+ Style/Semicolon:
154
+ Enabled: false
155
+ StyleGuide: http://relaxed.ruby.style/#stylesemicolon
156
+
157
+ Style/SignalException:
158
+ Enabled: false
159
+ StyleGuide: http://relaxed.ruby.style/#stylesignalexception
160
+
161
+ Style/SingleLineBlockParams:
162
+ Enabled: false
163
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
164
+
165
+ Style/SingleLineMethods:
166
+ Enabled: false
167
+ StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
168
+
169
+ Style/SpaceBeforeBlockBraces:
170
+ Enabled: false
171
+ StyleGuide: http://relaxed.ruby.style/#stylespacebeforeblockbraces
172
+
173
+ Style/SpaceInsideParens:
174
+ Enabled: false
175
+ StyleGuide: http://relaxed.ruby.style/#stylespaceinsideparens
176
+
177
+ Style/SpecialGlobalVars:
178
+ Enabled: false
179
+ StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
180
+
181
+ Style/StringLiterals:
182
+ Enabled: false
183
+ StyleGuide: http://relaxed.ruby.style/#stylestringliterals
184
+
185
+ Style/SymbolProc:
186
+ Enabled: false
187
+
188
+ Style/WhileUntilModifier:
189
+ Enabled: false
190
+ StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
191
+
192
+ Lint/AmbiguousRegexpLiteral:
193
+ Enabled: false
194
+ StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
195
+
196
+ Lint/AssignmentInCondition:
197
+ Enabled: false
198
+ StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
199
+
200
+ Lint/HandleExceptions:
201
+ Exclude:
202
+ - 'Rakefile'
203
+
204
+ Metrics/AbcSize:
205
+ Enabled: false
206
+
207
+ Metrics/BlockLength:
208
+ Exclude:
209
+ - 'spec/*/*'
210
+
211
+ Metrics/BlockNesting:
212
+ Enabled: false
213
+
214
+ Metrics/ClassLength:
215
+ Enabled: false
216
+
217
+ Metrics/ModuleLength:
218
+ Enabled: false
219
+
220
+ Metrics/CyclomaticComplexity:
221
+ Enabled: false
222
+
223
+ Metrics/LineLength:
224
+ Enabled: false
225
+
226
+ Metrics/MethodLength:
227
+ Enabled: false
228
+
229
+ Metrics/ParameterLists:
230
+ Enabled: false
231
+
232
+ Metrics/PerceivedComplexity:
233
+ Enabled: false
234
+
235
+ Naming/BinaryOperatorParameterName:
236
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ sudo: false
2
+ cache: bundler
3
+ language: ruby
4
+ bundler_args: --quiet
5
+ script:
6
+ - bundle exec rake
7
+ rvm:
8
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}.git" }
4
+
5
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
6
+ gem 'solidus', github: 'solidusio/solidus', branch: branch
7
+
8
+ gemspec
9
+
10
+ gem 'pry'
11
+
12
+ group :test do
13
+ gem 'ffaker'
14
+ gem 'sqlite3'
15
+ gem 'vcr'
16
+ gem 'webmock'
17
+ end
18
+
19
+ gem 'activemerchant', github: 'activemerchant/active_merchant'
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2017 César Carruitero
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ Solidus PayuLatam
2
+ =================
3
+
4
+ Solidus extension to add support for Payu Latam Gateway.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add in your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'solidus_payu_latam'
13
+ ```
14
+
15
+ Then bundle your dependencies and run the installation generator:
16
+
17
+ ```shell
18
+ bundle
19
+ bundle exec rails g solidus_payu_latam:install
20
+ ```
21
+
22
+ Usage
23
+ -----
24
+
25
+ After install and run the migrations, you should see the gateway in the
26
+ provider dropdown when you try to edit or create a payment method in the admin.
27
+
28
+ Then select the `Payu Latam Gateway`, add your credentials, and ensure the
29
+ payment method is active.
30
+
31
+ That's it. Now you can use the gateway to process your user payments.
32
+
33
+ Tests
34
+ -------
35
+
36
+ In order to run the tests you need to build a dummy app first.
37
+
38
+ Run the following to automatically build a dummy app if necessary and run the
39
+ tests:
40
+
41
+ ```shell
42
+ bundle exec rake
43
+ ```
44
+
45
+ The dummy app can be regenerated by using `rake test_app`.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'bundler'
2
+
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ begin
6
+ require 'spree/testing_support/extension_rake'
7
+ require 'rubocop/rake_task'
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i(first_run rubocop spec)
15
+ rescue LoadError
16
+ # no rspec available
17
+ end
18
+
19
+ task :first_run do
20
+ if Dir['spec/dummy'].empty?
21
+ Rake::Task[:test_app].invoke
22
+ Dir.chdir('../../')
23
+ end
24
+ end
25
+
26
+ desc 'Generates a dummy app for testing'
27
+ task :test_app do
28
+ ENV['LIB_NAME'] = 'solidus_payu_latam'
29
+ Rake::Task['extension:test_app'].invoke
30
+ end
@@ -0,0 +1,17 @@
1
+ module SolidusPayuLatam
2
+ module InjectCustomerDocumentConcern
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ prepend(InstanceMethods)
6
+ end
7
+
8
+ module InstanceMethods
9
+ def gateway_options
10
+ options = super
11
+ document = order.customer_document
12
+ options[:customer_document] = document if document
13
+ options
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ module SolidusPayuLatam
2
+ module PermittedAttributesConcern
3
+ def checkout_attributes
4
+ super | [:customer_document]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ Spree::Order.class_eval do
2
+ checkout_flow do
3
+ go_to_state :address
4
+ go_to_state :delivery
5
+ go_to_state :payment
6
+ go_to_state :complete
7
+ end
8
+
9
+ state_machine do
10
+ event :payment_failed do
11
+ reset
12
+ transition payment: :payment
13
+ end
14
+ end
15
+ end
@@ -0,0 +1 @@
1
+ Spree::Payment.include SolidusPayuLatam::InjectCustomerDocumentConcern
@@ -0,0 +1 @@
1
+ Spree::PermittedAttributes.singleton_class.prepend SolidusPayuLatam::PermittedAttributesConcern