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.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +11 -0
- data/Guardfile +90 -0
- data/LICENSE +26 -0
- data/README.md +81 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/app/billet_settings/billet_setting.js.coffee +66 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_billet.js +1 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_billet.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_billet.css +3 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_billet.css +4 -0
- data/app/controllers/spree/admin/billet_settings_controller.rb +29 -0
- data/app/controllers/spree/admin/billets_controller.rb +61 -0
- data/app/controllers/spree/billets_controller.rb +35 -0
- data/app/models/spree/address_decorator.rb +17 -0
- data/app/models/spree/billet.rb +257 -0
- data/app/models/spree/payment_method/billet.rb +83 -0
- data/app/overrides/spree/admin/shared/_main_menu/add_payment_tab_to_main_menu.html.erb.deface +6 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_billet_settings_tab.html.erb.deface +2 -0
- data/app/overrides/spree/payments/_payment/add_billet_info_to_order_details.html.erb.deface +6 -0
- data/app/views/spree/admin/billet_settings/edit.html.erb +154 -0
- data/app/views/spree/admin/billets/return.html.erb +40 -0
- data/app/views/spree/admin/billets/return_info.html.erb +32 -0
- data/app/views/spree/admin/billets/shipping.html.erb +39 -0
- data/app/views/spree/admin/payments/source_forms/_billet.html.erb +4 -0
- data/app/views/spree/admin/payments/source_views/_billet.html.erb +39 -0
- data/app/views/spree/admin/shared/sub_menu/_payment.html.erb +4 -0
- data/app/views/spree/checkout/payment/_billet.html.erb +4 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +58 -0
- data/config/locales/pt-br.yml +57 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20150617193744_create_spree_billets.rb +14 -0
- data/lib/generators/spree_zaez_billet/install/install_generator.rb +31 -0
- data/lib/spree/billet_configuration.rb +31 -0
- data/lib/spree_zaez_billet.rb +5 -0
- data/lib/spree_zaez_billet/engine.rb +31 -0
- data/lib/spree_zaez_billet/factories.rb +34 -0
- data/spec/features/admin/billet_payments_spec.rb +85 -0
- data/spec/features/admin/billet_settings_spec.rb +207 -0
- data/spec/features/admin/billets_return_spec.rb +39 -0
- data/spec/features/admin/billets_shipping_spec.rb +87 -0
- data/spec/features/checkout_with_billet_spec.rb +84 -0
- data/spec/fixtures/files/cnab240.ret +16 -0
- data/spec/fixtures/files/cnab400.ret +54 -0
- data/spec/lib/spree/billet_configuration_spec.rb +14 -0
- data/spec/models/spree/address_decorator_spec.rb +13 -0
- data/spec/models/spree/billet_spec.rb +366 -0
- data/spec/spec_helper.rb +95 -0
- data/spec/support/capybara_login.rb +13 -0
- data/spec/support/shared_contexts/checkout_setup.rb +10 -0
- data/spec/support/verify_input_field.rb +16 -0
- data/spree_zaez_billet.gemspec +38 -0
- metadata +72 -3
@@ -0,0 +1,16 @@
|
|
1
|
+
00100000 2356438990001450019999570014 0123450000000054321 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxBANCO DO BRASIL 22912201101431900210803000000920674440PROCESSAMEN
|
2
|
+
00100011T0100020 20356438990001450019999570014 0123450000000054321 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 000000002912201100000000 000000000
|
3
|
+
0010001300001T 170123450000000054321 14499570000000005 7 00000000000000000034400001020850 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
4
|
+
0010001300002U 170000000000000090000000000000010000000000000020000000000000030000000000344000000000000342970000000000000040000000000000052912201102012012 000000000000000 000
|
5
|
+
0010001300003T 170123450000000054321 14499570000000001 7 00000000000000000032117237003210 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
6
|
+
0010001300004U 170000000000000000000000000000000000000000000000000000000000000000000000321170000000000320140000000000000000000000000000002912201102012012 000000000000000 000
|
7
|
+
0010001300005T 170123450000000054321 14499570000000002 7 00000000000000000075147237003210 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
8
|
+
0010001300006U 170000000000000000000000000000000000000000000000000000000000000000000000751470000000000750440000000000000000000000000000002912201102012012 000000000000000 000
|
9
|
+
0010001300007T 170123450000000054321 14499570000000003 7 00000000000000000086618001043915 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
10
|
+
0010001300008U 170000000000000000000000000000000000000000000000000000000000000000000000866180000000000865150000000000000000000000000000002912201102012012 000000000000000 000
|
11
|
+
0010001300009T 170123450000000054321 14499570000000004 7 00000000000000000083000237021340 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
12
|
+
0010001300010U 170000000000000000000000000000000000000000000000000000000000000000000000830000000000000828970000000000000000000000000000002912201102012012 000000000000000 000
|
13
|
+
0010001300011T 170123450000000054321 14499570000000006 7 00000000000000000206255237011020 0900000000000000000000000000000000000000000000000000000 000000000000000000000010303 170191449957
|
14
|
+
0010001300012U 170000000000000000000000000000000000000000000000000000000000000000000002062550000000002061520000000000000000000000000000002912201102012012 000000000000000 000
|
15
|
+
00100015 000072000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
16
|
+
00199999 000001000074000000 00000000000000000000000000000
|
@@ -0,0 +1,54 @@
|
|
1
|
+
02RETORNO01COBRANCA 073000035110 PLUTO ALTO ELENTAS LTDA ME 341BANCO ITAU S.A.20051301600BPI00025210513 000001
|
2
|
+
10216733872000107073000035110 00000011 109000000114 I06200513 00000011 000000000000000400010418739 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000002
|
3
|
+
10216733872000107073000035110 00000035 109000000353 I06200513 00000035 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000003
|
4
|
+
10216733872000107073000035110 00000052 109000000528 I06200513 00000052 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000004
|
5
|
+
10216733872000107073000035110 00000107 109000001070 I06200513 00000107 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000005
|
6
|
+
10216733872000107073000035110 00000139 109000001393 I06200513 00000139 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000006
|
7
|
+
10216733872000107073000035110 00000195 109000001955 I06200513 00000195 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000007
|
8
|
+
10216733872000107073000035110 00000267 109000002672 I06200513 00000267 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000008
|
9
|
+
10216733872000107073000035110 00000331 109000003316 I06200513 00000331 000000000000000400010404085 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000009
|
10
|
+
10216733872000107073000035110 00000541 109000005410 I06200513 00000541 000000000000001050010417848 000000000021000000000000000000000000000000000000000000000000000000000000000000000000001029000000000000000000000000000 21051300000000000000000000000 B5000010
|
11
|
+
10216733872000107073000035110 00000890 109000008901 I06200513 00000890 000000000000000400010418754 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000011
|
12
|
+
10216733872000107073000035110 00000956 109000009560 I06200513 00000956 000000000000000750010417848 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000729000000000000000000000000000 21051300000000000000000000000 B5000012
|
13
|
+
10216733872000107073000035110 00000975 109000009750 I06200513 00000975 000000000000000750010417848 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000729000000000000000000000000000 21051300000000000000000000000 B2000013
|
14
|
+
10216733872000107073000035110 00001036 109000010360 I06200513 00001036 000000000000000210034178584 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000189000000000000000000000000000 21051300000000000000000000000 CP000014
|
15
|
+
10216733872000107073000035110 00001052 109000010527 I06200513 00001052 000000000000000840010417848 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000819000000000000000000000000000 21051300000000000000000000000 B5000015
|
16
|
+
10216733872000107073000035110 00001109 109000011095 I06200513 00001109 000000000000000460010436921 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000439000000000000000000000000000 21051300000000000000000000000 B5000016
|
17
|
+
10216733872000107073000035110 00001123 109000011236 I06200513 00001123 000000000000000400010418754 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000017
|
18
|
+
10216733872000107073000035110 00001206 109000012069 I06200513 00001206 000000000000000400010418754 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000018
|
19
|
+
10216733872000107073000035110 00001324 109000013240 I06200513 00001324 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000019
|
20
|
+
10216733872000107073000035110 00001351 109000013513 I06200513 00001351 000000000000000400023729371 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B2000020
|
21
|
+
10216733872000107073000035110 00001372 109000013729 I06200513 00001372 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000021
|
22
|
+
10216733872000107073000035110 00001373 109000013737 I06200513 00001373 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000022
|
23
|
+
10216733872000107073000035110 00001380 109000013802 I06200513 00001380 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000023
|
24
|
+
10216733872000107073000035110 00001458 109000014586 I06200513 00001458 000000000000000400000152480 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000024
|
25
|
+
10216733872000107073000035110 00001498 109000014982 I06200513 00001498 000000000000000400034102899 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 AA000025
|
26
|
+
10216733872000107073000035110 00001698 109000016987 I06200513 00001698 000000000000000191010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000 21051300000000000000000000000 B5000026
|
27
|
+
10216733872000107073000035110 00002129 109000021292 I06200513 00002129 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000027
|
28
|
+
10216733872000107073000035110 00002236 109000022365 I06200513 00002236 000000000000000400010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000028
|
29
|
+
10216733872000107073000035110 00002260 109000022605 I06200513 00002260 000000000000000400010436921 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B2000029
|
30
|
+
10216733872000107073000035110 00002274 109000022746 I06200513 00002274 000000000000000400034186686 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 CP000030
|
31
|
+
10216733872000107073000035110 00002286 109000022860 I06200513 00002286 000000000000000400010436921 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000031
|
32
|
+
10216733872000107073000035110 00002311 109000023116 I06200513 00002311 000000000000000400010418770 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000379000000000000000000000000000 21051300000000000000000000000 B5000032
|
33
|
+
10216733872000107073000035110 00002586 109000025863 I06200513 00002586 000000000000000640010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000619000000000000000000000000000 21051300000000000000000000000 B5000033
|
34
|
+
10216733872000107073000035110 00002597 109000025970 I06200513 00002597 000000000000000440000126385 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B5000034
|
35
|
+
10216733872000107073000035110 00002601 109000026010 I06200513 00002601 000000000000000440010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B5000035
|
36
|
+
10216733872000107073000035110 00002607 109000026077 I06200513 00002607 000000000000000440010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B5000036
|
37
|
+
10216733872000107073000035110 00002617 109000026176 I06200513 00002617 000000000000000440000148322 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B1000037
|
38
|
+
10216733872000107073000035110 00002627 109000026275 I06200513 00002627 000000000000000440000148298 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B1000038
|
39
|
+
10216733872000107073000035110 00002668 109000026689 I06200513 00002668 000000000000000440023729371 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B3000039
|
40
|
+
10216733872000107073000035110 00002674 109000026747 I06200513 00002674 000000000000000440010404085 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B5000040
|
41
|
+
10216733872000107073000035110 00002721 109000027216 I06200513 00002721 000000000000000440010415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B5000041
|
42
|
+
10216733872000107073000035110 00003136 109000031366 I06200513 00003136 000000000000000487534148272 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000476700000000001020000000000000 21051300000000000000000000000 CP000042
|
43
|
+
10216733872000107073000035110 00003238 109000032380 I06200513 00003238 000000000000003500000130478 000000000021000000000000000000000000000000000000000000000000000000000000000000000000003479000000000000000000000000000 21051300000000000000000000000 B2000043
|
44
|
+
10216733872000107073000035110 00003344 109000033446 I06200513 00003344 000000000000000440000148298 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 B1000044
|
45
|
+
10216733872000107073000035110 00003391 109000033917 I06200513 00003391 000000000000000440034186132 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000419000000000000000000000000000 21051300000000000000000000000 BL000045
|
46
|
+
10216733872000107073000035110 00003456 109000034568 I06200513 00003456 000000000000000571534102899 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000562200000000001170000000000000 21051300000000000000000000000 CP000046
|
47
|
+
10216733872000107073000035110 00003505 109000035052 I06200513 00003505 000000000000000457100148322 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000436100000000000000000000000000 21051300000000000000000000000 B1000047
|
48
|
+
10216733872000107073000035110 00003925 109000039252 I06200513 00003925 000000000000000571034165466 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000561900000000001190000000000000 21051300000000000000000000000 CP000048
|
49
|
+
10216733872000107073000035110 00004012 109000040128 I06200513 00004012 000000000000000500010430783 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000479000000000000000000000000000 21051300000000000000000000000 B5000049
|
50
|
+
10216733872000107073000035110 00004019 109000040193 I06200513 00004019 000000000000000571510415552 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000550500000000000000000000000000 21051300000000000000000000000 B5000050
|
51
|
+
10216733872000107073000035110 00004026 109000040268 I06200513 00004026 000000000000000500039913003 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000479000000000000000000000000000 21051300000000000000000000000 B3000051
|
52
|
+
10216733872000107073000035110 27615123 157276151236 I06200513000000108927615123 100513000000000440034165466 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000428800000000000980000000000000 21051300000000000000000000000DIVA LOUZAMARA DO CASTO BLITTO CP000052
|
53
|
+
10216733872000107073000035110 27714592 157277145922 I09200513000000206827714592 100513000000000400034177099 000000000021000000000000000000000000000000000000000000000000000000000000000000000000000021000000000000000000000000000 00000000000000000000000MIRCALO TIADORO 000053
|
54
|
+
9201341 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 0000003200000000148705 21/05S000250000005200000000268896 000054
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::BilletConfiguration do
|
4
|
+
|
5
|
+
let(:config) { Spree::BilletConfiguration.new }
|
6
|
+
|
7
|
+
[:bank, :corporate_name, :document, :address, :agency, :account, :agreement, :wallet,
|
8
|
+
:variation_wallet, :due_date, :acceptance, :instruction_1, :instruction_2, :instruction_3,
|
9
|
+
:instruction_4, :instruction_5, :instruction_6, :doc_customer_attr].each do |preference|
|
10
|
+
it "should has the #{preference} preference" do
|
11
|
+
expect(config.has_preference?(preference)).to be true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Address do
|
4
|
+
|
5
|
+
context 'full address' do
|
6
|
+
let(:address) { FactoryGirl.build(:address, address1: 'street', address2: 'district', city: 'city', zipcode: '12345') }
|
7
|
+
|
8
|
+
it 'should show the full address' do
|
9
|
+
state_abbr = address.state.abbr
|
10
|
+
expect(address.full_address).to eq "street, district - 12345 - city/#{state_abbr}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,366 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Billet do
|
4
|
+
|
5
|
+
let(:payment) { FactoryGirl.build(:payment) }
|
6
|
+
let(:billet) { FactoryGirl.build(:billet, status: 'pending', payment: payment) }
|
7
|
+
|
8
|
+
it 'should return true when billet is pending' do
|
9
|
+
expect(billet.pending?).to be true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return true when billet is paid' do
|
13
|
+
billet.status = 'paid'
|
14
|
+
expect(billet.paid?).to be true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should return true when billet is waiting registry' do
|
18
|
+
billet.status = 'waiting_registry'
|
19
|
+
expect(billet.waiting_registry?).to be true
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return if the document can be generated' do
|
23
|
+
billet.status = 'waiting_registry'
|
24
|
+
expect(billet.can_generate_document?).to be true
|
25
|
+
billet.status = 'pending'
|
26
|
+
expect(billet.can_generate_document?).to be true
|
27
|
+
|
28
|
+
# when is void or paid
|
29
|
+
billet.status = 'void'
|
30
|
+
expect(billet.can_generate_document?).to be false
|
31
|
+
billet.status = 'paid'
|
32
|
+
expect(billet.can_generate_document?).to be false
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should change the status to pending' do
|
36
|
+
billet.status = 'void'
|
37
|
+
# stub the save method
|
38
|
+
allow(billet).to receive(:save).and_return(nil)
|
39
|
+
billet.to_pending!
|
40
|
+
expect(billet.status).to eq 'pending'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should return the customer name' do
|
44
|
+
bill_address = billet.order.bill_address
|
45
|
+
bill_address.firstname = 'name'
|
46
|
+
bill_address.lastname = 'lastname'
|
47
|
+
|
48
|
+
expect(billet.customer_name).to eq 'name lastname'
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should return the due date' do
|
52
|
+
Spree::BilletConfig.due_date = 1
|
53
|
+
|
54
|
+
expect(billet.due_date).to eq(Date.today + 1.days)
|
55
|
+
|
56
|
+
# set default
|
57
|
+
Spree::BilletConfig.due_date = 5
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'actions options' do
|
61
|
+
it 'should return when can capture the billet' do
|
62
|
+
payment.state = 'checkout'
|
63
|
+
expect(billet.can_capture?(payment)).to be true
|
64
|
+
|
65
|
+
payment.state = 'pending'
|
66
|
+
expect(billet.can_capture?(payment)).to be true
|
67
|
+
|
68
|
+
payment.state = 'void'
|
69
|
+
expect(billet.can_capture?(payment)).to be false
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should return when can void the billet' do
|
73
|
+
payment.state = 'checkout'
|
74
|
+
expect(billet.can_void?(payment)).to be true
|
75
|
+
|
76
|
+
payment.state = 'pending'
|
77
|
+
expect(billet.can_void?(payment)).to be true
|
78
|
+
|
79
|
+
payment.state = 'processing'
|
80
|
+
expect(billet.can_void?(payment)).to be true
|
81
|
+
|
82
|
+
payment.state = 'void'
|
83
|
+
expect(billet.can_void?(payment)).to be false
|
84
|
+
|
85
|
+
payment.state = 'failure'
|
86
|
+
expect(billet.can_void?(payment)).to be false
|
87
|
+
|
88
|
+
payment.state = 'invalid'
|
89
|
+
expect(billet.can_void?(payment)).to be false
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'should return the actions to payment according to state' do
|
93
|
+
payment.state = 'checkout'
|
94
|
+
expect(billet.actions).to eq %w(capture void)
|
95
|
+
|
96
|
+
payment.state = 'processing'
|
97
|
+
expect(billet.actions).to eq %w(void)
|
98
|
+
|
99
|
+
payment.state = 'void'
|
100
|
+
expect(billet.actions).to eq []
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'displaying amount' do
|
105
|
+
let(:order_currency) { FactoryGirl.build(:order, currency: 'USD') }
|
106
|
+
let(:billet_with_order) { FactoryGirl.build(:billet, amount: 12.0, order: order_currency) }
|
107
|
+
|
108
|
+
it 'should return the currency according to order' do
|
109
|
+
expect(billet_with_order.currency).to eq 'USD'
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should return amount converted to money according to currency' do
|
113
|
+
amount = billet_with_order.display_amount
|
114
|
+
expect(amount).to eq(Spree::Money.new(billet_with_order.amount))
|
115
|
+
expect(amount.to_html).to eq '$12.00'
|
116
|
+
|
117
|
+
# modifying the currency
|
118
|
+
order_currency.currency = 'BRL'
|
119
|
+
new_amount = billet_with_order.display_amount
|
120
|
+
expect(new_amount.to_html).to eq 'R$12.00'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# tests from spree/core/spec/models/spree/payment_spec
|
125
|
+
describe '#amount=' do
|
126
|
+
before do
|
127
|
+
subject.amount = amount
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when the amount is a string' do
|
131
|
+
context 'amount is a decimal' do
|
132
|
+
let(:amount) { '2.99' }
|
133
|
+
|
134
|
+
it '#amount' do
|
135
|
+
expect(subject.amount).to eq BigDecimal('2.99')
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context 'amount is an integer' do
|
140
|
+
let(:amount) { '2' }
|
141
|
+
|
142
|
+
it '#amount' do
|
143
|
+
expect(subject.amount).to eq BigDecimal('2.0')
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'amount contains a dollar sign' do
|
148
|
+
let(:amount) { '$2.99' }
|
149
|
+
|
150
|
+
it '#amount' do
|
151
|
+
expect(subject.amount).to eq BigDecimal('2.99')
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'amount contains a comma' do
|
156
|
+
let(:amount) { '$2,999.99' }
|
157
|
+
|
158
|
+
it '#amount' do
|
159
|
+
expect(subject.amount).to eq BigDecimal('2999.99')
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'amount contains a negative sign' do
|
164
|
+
let(:amount) { '-2.99' }
|
165
|
+
|
166
|
+
it '#amount' do
|
167
|
+
expect(subject.amount).to eq BigDecimal('-2.99')
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context 'amount is invalid' do
|
172
|
+
let(:amount) { 'invalid' }
|
173
|
+
|
174
|
+
it '#amount' do
|
175
|
+
expect(subject.amount).to eq BigDecimal('0')
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'amount is an empty string' do
|
180
|
+
let(:amount) { '' }
|
181
|
+
|
182
|
+
it '#amount' do
|
183
|
+
expect(subject.amount).to be_nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'when the amount is a number' do
|
189
|
+
let(:amount) { 1.55 }
|
190
|
+
|
191
|
+
it '#amount' do
|
192
|
+
expect(subject.amount).to eq BigDecimal('1.55')
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'generating billet document' do
|
198
|
+
|
199
|
+
let(:order) { FactoryGirl.build(:order) }
|
200
|
+
|
201
|
+
before(:all) do
|
202
|
+
Spree::BilletConfig.corporate_name = 'some name'
|
203
|
+
Spree::BilletConfig.document = '12345'
|
204
|
+
Spree::BilletConfig.address = 'full address'
|
205
|
+
Spree::BilletConfig.agency = '1234'
|
206
|
+
Spree::BilletConfig.account = '123'
|
207
|
+
Spree::BilletConfig.agreement = '123456'
|
208
|
+
Spree::BilletConfig.wallet = '212'
|
209
|
+
Spree::BilletConfig.variation_wallet = '12'
|
210
|
+
Spree::BilletConfig.instruction_1 = '1st instruction'
|
211
|
+
Spree::BilletConfig.instruction_2 = '2nd instruction'
|
212
|
+
Spree::BilletConfig.instruction_3 = '3rd instruction'
|
213
|
+
Spree::BilletConfig.instruction_4 = '4th instruction'
|
214
|
+
Spree::BilletConfig.instruction_5 = '5th instruction'
|
215
|
+
Spree::BilletConfig.instruction_6 = '6th instruction'
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'should generate the document' do
|
219
|
+
order.payments << payment
|
220
|
+
Spree::BilletConfig.bank = 'banco_brasil'
|
221
|
+
|
222
|
+
document = billet.generate_document
|
223
|
+
|
224
|
+
expect(document.cedente).to eq 'some name'
|
225
|
+
expect(document.documento_cedente).to eq '12345'
|
226
|
+
expect(document.cedente_endereco).to eq 'full address'
|
227
|
+
expect(document.sacado).to eq "#{order.bill_address.firstname} #{order.bill_address.lastname}"
|
228
|
+
expect(document.sacado_documento).to eq billet.user.attributes[Spree::BilletConfig.doc_customer_attr]
|
229
|
+
expect(document.sacado_endereco).to eq order.bill_address.full_address
|
230
|
+
expect(document.numero_documento).to eq '00001' # 5 posicoes quando o convenio tem 6 digitos para BB
|
231
|
+
expect(document.dias_vencimento).to eq 5 # dias padrão
|
232
|
+
expect(document.data_documento).to eq Date.today
|
233
|
+
expect(document.valor).to eq 10.0
|
234
|
+
expect(document.aceite).to eq 'N'
|
235
|
+
expect(document.agencia).to eq '1234'
|
236
|
+
expect(document.conta_corrente).to eq '00000123' # 8 digitos
|
237
|
+
expect(document.convenio).to eq '123456'
|
238
|
+
expect(document.carteira).to eq '212'
|
239
|
+
expect(document.variacao).to eq '12'
|
240
|
+
expect(document.instrucao1).to eq '1st instruction'
|
241
|
+
expect(document.instrucao2).to eq '2nd instruction'
|
242
|
+
expect(document.instrucao3).to eq '3rd instruction'
|
243
|
+
expect(document.instrucao4).to eq '4th instruction'
|
244
|
+
expect(document.instrucao5).to eq '5th instruction'
|
245
|
+
expect(document.instrucao6).to eq '6th instruction'
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'different banks' do
|
249
|
+
|
250
|
+
{'banco_brasil' => Brcobranca::Boleto::BancoBrasil,
|
251
|
+
'bradesco' => Brcobranca::Boleto::Bradesco,
|
252
|
+
'caixa' => Brcobranca::Boleto::Caixa,
|
253
|
+
'santander' => Brcobranca::Boleto::Santander,
|
254
|
+
'itau' => Brcobranca::Boleto::Itau,
|
255
|
+
'sicredi' => Brcobranca::Boleto::Sicredi}.each do |key, value|
|
256
|
+
|
257
|
+
it "should return object #{value}" do
|
258
|
+
order.payments << payment
|
259
|
+
Spree::BilletConfig.bank = key
|
260
|
+
document = billet.generate_document
|
261
|
+
|
262
|
+
expect(document.is_a?(value)).to be true
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'raise an error when ay bank is set' do
|
267
|
+
order.payments << payment
|
268
|
+
Spree::BilletConfig.bank = ''
|
269
|
+
expect { billet.generate_document }.to raise_error('It is necessary set the billet config')
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context 'generating shipping file' do
|
275
|
+
before(:all) do
|
276
|
+
Spree::BilletConfig.corporate_name = 'some name'
|
277
|
+
Spree::BilletConfig.document = '12345678910'
|
278
|
+
Spree::BilletConfig.address = 'full address'
|
279
|
+
Spree::BilletConfig.agency = '1234'
|
280
|
+
Spree::BilletConfig.account = '123'
|
281
|
+
Spree::BilletConfig.agreement = '123456'
|
282
|
+
Spree::BilletConfig.wallet = '212'
|
283
|
+
Spree::BilletConfig.variation_wallet = '12'
|
284
|
+
Spree::BilletConfig.account_digit = '1'
|
285
|
+
# using authentication token to storage document customer
|
286
|
+
Spree::BilletConfig.doc_customer_attr = 'authentication_token'
|
287
|
+
end
|
288
|
+
|
289
|
+
def prepare_object
|
290
|
+
Spree::BilletConfig.bank = 'itau'
|
291
|
+
billet.status = 'waiting_registry'
|
292
|
+
billet.user.authentication_token = '12345678910'
|
293
|
+
billet.order.bill_address.zipcode = '12345678'
|
294
|
+
|
295
|
+
# stub the scope and the save method
|
296
|
+
allow(Spree::Billet).to receive(:unregistered).and_return([billet])
|
297
|
+
allow(billet).to receive(:save).and_return(nil)
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'shipping number should iterate when shipping is generated' do
|
301
|
+
prepare_object
|
302
|
+
number = Spree::BilletConfig.shipping_number
|
303
|
+
_shipping = Spree::Billet.generate_shipping
|
304
|
+
|
305
|
+
expect(Spree::BilletConfig.shipping_number).to eq(number + 1)
|
306
|
+
end
|
307
|
+
|
308
|
+
it 'should return shipping' do
|
309
|
+
prepare_object
|
310
|
+
shipping = Spree::Billet.generate_shipping
|
311
|
+
|
312
|
+
expect(shipping.class).to eq String
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'the status of billets should change to pending' do
|
316
|
+
prepare_object
|
317
|
+
_shipping = Spree::Billet.generate_shipping
|
318
|
+
|
319
|
+
expect(billet.status).to eq 'pending'
|
320
|
+
end
|
321
|
+
|
322
|
+
context 'raise errors' do
|
323
|
+
it 'should return an error when any bank is selected' do
|
324
|
+
prepare_object
|
325
|
+
Spree::BilletConfig.bank = ''
|
326
|
+
shipping = Spree::Billet.generate_shipping
|
327
|
+
|
328
|
+
expect(shipping[:reason]).to eq :billet_bank_not_implemented
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'should return an error when any billet is unregistered' do
|
332
|
+
shipping = Spree::Billet.generate_shipping
|
333
|
+
|
334
|
+
expect(shipping[:reason]).to eq :there_are_not_any_billets_to_registry
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should return an error when the billets are invalid' do
|
338
|
+
prepare_object
|
339
|
+
billet.order.bill_address.zipcode = '123'
|
340
|
+
shipping = Spree::Billet.generate_shipping
|
341
|
+
|
342
|
+
expect(shipping[:reason]).to eq :invalid_billets
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
after(:all) do
|
348
|
+
Spree::BilletConfig.bank = ''
|
349
|
+
Spree::BilletConfig.corporate_name = ''
|
350
|
+
Spree::BilletConfig.document = ''
|
351
|
+
Spree::BilletConfig.address = ''
|
352
|
+
Spree::BilletConfig.agency = ''
|
353
|
+
Spree::BilletConfig.account = ''
|
354
|
+
Spree::BilletConfig.agreement = ''
|
355
|
+
Spree::BilletConfig.wallet = ''
|
356
|
+
Spree::BilletConfig.variation_wallet = ''
|
357
|
+
Spree::BilletConfig.account_digit = ''
|
358
|
+
Spree::BilletConfig.doc_customer_attr = ''
|
359
|
+
Spree::BilletConfig.instruction_1 = ''
|
360
|
+
Spree::BilletConfig.instruction_2 = ''
|
361
|
+
Spree::BilletConfig.instruction_3 = ''
|
362
|
+
Spree::BilletConfig.instruction_4 = ''
|
363
|
+
Spree::BilletConfig.instruction_5 = ''
|
364
|
+
Spree::BilletConfig.instruction_6 = ''
|
365
|
+
end
|
366
|
+
end
|