spree_zaez_billet 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 (57) 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 +11 -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/billet_settings/billet_setting.js.coffee +66 -0
  11. data/app/assets/javascripts/spree/backend/spree_zaez_billet.js +1 -0
  12. data/app/assets/javascripts/spree/frontend/spree_zaez_billet.js +2 -0
  13. data/app/assets/stylesheets/spree/backend/spree_zaez_billet.css +3 -0
  14. data/app/assets/stylesheets/spree/frontend/spree_zaez_billet.css +4 -0
  15. data/app/controllers/spree/admin/billet_settings_controller.rb +29 -0
  16. data/app/controllers/spree/admin/billets_controller.rb +61 -0
  17. data/app/controllers/spree/billets_controller.rb +35 -0
  18. data/app/models/spree/address_decorator.rb +17 -0
  19. data/app/models/spree/billet.rb +257 -0
  20. data/app/models/spree/payment_method/billet.rb +83 -0
  21. data/app/overrides/spree/admin/shared/_main_menu/add_payment_tab_to_main_menu.html.erb.deface +6 -0
  22. data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_billet_settings_tab.html.erb.deface +2 -0
  23. data/app/overrides/spree/payments/_payment/add_billet_info_to_order_details.html.erb.deface +6 -0
  24. data/app/views/spree/admin/billet_settings/edit.html.erb +154 -0
  25. data/app/views/spree/admin/billets/return.html.erb +40 -0
  26. data/app/views/spree/admin/billets/return_info.html.erb +32 -0
  27. data/app/views/spree/admin/billets/shipping.html.erb +39 -0
  28. data/app/views/spree/admin/payments/source_forms/_billet.html.erb +4 -0
  29. data/app/views/spree/admin/payments/source_views/_billet.html.erb +39 -0
  30. data/app/views/spree/admin/shared/sub_menu/_payment.html.erb +4 -0
  31. data/app/views/spree/checkout/payment/_billet.html.erb +4 -0
  32. data/bin/rails +7 -0
  33. data/config/locales/en.yml +58 -0
  34. data/config/locales/pt-br.yml +57 -0
  35. data/config/routes.rb +13 -0
  36. data/db/migrate/20150617193744_create_spree_billets.rb +14 -0
  37. data/lib/generators/spree_zaez_billet/install/install_generator.rb +31 -0
  38. data/lib/spree/billet_configuration.rb +31 -0
  39. data/lib/spree_zaez_billet.rb +5 -0
  40. data/lib/spree_zaez_billet/engine.rb +31 -0
  41. data/lib/spree_zaez_billet/factories.rb +34 -0
  42. data/spec/features/admin/billet_payments_spec.rb +85 -0
  43. data/spec/features/admin/billet_settings_spec.rb +207 -0
  44. data/spec/features/admin/billets_return_spec.rb +39 -0
  45. data/spec/features/admin/billets_shipping_spec.rb +87 -0
  46. data/spec/features/checkout_with_billet_spec.rb +84 -0
  47. data/spec/fixtures/files/cnab240.ret +16 -0
  48. data/spec/fixtures/files/cnab400.ret +54 -0
  49. data/spec/lib/spree/billet_configuration_spec.rb +14 -0
  50. data/spec/models/spree/address_decorator_spec.rb +13 -0
  51. data/spec/models/spree/billet_spec.rb +366 -0
  52. data/spec/spec_helper.rb +95 -0
  53. data/spec/support/capybara_login.rb +13 -0
  54. data/spec/support/shared_contexts/checkout_setup.rb +10 -0
  55. data/spec/support/verify_input_field.rb +16 -0
  56. data/spree_zaez_billet.gemspec +38 -0
  57. metadata +72 -3
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Billet Payments', type: :feature do
4
+ let!(:order1) { create(:order) }
5
+ let!(:payment) { create(:billet_payment, number: 'P100', order: order1) }
6
+
7
+ before { create_admin_in_sign_in }
8
+
9
+ context 'show billet info' do
10
+ it 'should show billet information in payments', js: true do
11
+ visit spree.admin_order_payment_path(order1, payment)
12
+
13
+ expect(page).to have_text 'Number'
14
+ expect(page).to have_text '1'
15
+ expect(page).to have_text 'Amount'
16
+ expect(page).to have_text '$15.99'
17
+ expect(page).to have_text 'Due Date'
18
+ expect(page).to have_text payment.source.due_date.strftime(I18n.t('date.formats.default'))
19
+ expect(page).to have_css '.label-pending'
20
+ expect(page).to have_text 'PENDING'
21
+ end
22
+
23
+ it 'should show generate button when the billet is pending', js: true do
24
+ visit spree.admin_order_payment_path(order1, payment)
25
+
26
+ expect(page).to have_link 'Generate Billet'
27
+ end
28
+
29
+ it 'should do not show generate button when the billet is paid/void', js: true do
30
+ payment.source.status = 'void'
31
+ payment.source.save
32
+
33
+ visit spree.admin_order_payment_path(order1, payment)
34
+
35
+ expect(page).not_to have_link 'Generate Billet'
36
+ end
37
+ end
38
+
39
+ context 'capture the billet' do
40
+ it 'should capture the payment and update the billet to paid', js: true do
41
+ visit spree.admin_order_payments_path order1
42
+ click_icon :capture
43
+ click_link 'P100'
44
+
45
+ expect(page).to have_css '.label-paid'
46
+ expect(page).to have_text 'PAID'
47
+ expect(page).to have_text 'Paid In'
48
+ expect(page).to have_text Date.today.strftime(I18n.t('date.formats.default'))
49
+ end
50
+ end
51
+
52
+ context 'void the billet' do
53
+ it 'should void the payment and update the billet to void', js: true do
54
+ visit spree.admin_order_payments_path order1
55
+ click_icon :void
56
+ click_link 'P100'
57
+
58
+ expect(page).to have_css '.label-void'
59
+ expect(page).to have_text 'VOID'
60
+ end
61
+ end
62
+
63
+ context 'billet overdue' do
64
+ let!(:order2) { create(:order) }
65
+ let!(:payment_overdue) { create(:billet_payment_overdue, number: 'P200', order: order2) }
66
+
67
+ it 'should void the old payment and create a new when billet is overdue', js: true do
68
+ allow_any_instance_of(Spree::Billet).to receive(:generate_document).
69
+ and_return(Brcobranca::Boleto::Itau.new(agencia: '1234',
70
+ conta_corrente: '12345',
71
+ documento_cedente: '12345',
72
+ sacado_documento: '12345',
73
+ numero_documento: 1))
74
+
75
+ visit spree.admin_order_payment_path(order2, payment_overdue)
76
+ click_link 'Generate Billet'
77
+
78
+ visit spree.admin_order_payments_path order2
79
+
80
+ within_row(1) do
81
+ expect(column_text(6)).to eq 'void'
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Billet Settings', type: :feature do
4
+
5
+ before { create_admin_in_sign_in }
6
+
7
+ context 'visit billet settings' do
8
+ it 'should be a link to billet settings' do
9
+ within('.sidebar') { page.find_link('Billet Settings')['/admin/billet_settings/edit'] }
10
+ end
11
+ end
12
+
13
+ context 'show billet settings' do
14
+ it 'should show common billet settings', js: true do
15
+ Spree::BilletConfig.bank = ''
16
+ visit spree.edit_admin_billet_settings_path
17
+
18
+ expect(page).to have_selector '#bank'
19
+ expect(page).to have_selector '#corporate_name'
20
+ expect(page).to have_selector '#document'
21
+ expect(page).to have_selector '#address'
22
+ expect(page).to have_selector '#agency'
23
+ expect(page).to have_selector '#account'
24
+ expect(page).to have_selector '#registered'
25
+ expect(page).to have_selector '#due_date'
26
+ expect(page).to have_selector '[name=acceptance]'
27
+ expect(page).to have_selector '#instruction_1'
28
+ expect(page).to have_selector '#instruction_2'
29
+ expect(page).to have_selector '#instruction_3'
30
+ expect(page).to have_selector '#instruction_4'
31
+ expect(page).to have_selector '#instruction_5'
32
+ expect(page).to have_selector '#instruction_6'
33
+ end
34
+
35
+ it 'should clear the shipping number', js: true do
36
+ Spree::BilletConfig.shipping_number = 19
37
+ visit spree.edit_admin_billet_settings_path
38
+
39
+ click_link 'Clear Number'
40
+
41
+ expect(find_field('shipping_number', disabled: true).value).to eq '1'
42
+ end
43
+
44
+ context 'choosing the bank' do
45
+ before { visit spree.edit_admin_billet_settings_path }
46
+
47
+ it 'do not show specific fields when any bank is selected', js: true do
48
+ expect(page).not_to have_selector '#wallet'
49
+ expect(page).not_to have_selector '#variation_wallet'
50
+ expect(page).not_to have_selector '#agreement'
51
+ expect(page).not_to have_selector '#account_digit'
52
+ expect(page).not_to have_selector '#company_code'
53
+ expect(page).not_to have_selector '#office_code'
54
+ expect(page).not_to have_selector '#app_version'
55
+ expect(page).not_to have_selector '#byte_idt'
56
+ end
57
+
58
+ it 'should show fields of Banco do Brasil', js: true do
59
+ select2 'Banco do Brasil', from: 'Bank'
60
+
61
+ expect(page).to have_selector '#agreement'
62
+ expect(page).to have_selector '#wallet'
63
+ expect(page).to have_selector '#variation_wallet'
64
+ end
65
+
66
+ it 'should show fields of Caixa', js: true do
67
+ select2 'Caixa Econômica Federal', from: 'Bank'
68
+
69
+ expect(page).to have_selector '#agreement'
70
+ expect(page).to have_selector '#account_digit'
71
+ expect(page).to have_selector '#app_version'
72
+ end
73
+
74
+ it 'should show fields of Bradesco', js: true do
75
+ select2 'Bradesco', from: 'Bank'
76
+
77
+ expect(page).to have_selector '#wallet'
78
+ expect(page).to have_selector '#account_digit'
79
+ expect(page).to have_selector '#company_code'
80
+ end
81
+
82
+ it 'should show fields of Itaú', js: true do
83
+ select2 'Itaú', from: 'Bank'
84
+
85
+ expect(page).to have_selector '#wallet'
86
+ expect(page).to have_selector '#account_digit'
87
+ expect(page).to have_selector '#agreement'
88
+ end
89
+
90
+ it 'should show fields of HSBC', js: true do
91
+ select2 'HSBC', from: 'Bank'
92
+
93
+ expect(page).to have_selector '#wallet'
94
+ end
95
+
96
+ it 'should show fields of Santander', js: true do
97
+ select2 'Santander Banespa', from: 'Bank'
98
+
99
+ expect(page).to have_selector '#wallet'
100
+ expect(page).to have_selector '#agreement'
101
+ end
102
+
103
+ it 'should show fields of Sicredi', js: true do
104
+ select2 'Sicredi', from: 'Bank'
105
+
106
+ expect(page).to have_selector '#wallet'
107
+ expect(page).to have_selector '#byte_idt'
108
+ expect(page).to have_selector '#office_code'
109
+ end
110
+ end
111
+ end
112
+
113
+ context 'edit billet settings' do
114
+ before { visit spree.edit_admin_billet_settings_path }
115
+
116
+ it 'can edit bank', js: true do
117
+ select2 'Bradesco', from: 'Bank'
118
+ click_button 'Update'
119
+
120
+ expect(Spree::BilletConfig.bank).to eq 'bradesco'
121
+ expect(find_field('bank').value).to eq 'bradesco'
122
+
123
+ # set default
124
+ Spree::BilletConfig.bank = ''
125
+ end
126
+
127
+ {corporate_name: 'some name LTDA',
128
+ document: '123',
129
+ address: 'full address',
130
+ agency: '1234',
131
+ account: '12345',
132
+ instruction_1: '1st instruction',
133
+ instruction_2: '2nd instruction',
134
+ instruction_3: '3rd instruction',
135
+ instruction_4: '4th instruction',
136
+ instruction_5: '5th instruction',
137
+ instruction_6: '6th instruction'}.each do |key, value|
138
+ it "can edit #{key}", js: true do
139
+ fill_in key.to_s, with: value
140
+ click_button 'Update'
141
+
142
+ verify_input_value key.to_s, Spree::BilletConfig, value, ''
143
+ end
144
+ end
145
+
146
+ [{name: 'agreement', value: '123456', bank: 'Banco do Brasil'},
147
+ {name: 'wallet', value: '123', bank: 'Banco do Brasil'},
148
+ {name: 'variation_wallet', value: '1', bank: 'Banco do Brasil'},
149
+ {name: 'account_digit', value: '1', bank: 'Bradesco'},
150
+ {name: 'app_version', value: '123456', bank: 'Caixa Econômica Federal'},
151
+ {name: 'company_code', value: '1234', bank: 'Bradesco'},
152
+ {name: 'office_code', value: '12', bank: 'Sicredi'},
153
+ {name: 'byte_idt', value: '12', bank: 'Sicredi'}].each do |item|
154
+ it "can edit #{item[:name]}", js: true do
155
+ select2 item[:bank], from: 'Bank'
156
+ fill_in item[:name], with: item[:value]
157
+ click_button 'Update'
158
+
159
+ verify_input_value item[:name], Spree::BilletConfig, item[:value], ''
160
+ end
161
+ end
162
+
163
+ it 'can edit due date' do
164
+ fill_in 'due_date', with: 3
165
+ click_button 'Update'
166
+
167
+ expect(Spree::BilletConfig.due_date).to eq 3
168
+ expect(find_field('due_date').value).to eq '3'
169
+
170
+ # set default
171
+ Spree::BilletConfig.due_date = 5
172
+ end
173
+
174
+ it 'can edit acceptance', js: true do
175
+ find(:css, '#acceptance_S').set true
176
+ click_button 'Update'
177
+
178
+ expect(Spree::BilletConfig.acceptance).to eq 'S'
179
+ expect(find_field('acceptance_S')).to be_checked
180
+
181
+ # set default
182
+ Spree::BilletConfig.acceptance = 'N'
183
+ end
184
+
185
+ it 'can edit document customer attribute', js: true do
186
+ select2 'Authentication Token', from: 'Document Customer Attribute'
187
+ click_button 'Update'
188
+
189
+ expect(Spree::BilletConfig.doc_customer_attr).to eq 'authentication_token'
190
+ expect(find_field('doc_customer_attr').value).to eq 'authentication_token'
191
+
192
+ # set default
193
+ Spree::BilletConfig.doc_customer_attr = ''
194
+ end
195
+
196
+ it 'can edit if the billet is registered', js: true do
197
+ find(:css, '#registered').set false
198
+ click_button 'Update'
199
+
200
+ expect(Spree::BilletConfig.registered).to eq false
201
+ expect(find_field('registered')).not_to be_checked
202
+
203
+ # set default
204
+ Spree::BilletConfig.registered = true
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Billets Return', type: :feature do
4
+ let!(:order) { create(:order) }
5
+ let!(:payment) { create(:billet_payment, number: 'P100', order: order) }
6
+
7
+ let(:file_path) { Rails.root + '../../spec/fixtures/files/cnab240.ret' }
8
+ let(:file_path_without_return) { Rails.root + '../../spec/fixtures/files/cnab400.ret' }
9
+
10
+ before { create_admin_in_sign_in }
11
+
12
+ it 'should read return and show the paid payments', js: true do
13
+ payment
14
+ visit spree.admin_billets_return_path
15
+
16
+ find(:css, '#file_type_cnab240').set true
17
+ attach_file('file', file_path)
18
+ click_button 'Continue'
19
+
20
+ within_row(1) do
21
+ expect(column_text(1)).to eq '00000001'
22
+ expect(column_text(2)).to eq '$322.20'
23
+ expect(column_text(3)).to eq '2002-01-20'
24
+ expect(column_text(4)).to eq order.number
25
+ end
26
+ end
27
+
28
+ it 'should show an message when any billets was paid', js: true do
29
+ payment
30
+ visit spree.admin_billets_return_path
31
+
32
+ find(:css, '#file_type_cnab400').set true
33
+ attach_file('file', file_path_without_return)
34
+
35
+ click_button 'Continue'
36
+
37
+ expect(page).to have_text 'There is not return in attached file.'
38
+ end
39
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Billets Shipping', type: :feature do
4
+
5
+ before { create_admin_in_sign_in }
6
+
7
+ let!(:payment) { FactoryGirl.build(:payment, id: 1) }
8
+ let!(:billet) { FactoryGirl.build(:billet, status: 'waiting_registry', payment: payment) }
9
+
10
+ it 'should show a message when there are not any billets to registry', js: true do
11
+
12
+ visit spree.admin_billets_shipping_path
13
+
14
+ expect(page).to have_text 'No Billet found'
15
+ expect(page).not_to have_button 'Register Billets'
16
+ end
17
+
18
+ context 'with unregistered billets' do
19
+
20
+ before do
21
+ billet
22
+ allow(Spree::Billet).to receive(:unregistered).and_return([billet])
23
+ visit spree.admin_billets_shipping_path
24
+ end
25
+
26
+ it 'should show the information about unregistered billets', js: true do
27
+ expect(page).to have_button 'Register Billets'
28
+
29
+ within_row(1) do
30
+ expect(column_text(1)).to eq '1'
31
+ expect(column_text(2)).to eq billet.customer_name
32
+ expect(column_text(3)).to eq '$10.00'
33
+ expect(column_text(4)).to eq Date.today.strftime(I18n.t('date.formats.default'))
34
+ expect(column_text(5)).to eq billet.due_date.strftime(I18n.t('date.formats.default'))
35
+ end
36
+ end
37
+
38
+ it 'should show an error message when the bank is not selected', js: true do
39
+ Spree::BilletConfig.bank = ''
40
+
41
+ click_button 'Register Billets'
42
+ expect(page).to have_text 'The Bank selected in settings is not implemented!'
43
+ end
44
+
45
+ it 'should show an error message when any billets are valid', js: true do
46
+ # set the bank in billets configuration
47
+ Spree::BilletConfig.bank = 'caixa'
48
+
49
+ click_button 'Register Billets'
50
+ expect(page).to have_text 'The billets are invalid!'
51
+
52
+ # set default
53
+ Spree::BilletConfig.bank = ''
54
+ end
55
+
56
+ it 'should generate the billet', js: true do
57
+ # set the bank in billets configuration
58
+ Spree::BilletConfig.bank = 'bradesco'
59
+ Spree::BilletConfig.corporate_name = 'some name'
60
+ Spree::BilletConfig.agency = '1234'
61
+ Spree::BilletConfig.account = '123'
62
+ Spree::BilletConfig.wallet = '12'
63
+ Spree::BilletConfig.company_code = '12345'
64
+ Spree::BilletConfig.account_digit = '1'
65
+ # using authentication token to storage document customer
66
+ Spree::BilletConfig.doc_customer_attr = 'authentication_token'
67
+ billet.user.authentication_token = '123456789010'
68
+ billet.order.bill_address.zipcode = '12345678'
69
+ # stub the save method
70
+ allow(billet).to receive(:save).and_return(nil)
71
+
72
+ click_button 'Register Billets'
73
+
74
+ expect(page).not_to have_css '.alert .alert-danger'
75
+
76
+ # set default
77
+ Spree::BilletConfig.bank = ''
78
+ Spree::BilletConfig.corporate_name = ''
79
+ Spree::BilletConfig.agency = ''
80
+ Spree::BilletConfig.account = ''
81
+ Spree::BilletConfig.wallet = ''
82
+ Spree::BilletConfig.company_code = ''
83
+ Spree::BilletConfig.account_digit = ''
84
+ Spree::BilletConfig.doc_customer_attr = ''
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Checkout with Billet Payment Method', type: :feature do
4
+
5
+ include_context 'checkout setup'
6
+
7
+ context 'auto capture payment equals to false' do
8
+ before do
9
+ payment_method.auto_capture = false
10
+ payment_method.save
11
+ end
12
+
13
+ it 'should create a order with billet', js: true do
14
+ add_mug_to_cart
15
+ click_button 'Checkout'
16
+
17
+ fill_in 'order_email', :with => 'test@example.com'
18
+ click_on 'Continue'
19
+ fill_in_address
20
+
21
+ # confirm address
22
+ click_button 'Save and Continue'
23
+ # confirm shipping method
24
+ click_button 'Save and Continue'
25
+ # confirm payment method (billet)
26
+ click_button 'Save and Continue'
27
+ expect(page).to have_content 'Payment by Billet'
28
+ expect(page).to have_link 'Generate Billet'
29
+
30
+ expect(Spree::Billet.count).to eq 1
31
+
32
+ if Spree::BilletConfig.registered
33
+ expect(Spree::Billet.first.waiting_registry?).to be true
34
+ else
35
+ expect(Spree::Billet.first.pending?).to be true
36
+ end
37
+ end
38
+ end
39
+
40
+ context 'auto capture payment equals to true' do
41
+ before do
42
+ payment_method.auto_capture = true
43
+ payment_method.save
44
+ end
45
+
46
+ it 'should create a order with billet', js: true do
47
+ add_mug_to_cart
48
+ click_button 'Checkout'
49
+
50
+ fill_in 'order_email', :with => 'test@example.com'
51
+ click_on 'Continue'
52
+ fill_in_address
53
+
54
+ # confirm address
55
+ click_button 'Save and Continue'
56
+ # confirm shipping method
57
+ click_button 'Save and Continue'
58
+ # confirm payment method (billet)
59
+ click_button 'Save and Continue'
60
+ expect(page).to have_content 'Payment by Billet'
61
+
62
+ expect(Spree::Billet.count).to eq 1
63
+ expect(Spree::Billet.first.paid?).to be true
64
+ end
65
+ end
66
+
67
+ def fill_in_address
68
+ address = 'order_bill_address_attributes'
69
+ fill_in "#{address}_firstname", with: 'Ryan'
70
+ fill_in "#{address}_lastname", with: 'Bigg'
71
+ fill_in "#{address}_address1", with: '143 Swan Street'
72
+ fill_in "#{address}_city", with: 'Richmond'
73
+ select 'United States of America', from: "#{address}_country_id"
74
+ select 'Alabama', from: "#{address}_state_id"
75
+ fill_in "#{address}_zipcode", with: '12345'
76
+ fill_in "#{address}_phone", with: '(555) 555-5555'
77
+ end
78
+
79
+ def add_mug_to_cart
80
+ visit spree.root_path
81
+ click_link mug.name
82
+ click_button 'add-to-cart-button'
83
+ end
84
+ end