spree_zaez_clearsale 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +12 -0
  5. data/Gemfile +7 -0
  6. data/Guardfile +90 -0
  7. data/LICENSE +26 -0
  8. data/README.md +81 -0
  9. data/Rakefile +21 -0
  10. data/app/assets/javascripts/spree/backend/app/clear_sale_settings/clear_sale_add_provider.js.coffee +80 -0
  11. data/app/assets/javascripts/spree/backend/app/clear_sale_settings/clear_sale_provider.js.coffee +27 -0
  12. data/app/assets/javascripts/spree/backend/app/clear_sale_settings/clear_sale_settings.js.coffee +39 -0
  13. data/app/assets/javascripts/spree/backend/spree_zaez_clearsale.js +1 -0
  14. data/app/assets/javascripts/spree/frontend/app/addresses/phone_mask_address.js.coffee +26 -0
  15. data/app/assets/javascripts/spree/frontend/spree_zaez_clearsale.js +3 -0
  16. data/app/assets/stylesheets/spree/backend/spree_zaez_clearsale.css +18 -0
  17. data/app/assets/stylesheets/spree/frontend/spree_zaez_clearsale.css +4 -0
  18. data/app/controllers/spree/admin/clear_sale_settings_controller.rb +33 -0
  19. data/app/controllers/spree/admin/payments_controller_decorator.rb +9 -0
  20. data/app/helpers/orders_helper_decorator.rb +12 -0
  21. data/app/models/spree/clear_sale.rb +153 -0
  22. data/app/models/spree/credit_card_decorator.rb +10 -0
  23. data/app/models/spree/payment_decorator.rb +33 -0
  24. data/app/overrides/spree/address/_form/add_constructor_to_form.html.erb.deface +4 -0
  25. data/app/overrides/spree/admin/orders/index/replace_considered_risk_column.html.erb.deface +2 -0
  26. data/app/overrides/spree/admin/orders/index/replace_considered_risky_label.html.erb.deface +6 -0
  27. data/app/overrides/spree/admin/shared/_order_tabs/add_clear_sale_iframe_to_order_menu.html.erb.deface +6 -0
  28. data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_clear_sale_settings_tab.html.erb.deface +2 -0
  29. data/app/views/spree/admin/clear_sale_settings/edit.html.erb +142 -0
  30. data/app/views/spree/admin/payments/clear_sale.html.erb +36 -0
  31. data/bin/rails +7 -0
  32. data/config/locales/en.yml +36 -0
  33. data/config/locales/pt-br.yml +36 -0
  34. data/config/routes.rb +9 -0
  35. data/db/migrate/20150608175547_add_bin_card_to_spree_credit_card.rb +5 -0
  36. data/db/migrate/20150611113444_add_clearsale_score_to_spree_payments.rb +5 -0
  37. data/lib/generators/spree_zaez_clearsale/install/install_generator.rb +31 -0
  38. data/lib/spree/clear_sale_configuration.rb +36 -0
  39. data/lib/spree_zaez_clearsale.rb +2 -0
  40. data/lib/spree_zaez_clearsale/engine.rb +27 -0
  41. data/lib/spree_zaez_clearsale/factories.rb +6 -0
  42. data/spec/features/admin/clear_sale_settings_spec.rb +145 -0
  43. data/spec/features/admin/orders/clearsale_spec.rb +60 -0
  44. data/spec/features/admin/orders/listing_spec.rb +47 -0
  45. data/spec/fixtures/clearsale_critical.txt +51 -0
  46. data/spec/fixtures/clearsale_high.txt +51 -0
  47. data/spec/fixtures/clearsale_low.txt +51 -0
  48. data/spec/fixtures/clearsale_medium.txt +51 -0
  49. data/spec/helpers/admin/orders_helper_decorator_spec.rb +32 -0
  50. data/spec/lib/spree/clear_sale_configuration_spec.rb +41 -0
  51. data/spec/models/spree/clear_sale_spec.rb +126 -0
  52. data/spec/models/spree/credit_card_decorator_spec.rb +11 -0
  53. data/spec/models/spree/payment_decorator_spec.rb +73 -0
  54. data/spec/spec_helper.rb +92 -0
  55. data/spec/support/capybara_login.rb +13 -0
  56. data/spec/support/verify_input_field.rb +16 -0
  57. data/spree_zaez_clearsale.gemspec +38 -0
  58. data/vendor/assets/javascripts/inputmask/inputmask.min.js +10 -0
  59. data/vendor/assets/javascripts/inputmask/jquery.inputmask.min.js +8 -0
  60. metadata +76 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 654ecd46d4228d82db6dd629c4ceca5232e20a56
4
- data.tar.gz: d6ea0125550293ae6373b78783b8ba17dcfdb531
3
+ metadata.gz: 416686e6dff14e98ee9585eaf3e04f7f18228e66
4
+ data.tar.gz: 7440b728c4cea3dbd294d1a4b4eea97a7fcc996b
5
5
  SHA512:
6
- metadata.gz: e6af4396d01f3e7cf1b0c4883a9d39c363943b8d0b276e81099a49bf2a70ea8f751a6b86231b7e47c7eaec641df4464e6d97c193587f07b7e430922d145612f7
7
- data.tar.gz: 93888d2667059ea7ab6da122f94efaee495f629fdbd6df60f5d16fb4adccd7ae60177eec1a5e9f1fadb9f601c972ed8d251d10ef59989c703597e5f55eb815b1
6
+ metadata.gz: 755e80597ca81be437e3ead35a089119191ba5bc458d177f2365323c98ec7b05a03b9b9a37f98adba52dba416c37719369844c49cccad4a72817c058bfa3fd62
7
+ data.tar.gz: 1a0de27f5573c1d57d17938e35072772806b85cecc9ab28ab1f0ecae186e98bef91d59f6879d6796f25eadb677279aa05d9defa3d1553fb2d8744e3ddc41343e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ .sass-cache
8
+ coverage
9
+ Gemfile.lock
10
+ tmp
11
+ nbproject
12
+ pkg
13
+ *.swp
14
+ spec/dummy
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation --color
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ before_script:
2
+ - sh -e /etc/init.d/xvfb start
3
+ - export DISPLAY=:99.0
4
+ bundler_args: --quiet
5
+ script:
6
+ - bundle exec rake test_app
7
+ - bundle exec rspec
8
+ language: ruby
9
+ rvm:
10
+ - 2.0.0
11
+ - 2.1.2
12
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'spree', github: 'spree/spree', branch: '3-0-stable'
4
+ # Provides basic authentication functionality for testing parts of your engine
5
+ gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
6
+
7
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,90 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec feature)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), the you will want to move the Guardfile
18
+ ## to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :shell do
36
+ watch(/^db\/migrate\/.*\.rb/) do |m|
37
+ puts "#{m[0]} Changed"
38
+ `bundle exec rake test_app`
39
+ end
40
+ end
41
+
42
+ guard :bundler do
43
+ watch('Gemfile')
44
+ # Uncomment next line if Gemfile contain `gemspec' command
45
+ watch(/^.+\.gemspec/)
46
+ end
47
+
48
+ guard :rspec, cmd: "bundle exec rspec" do
49
+ require "guard/rspec/dsl"
50
+ dsl = Guard::RSpec::Dsl.new(self)
51
+
52
+ # Feel free to open issues for suggestions and improvements
53
+
54
+ # RSpec files
55
+ rspec = dsl.rspec
56
+ watch(rspec.spec_helper) { rspec.spec_dir }
57
+ watch(rspec.spec_support) { rspec.spec_dir }
58
+ watch(rspec.spec_files)
59
+
60
+ # Ruby files
61
+ ruby = dsl.ruby
62
+ dsl.watch_spec_files_for(ruby.lib_files)
63
+
64
+ # Rails files
65
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
66
+ dsl.watch_spec_files_for(rails.app_files)
67
+ dsl.watch_spec_files_for(rails.views)
68
+
69
+ watch(rails.controllers) do |m|
70
+ [
71
+ rspec.spec.("routing/#{m[1]}_routing"),
72
+ rspec.spec.("controllers/#{m[1]}_controller"),
73
+ rspec.spec.("acceptance/#{m[1]}")
74
+ ]
75
+ end
76
+
77
+ # Rails config changes
78
+ watch(rails.spec_helper) { rspec.spec_dir }
79
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
80
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
81
+
82
+ # Capybara features specs
83
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
84
+
85
+ # Turnip features and steps
86
+ watch(%r{^spec/acceptance/(.+)\.feature$})
87
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
88
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
89
+ end
90
+ end
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015 Zaez Inovação Digital
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,81 @@
1
+ Spree Clearsale [![Build Status](https://travis-ci.org/zaeznet/spree_zaez_clearsale.svg?branch=master)](https://travis-ci.org/zaeznet/spree_zaez_clearsale)
2
+ ==================
3
+
4
+ Implementation of ClearSale Start to Spree.
5
+ To see the docs, [click here](http://www.clearsale.com.br/start/manual/Start_Manual_Integracao.pdf).
6
+
7
+ This gem needs the customer's document (CPF/CNPJ), which is represented by the setting Spree::ClearSaleConfig[:doc_customer_attr].
8
+ It's recommended use the gem [spree_zaez_brazilian_fields](https://github.com/zaeznet/spree_zaez_brazilian_fields) for that.
9
+
10
+ This gem does not support guest checkout. So disable this option in a config file:
11
+
12
+ ```ruby
13
+ Spree::Config[:allow_guest_checkout] = false
14
+ ```
15
+
16
+ In /admin/orders, the column considered risky of the order is overrided for the ClearSale score.
17
+
18
+
19
+ Installation
20
+ ------------
21
+
22
+ Add spree_zaez_clearsale to your Gemfile:
23
+
24
+ ```ruby
25
+ gem 'spree_zaez_clearsale', github: 'zaeznet/spree_zaez_clearsale'
26
+ ```
27
+
28
+ Bundle your dependencies and run the installation generator:
29
+
30
+ ```shell
31
+ bundle
32
+ bundle exec rails g spree_zaez_clearsale:install
33
+ ```
34
+
35
+
36
+ Settings
37
+ -------
38
+
39
+ To configure the ClearSale, go to /admin/clear_sale_settings/edit (or access by the menu in configurations > ClearSale Settings).
40
+ To set the settings through a config file, you can assign values to the settings like so:
41
+
42
+ ```ruby
43
+ Spree::ClearSaleConfig[:token] = 'asd-123'
44
+ ```
45
+
46
+ See all settings in /lib/spree/clear_sale_configuration.rb
47
+
48
+ If your customer has the attribute birth date (using the gem spree_zaez_brazilian_fields for example), you could set by the setting:
49
+
50
+ ```ruby
51
+ Spree::ClearSaleConfig[:birth_date_customer_attr]
52
+ ```
53
+
54
+
55
+ Deface
56
+ -------
57
+
58
+ ```
59
+ Backend
60
+ * replace_considered_risky_column -> spree/admin/orders/index.html.erb
61
+ * replace_considered_risky_label -> spree/admin/orders/index.html.erb
62
+ * add_clear_sale_iframe_to_order_menu -> spree/admin/shared/_order_tabs.html.erb
63
+ * add_clear_sale_settings_tab -> spree/admin/shared/sub_menu/_configuration.html.erb
64
+
65
+ Frontend
66
+ * add_constructor_to_form -> spree/address/_form.html.erb
67
+ ```
68
+
69
+
70
+ Testing
71
+ -------
72
+
73
+ First bundle your dependencies, then run `rake`. `rake` will default to building the dummy app if it does not exist, then it will run specs. The dummy app can be regenerated by using `rake test_app`.
74
+
75
+ ```shell
76
+ bundle
77
+ bundle exec rake
78
+ ```
79
+
80
+
81
+ Copyright (c) 2015 Zaez Inovação Digital, released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'spree/testing_support/extension_rake'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
16
+
17
+ desc 'Generates a dummy app for testing'
18
+ task :test_app do
19
+ ENV['LIB_NAME'] = 'spree_zaez_clearsale'
20
+ Rake::Task['extension:test_app'].invoke
21
+ end
@@ -0,0 +1,80 @@
1
+ #= require_self
2
+ class window.ClearSaleAddProvider
3
+
4
+ # Adiciona um novo provider
5
+ # @param event JqueryEvent
6
+ addProvider: (event) ->
7
+ event.preventDefault()
8
+ if $('#provider').select2('data')? and $('#payment_type').select2('data')?
9
+ $('.empty-fields-item').hide()
10
+ provider = $('#provider').select2('data')
11
+ payment_type = $('#payment_type').select2('data')
12
+ provider = @findOrAdd provider
13
+ provider.setPaymentType payment_type
14
+ do @render
15
+ else
16
+ $('.empty-fields-item').show()
17
+
18
+ afterConstructor: ->
19
+
20
+ beforeConstructor: ->
21
+
22
+ constructor: (@default_providers, defaultExecution = true) ->
23
+ do @beforeConstructor
24
+ do @defaultExecution if defaultExecution
25
+ do @afterConstructor
26
+
27
+ defaultExecution: ->
28
+ do @setVariables
29
+ do @setEvents
30
+ do @setDefaultProviders
31
+
32
+ findOrAdd: (provider) ->
33
+ if existing = _.find(@providers, (v) ->
34
+ v.id == provider.id)
35
+ return existing
36
+ else
37
+ provider = new ClearSaleProvider($.extend({}, provider))
38
+ @providers.push provider
39
+ return provider
40
+
41
+ # Remove um provider da tabela
42
+ # @param event JqueryEvent
43
+ removeProvider: (event) ->
44
+ event.preventDefault()
45
+ target = $ event.target
46
+ provider_id = target.data('provider')
47
+ @providers = (v for v in @providers when v.id isnt provider_id)
48
+ do @render
49
+
50
+ # Renderiza a tabela de itens
51
+ render: ->
52
+ if @providers.length > 0
53
+ $('#clear-sale-providers-table').show()
54
+ rendered = @template {providers: @providers}
55
+ $('#clear_sale_providers_tbody').html(rendered)
56
+ else
57
+ $('#clear-sale-providers-table').hide()
58
+ for item in $('input[name="providers[]"]')
59
+ $(item).val('')
60
+ for item in $('input[name="payment_types[]"]')
61
+ $(item).val('')
62
+
63
+ # Insere na tabela os providers ja salvos
64
+ setDefaultProviders: ->
65
+ for item in @default_providers
66
+ provider = @findOrAdd item
67
+ provider.setPaymentType item.payment_type
68
+ do @render
69
+
70
+ # Seta Eventos para as ações nas páginas
71
+ setEvents: ->
72
+ @addButton.on 'click', $.proxy(@addProvider, @)
73
+ @itemTable.on 'click', '.clear_sale_remove_provider', $.proxy(@removeProvider, @)
74
+
75
+ # Seta as variaveis da instância
76
+ setVariables: ->
77
+ @providers = []
78
+ @template = Handlebars.compile $('#clear_sale_provider_template').html()
79
+ @addButton = $ 'button.clear_sale_add_provider'
80
+ @itemTable = $ '#clear-sale-providers-table'
@@ -0,0 +1,27 @@
1
+ # Modelo base para os providers que utilizarao o ClearSale
2
+ class window.ClearSaleProvider
3
+
4
+ # Callback disparado após a execução
5
+ # do constructor de uma classe
6
+ afterConstructor: ->
7
+
8
+ # Callback disparado antes da execução
9
+ # do constructor de uma classe
10
+ beforeConstructor: ->
11
+
12
+ # Constructor da classe
13
+ constructor: (@provider) ->
14
+ @beforeConstructor @provider
15
+ @setAttributes @provider
16
+ @afterConstructor @provider
17
+
18
+ # Seta os attributos do provider passado
19
+ # no construtor
20
+ # @param provider Object
21
+ setAttributes: (@provider) ->
22
+ @id = @provider.id
23
+ @name = @provider.text
24
+ @payment_type = ''
25
+
26
+ setPaymentType: (payment_type) ->
27
+ @payment_type = payment_type
@@ -0,0 +1,39 @@
1
+ #= require ./clear_sale_add_provider
2
+ #= require ./clear_sale_provider
3
+ #= require_self
4
+ class window.ClearSaleSettings
5
+ afterConstructor: ->
6
+
7
+ beforeConstructor: ->
8
+
9
+ constructor: (@providers, defaultExecution = true) ->
10
+ do @beforeConstructor
11
+ do @defaultExecution if defaultExecution
12
+ do @afterConstructor
13
+
14
+ defaultExecution: ->
15
+ add_provider = new ClearSaleAddProvider(@providers)
16
+ do @setBirthDate
17
+ $('#enable_birth_date').change => do @setBirthDate
18
+ do @setCategoryTaxonomy
19
+ $('#enable_category_taxonomy').change => do @setCategoryTaxonomy
20
+
21
+ # habilita/desabilita o campo
22
+ # do atributo da data de nascimento do cliente
23
+ # de acordo com o checkbox
24
+ setBirthDate: ->
25
+ if $('#enable_birth_date').is(':checked')
26
+ $('#birth_date_container').show()
27
+ else
28
+ $('#birth_date_container').hide()
29
+ $("#birth_date_customer_attr option[value='']").attr('selected', true)
30
+
31
+ # habilita/desabilita o campo
32
+ # que armazena o taxonomy que representa
33
+ # as categorias dos produtos
34
+ setCategoryTaxonomy: ->
35
+ if $('#enable_category_taxonomy').is(':checked')
36
+ $('#category_taxonomy_container').show()
37
+ else
38
+ $('#category_taxonomy_container').hide()
39
+ $("#category_taxonomy_id option[value='']").attr('selected', true)
@@ -0,0 +1 @@
1
+ //= require ./app/clear_sale_settings/clear_sale_settings
@@ -0,0 +1,26 @@
1
+ #= require_self
2
+ class window.PhoneMaskAddress
3
+ afterConstructor: ->
4
+
5
+ beforeConstructor: ->
6
+
7
+ constructor: (defaultExecution = true) ->
8
+ do @beforeConstructor
9
+ do @defaultExecution if defaultExecution
10
+ do @afterConstructor
11
+
12
+ defaultExecution: ->
13
+ # insere as mascaras dos telefones
14
+ $('#order_bill_address_attributes_phone').inputmask
15
+ mask: ["(99) 9999-9999", "(99) 99999-9999"]
16
+ keepStatic: true
17
+ $('#order_ship_address_attributes_phone').inputmask
18
+ mask: ["(99) 9999-9999", "(99) 99999-9999"]
19
+ keepStatic: true
20
+ # insere as mascaras dos telefones alternativos
21
+ $('#order_bill_address_attributes_alternative_phone').inputmask
22
+ mask: ["(99) 9999-9999", "(99) 99999-9999"]
23
+ keepStatic: true
24
+ $('#order_ship_address_attributes_alternative_phone').inputmask
25
+ mask: ["(99) 9999-9999", "(99) 99999-9999"]
26
+ keepStatic: true