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
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Payu Latam checkout', :vcr, type: :feature do
4
+ let(:zone) { create(:zone) }
5
+ let(:country) { create(:country) }
6
+ let(:product) { create(:product) }
7
+
8
+ context 'with autocapture' do
9
+ before do
10
+ Spree::Config.set(auto_capture: true)
11
+ setup_payu_latam_gateway
12
+ zone.members << Spree::ZoneMember.create!(zoneable: country)
13
+ create(:store)
14
+ create(:free_shipping_method)
15
+
16
+ visit "/products/#{product.slug}"
17
+ click_button 'Add To Cart'
18
+ click_button 'Checkout'
19
+ fill_in 'Customer E-Mail', with: 'han@example.com'
20
+ within('#billing') { fill_address(country) }
21
+ click_on 'Save and Continue'
22
+ click_on 'Save and Continue'
23
+ end
24
+
25
+ it 'can process a valid payment', js: true do
26
+ sleep(5)
27
+ # wait to payU.getPaymentMethods()
28
+ fill_credit_card '4111 1111 1111 1111', '32144457'
29
+ click_button 'Save and Continue'
30
+ expect(page).to have_content('Your order has been processed successfully')
31
+ end
32
+ end
33
+
34
+ context 'without autocapture' do
35
+ before do
36
+ Spree::Config.set(currency: 'PEN')
37
+ setup_payu_latam_gateway
38
+ zone.members << Spree::ZoneMember.create!(zoneable: country)
39
+ create(:store)
40
+ create(:free_shipping_method)
41
+
42
+ visit "/products/#{product.slug}"
43
+ click_button 'Add To Cart'
44
+ click_button 'Checkout'
45
+ fill_in 'Customer E-Mail', with: 'han@example.com'
46
+ within('#billing') { fill_address(country) }
47
+ click_on 'Save and Continue'
48
+ click_on 'Save and Continue'
49
+ end
50
+
51
+ context 'with valid payment', js: true do
52
+ stub_authorization!
53
+
54
+ before do
55
+ sleep(5)
56
+ # wait to payU.getPaymentMethods()
57
+ fill_credit_card '4111 1111 1111 1111', '32144457'
58
+ click_button 'Save and Continue'
59
+ end
60
+
61
+ it 'can process' do
62
+ expect(page).to have_content('Your order has been processed successfully')
63
+ end
64
+
65
+ it 'capture payment' do
66
+ sleep(5)
67
+ visit spree.admin_order_payments_path(Spree::Order.last)
68
+ sleep(3)
69
+ click_icon(:capture)
70
+ expect(page).to have_content("Payment Updated")
71
+ end
72
+
73
+ it "voids a payment" do
74
+ sleep(5)
75
+ visit spree.admin_order_payments_path(Spree::Order.last)
76
+ sleep(3)
77
+ click_icon(:void)
78
+ expect(page).to have_content("Payment Updated")
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Order, type: :model do
4
+ let(:order) { Spree::Order.new }
5
+
6
+ it 'has customer document attribute' do
7
+ document = '43920390'
8
+ order.customer_document = document
9
+ expect(order.customer_document).to eq(document)
10
+ end
11
+
12
+ context 'state_machine' do
13
+ it 'dont have confirm state' do
14
+ expect(Spree::Order.checkout_steps.keys.include?(:confirm)).to be(false)
15
+ end
16
+
17
+ context 'payment_failed event' do
18
+ let(:event) { Spree::Order.state_machine.events[:payment_failed] }
19
+
20
+ it 'not have confirm state' do
21
+ expect(event.known_states.include?(:confirm)).to be(false)
22
+ end
23
+
24
+ it 'only have transition from/to payment' do
25
+ expect(event.known_states).to eq([:payment])
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::PermittedAttributes do
4
+ let(:attributes) { described_class }
5
+
6
+ context 'checkout_attributes' do
7
+ it 'include customer_document' do
8
+ expect(attributes.checkout_attributes).to include(:customer_document)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,107 @@
1
+ # Run Coverage report
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec/dummy'
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Views', 'app/views'
10
+ add_group 'Libraries', 'lib'
11
+ end
12
+
13
+ # Configure Rails Environment
14
+ ENV['RAILS_ENV'] = 'test'
15
+
16
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
17
+
18
+ require 'rspec/rails'
19
+ require 'database_cleaner'
20
+ require 'ffaker'
21
+ require 'vcr'
22
+ require 'webmock'
23
+ require 'capybara/rspec'
24
+ require 'capybara/poltergeist'
25
+ Capybara.register_driver(:poltergeist) do |app|
26
+ Capybara::Poltergeist::Driver.new app, timeout: 90
27
+ end
28
+ Capybara.javascript_driver = :poltergeist
29
+ Capybara.default_max_wait_time = 10
30
+
31
+ # Requires supporting ruby files with custom matchers and macros, etc,
32
+ # in spec/support/ and its subdirectories.
33
+ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
34
+
35
+ # Requires factories and other useful helpers defined in spree_core.
36
+ require 'spree/testing_support/authorization_helpers'
37
+ require 'spree/testing_support/capybara_ext'
38
+ require 'spree/testing_support/controller_requests'
39
+ require 'spree/testing_support/factories'
40
+ require 'spree/testing_support/url_helpers'
41
+ require 'spree/testing_support/preferences'
42
+
43
+ # Requires factories defined in lib/solidus_payu_latam/factories.rb
44
+ require 'solidus_payu_latam/factories'
45
+
46
+ RSpec.configure do |config|
47
+ config.include FactoryGirl::Syntax::Methods
48
+ config.include PayuLatamHelper
49
+
50
+ # Infer an example group's spec type from the file location.
51
+ config.infer_spec_type_from_file_location!
52
+
53
+ # == URL Helpers
54
+ #
55
+ # Allows access to Spree's routes in specs:
56
+ #
57
+ # visit spree.admin_path
58
+ # current_path.should eql(spree.products_path)
59
+ config.include Spree::TestingSupport::UrlHelpers
60
+ config.include Spree::TestingSupport::Preferences
61
+
62
+ # == Mock Framework
63
+ #
64
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
65
+ #
66
+ # config.mock_with :mocha
67
+ # config.mock_with :flexmock
68
+ # config.mock_with :rr
69
+ config.mock_with :rspec
70
+ config.color = true
71
+
72
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
73
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
74
+
75
+ # Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
76
+ # to cleanup after each test instead. Without transactional fixtures set to false the records created
77
+ # to setup a test will be unavailable to the browser, which runs under a separate server instance.
78
+ config.use_transactional_fixtures = false
79
+
80
+ # Ensure Suite is set to use transactions for speed.
81
+ config.before :suite do
82
+ DatabaseCleaner.strategy = :transaction
83
+ DatabaseCleaner.clean_with :truncation
84
+ end
85
+
86
+ # Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
87
+ config.before do
88
+ DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
89
+ DatabaseCleaner.start
90
+ reset_spree_preferences
91
+ end
92
+
93
+ # After each spec clean the database.
94
+ config.after do
95
+ DatabaseCleaner.clean
96
+ end
97
+
98
+ config.fail_fast = ENV['FAIL_FAST'] || false
99
+ config.order = 'random'
100
+ end
101
+
102
+ VCR.configure do |c|
103
+ c.cassette_library_dir = "spec/cassettes"
104
+ c.hook_into :webmock
105
+ c.ignore_localhost = true
106
+ c.configure_rspec_metadata!
107
+ end
@@ -0,0 +1,31 @@
1
+ module PayuLatamHelper
2
+ def setup_payu_latam_gateway
3
+ Solidus::Gateway::PayuLatamGateway.create!(
4
+ name: 'Payu Latam',
5
+ preferred_merchant_id: '508029',
6
+ preferred_account_id: '512323',
7
+ preferred_api_login: 'pRRXKOl8ikMmt9u',
8
+ preferred_api_key: '4Vj8eK4rloUd272L48hsrarnUA'
9
+ )
10
+ end
11
+
12
+ def fill_credit_card(number, document)
13
+ fill_in 'Card Number', with: number, visible: false
14
+ # Otherwise ccType field does not get updated correctly
15
+ page.execute_script("$('.cardNumber').trigger('change')")
16
+ fill_in 'Card Code', with: '123'
17
+ fill_in 'Expiration', with: "01 / #{Time.now.year + 1}"
18
+ fill_in 'customer_document', with: document
19
+ end
20
+
21
+ def fill_address(country)
22
+ fill_in 'First Name', with: 'APPROVED'
23
+ fill_in 'Last Name', with: ''
24
+ fill_in 'Street Address', with: 'YT-1300'
25
+ fill_in 'City', with: 'Mos Eisley'
26
+ select 'United States of America', from: 'Country'
27
+ select country.states.first, from: 'order_bill_address_attributes_state_id'
28
+ fill_in 'Zip', with: '12010'
29
+ fill_in 'Phone', with: '(555) 555-5555'
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: solidus_payu_latam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - César Carruitero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: solidus_core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: solidus_support
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemerchant
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: capybara
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: poltergeist
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: database_cleaner
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: factory_girl
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: simplecov
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Adds Solidus support for Payu Latam Gateway
168
+ email: ccarruitero@protonmail.com
169
+ executables: []
170
+ extensions: []
171
+ extra_rdoc_files: []
172
+ files:
173
+ - ".gitignore"
174
+ - ".rspec"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - LICENSE
179
+ - README.md
180
+ - Rakefile
181
+ - app/models/concerns/solidus_payu_latam/inject_customer_document_concern.rb
182
+ - app/models/concerns/solidus_payu_latam/permitted_attributes_concern.rb
183
+ - app/models/order_decorator.rb
184
+ - app/models/payment_decorator.rb
185
+ - app/models/permitted_attributes_decorator.rb
186
+ - app/models/solidus/gateway/payu_latam_gateway.rb
187
+ - app/views/spree/admin/payments/source_forms/_payu_latam.html.erb
188
+ - app/views/spree/checkout/payment/_payu_latam.html.erb
189
+ - bin/rails
190
+ - config/locales/en.yml
191
+ - config/routes.rb
192
+ - db/migrate/20170916072806_add_customer_document_to_orders.rb
193
+ - lib/generators/solidus_payu_latam/install/install_generator.rb
194
+ - lib/solidus_payu_latam.rb
195
+ - lib/solidus_payu_latam/engine.rb
196
+ - lib/solidus_payu_latam/factories.rb
197
+ - lib/solidus_payu_latam/version.rb
198
+ - solidus_payu_latam.gemspec
199
+ - spec/cassettes/Payu_Latam_checkout/with_autocapture/can_process_a_valid_payment.yml
200
+ - spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/can_process.yml
201
+ - spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/capture_payment.yml
202
+ - spec/cassettes/Payu_Latam_checkout/without_autocapture/with_valid_payment/voids_a_payment.yml
203
+ - spec/features/payu_latam_checkout_spec.rb
204
+ - spec/models/spree/order_spec.rb
205
+ - spec/models/spree/permitted_attributes_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/support/payu_latam_helper.rb
208
+ homepage: https://github.com/ccarruitero/solidus_payu_latam
209
+ licenses:
210
+ - MIT
211
+ metadata: {}
212
+ post_install_message:
213
+ rdoc_options: []
214
+ require_paths:
215
+ - lib
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ version: '0'
221
+ required_rubygems_version: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 2.6.13
229
+ signing_key:
230
+ specification_version: 4
231
+ summary: Adds Solidus support for Payu Latam Gateway
232
+ test_files: []