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.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +7 -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/clear_sale_settings/clear_sale_add_provider.js.coffee +80 -0
- data/app/assets/javascripts/spree/backend/app/clear_sale_settings/clear_sale_provider.js.coffee +27 -0
- data/app/assets/javascripts/spree/backend/app/clear_sale_settings/clear_sale_settings.js.coffee +39 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_clearsale.js +1 -0
- data/app/assets/javascripts/spree/frontend/app/addresses/phone_mask_address.js.coffee +26 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_clearsale.js +3 -0
- data/app/assets/stylesheets/spree/backend/spree_zaez_clearsale.css +18 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_clearsale.css +4 -0
- data/app/controllers/spree/admin/clear_sale_settings_controller.rb +33 -0
- data/app/controllers/spree/admin/payments_controller_decorator.rb +9 -0
- data/app/helpers/orders_helper_decorator.rb +12 -0
- data/app/models/spree/clear_sale.rb +153 -0
- data/app/models/spree/credit_card_decorator.rb +10 -0
- data/app/models/spree/payment_decorator.rb +33 -0
- data/app/overrides/spree/address/_form/add_constructor_to_form.html.erb.deface +4 -0
- data/app/overrides/spree/admin/orders/index/replace_considered_risk_column.html.erb.deface +2 -0
- data/app/overrides/spree/admin/orders/index/replace_considered_risky_label.html.erb.deface +6 -0
- data/app/overrides/spree/admin/shared/_order_tabs/add_clear_sale_iframe_to_order_menu.html.erb.deface +6 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_clear_sale_settings_tab.html.erb.deface +2 -0
- data/app/views/spree/admin/clear_sale_settings/edit.html.erb +142 -0
- data/app/views/spree/admin/payments/clear_sale.html.erb +36 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +36 -0
- data/config/locales/pt-br.yml +36 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20150608175547_add_bin_card_to_spree_credit_card.rb +5 -0
- data/db/migrate/20150611113444_add_clearsale_score_to_spree_payments.rb +5 -0
- data/lib/generators/spree_zaez_clearsale/install/install_generator.rb +31 -0
- data/lib/spree/clear_sale_configuration.rb +36 -0
- data/lib/spree_zaez_clearsale.rb +2 -0
- data/lib/spree_zaez_clearsale/engine.rb +27 -0
- data/lib/spree_zaez_clearsale/factories.rb +6 -0
- data/spec/features/admin/clear_sale_settings_spec.rb +145 -0
- data/spec/features/admin/orders/clearsale_spec.rb +60 -0
- data/spec/features/admin/orders/listing_spec.rb +47 -0
- data/spec/fixtures/clearsale_critical.txt +51 -0
- data/spec/fixtures/clearsale_high.txt +51 -0
- data/spec/fixtures/clearsale_low.txt +51 -0
- data/spec/fixtures/clearsale_medium.txt +51 -0
- data/spec/helpers/admin/orders_helper_decorator_spec.rb +32 -0
- data/spec/lib/spree/clear_sale_configuration_spec.rb +41 -0
- data/spec/models/spree/clear_sale_spec.rb +126 -0
- data/spec/models/spree/credit_card_decorator_spec.rb +11 -0
- data/spec/models/spree/payment_decorator_spec.rb +73 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/capybara_login.rb +13 -0
- data/spec/support/verify_input_field.rb +16 -0
- data/spree_zaez_clearsale.gemspec +38 -0
- data/vendor/assets/javascripts/inputmask/inputmask.min.js +10 -0
- data/vendor/assets/javascripts/inputmask/jquery.inputmask.min.js +8 -0
- metadata +76 -3
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Listing Orders', type: :feature do
|
4
|
+
|
5
|
+
let(:order1) do
|
6
|
+
create :order,
|
7
|
+
created_at: 1.day.from_now,
|
8
|
+
completed_at: 1.day.from_now,
|
9
|
+
number: 'R100'
|
10
|
+
end
|
11
|
+
let(:order2) do
|
12
|
+
create :order,
|
13
|
+
created_at: Date.today,
|
14
|
+
completed_at: Date.today,
|
15
|
+
number: 'R200'
|
16
|
+
end
|
17
|
+
let(:payment1) { FactoryGirl.build(:payment, clearsale_score: 'critical', order: order1) }
|
18
|
+
let(:payment2) { FactoryGirl.build(:payment, clearsale_score: 'low', order: order2) }
|
19
|
+
let(:payment3) { FactoryGirl.build(:payment, clearsale_score: 'high', order: order2) }
|
20
|
+
|
21
|
+
before do
|
22
|
+
create_admin_in_sign_in
|
23
|
+
order1; order2
|
24
|
+
order1.payments << payment1
|
25
|
+
order2.payments.push [payment2, payment3]
|
26
|
+
|
27
|
+
visit spree.admin_orders_path
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should replace order considered risk for ClearSale score', js: true do
|
31
|
+
expect(page).not_to have_text 'Risky'
|
32
|
+
expect(page).to have_text 'CLEARSALE SCORE'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should show the ClearSale score', js: true do
|
36
|
+
within_row(1) do
|
37
|
+
expect(find('td:nth-child(3)')).to have_css '.label-clearsale-critical'
|
38
|
+
expect(column_text(3)).to eq 'Critical'
|
39
|
+
end
|
40
|
+
|
41
|
+
within_row(2) do
|
42
|
+
expect(find('td:nth-child(3)')).to have_css '.label-clearsale-high'
|
43
|
+
expect(find('td:nth-child(3)')).to have_css '.label-clearsale-low'
|
44
|
+
expect(column_text(3)).to eq 'Low High'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
|
+
<head>
|
4
|
+
<title>Start</title>
|
5
|
+
<link href="Css/estrutura.css" rel="stylesheet" type="text/css" />
|
6
|
+
<link href="Css/tema.css" rel="stylesheet" type="text/css" />
|
7
|
+
<script src="http://js.clearsale.com.br/html4/v1/jquery.js" type="text/javascript"></script>
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(function () {
|
10
|
+
$('#logoLink').click(function () {
|
11
|
+
var url = 'http://homologacao.clearsale.com.br/Start/Pedidos/VisualizarPedido?token=xxx';
|
12
|
+
if(url.length > 0)
|
13
|
+
{
|
14
|
+
window.open(url, '_blank');
|
15
|
+
}
|
16
|
+
});
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<form method="post" action="EnviarPedido.aspx" id="ctl00">
|
22
|
+
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="xxx" />
|
23
|
+
|
24
|
+
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="04606CF5" />
|
25
|
+
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="xxx" />
|
26
|
+
<div class="divPrincipal">
|
27
|
+
<div id="cabecalho">
|
28
|
+
<div class="divLogo">
|
29
|
+
<img id="logoLink" style="cursor:pointer" alt="" class="logo" src="http://img.clearsale.com.br/logo/start.png" />
|
30
|
+
</div>
|
31
|
+
<div class="divScore score-critico">
|
32
|
+
CRÍTICO
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
<div id="conteudo">
|
37
|
+
<div id="PnlBotoes" class="divBotoes">
|
38
|
+
|
39
|
+
<input type="submit" name="BtnAprovar" value="Aprovar" onclick="return confirm($('#HdfMensagemAprovar').val());" id="BtnAprovar" class="botaoFrame botaoAprovar" />
|
40
|
+
<input type="submit" name="BtnReprovar" value="Reprovar" onclick="return confirm($('#HdfMensagemReprovar').val());" id="BtnReprovar" class="botaoFrame botaoReprovar" />
|
41
|
+
<input type="submit" name="BtnDecisao" value="Decisão Garantida" onclick="return confirm($('#HdfMensagemDecisao').val());" id="BtnDecisao" class="botaoFrame botaoDecisao" />
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
<input type="hidden" name="HdfClasseScore" id="HdfClasseScore" value="score-critico" />
|
46
|
+
<input type="hidden" name="HdfMensagemAprovar" id="HdfMensagemAprovar" value="Deseja aprovar esse pedido?" />
|
47
|
+
<input type="hidden" name="HdfMensagemReprovar" id="HdfMensagemReprovar" value="Deseja reprovar esse pedido?" />
|
48
|
+
<input type="hidden" name="HdfMensagemDecisao" id="HdfMensagemDecisao" value="Deseja enviar esse pedido para análise ClearSale? Operação sujeita a cobrança." />
|
49
|
+
</form>
|
50
|
+
</body>
|
51
|
+
</html>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
|
+
<head>
|
4
|
+
<title>Start</title>
|
5
|
+
<link href="Css/estrutura.css" rel="stylesheet" type="text/css" />
|
6
|
+
<link href="Css/tema.css" rel="stylesheet" type="text/css" />
|
7
|
+
<script src="http://js.clearsale.com.br/html4/v1/jquery.js" type="text/javascript"></script>
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(function () {
|
10
|
+
$('#logoLink').click(function () {
|
11
|
+
var url = 'http://homologacao.clearsale.com.br/Start/Pedidos/VisualizarPedido?token=xxx';
|
12
|
+
if(url.length > 0)
|
13
|
+
{
|
14
|
+
window.open(url, '_blank');
|
15
|
+
}
|
16
|
+
});
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<form method="post" action="EnviarPedido.aspx" id="ctl00">
|
22
|
+
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="xxx" />
|
23
|
+
|
24
|
+
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="04606CF5" />
|
25
|
+
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="xxx" />
|
26
|
+
<div class="divPrincipal">
|
27
|
+
<div id="cabecalho">
|
28
|
+
<div class="divLogo">
|
29
|
+
<img id="logoLink" style="cursor:pointer" alt="" class="logo" src="http://img.clearsale.com.br/logo/start.png" />
|
30
|
+
</div>
|
31
|
+
<div class="divScore score-alto">
|
32
|
+
ALTO
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
<div id="conteudo">
|
37
|
+
<div id="PnlBotoes" class="divBotoes">
|
38
|
+
|
39
|
+
<input type="submit" name="BtnAprovar" value="Aprovar" onclick="return confirm($('#HdfMensagemAprovar').val());" id="BtnAprovar" class="botaoFrame botaoAprovar" />
|
40
|
+
<input type="submit" name="BtnReprovar" value="Reprovar" onclick="return confirm($('#HdfMensagemReprovar').val());" id="BtnReprovar" class="botaoFrame botaoReprovar" />
|
41
|
+
<input type="submit" name="BtnDecisao" value="Decisão Garantida" onclick="return confirm($('#HdfMensagemDecisao').val());" id="BtnDecisao" class="botaoFrame botaoDecisao" />
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
<input type="hidden" name="HdfClasseScore" id="HdfClasseScore" value="score-critico" />
|
46
|
+
<input type="hidden" name="HdfMensagemAprovar" id="HdfMensagemAprovar" value="Deseja aprovar esse pedido?" />
|
47
|
+
<input type="hidden" name="HdfMensagemReprovar" id="HdfMensagemReprovar" value="Deseja reprovar esse pedido?" />
|
48
|
+
<input type="hidden" name="HdfMensagemDecisao" id="HdfMensagemDecisao" value="Deseja enviar esse pedido para análise ClearSale? Operação sujeita a cobrança." />
|
49
|
+
</form>
|
50
|
+
</body>
|
51
|
+
</html>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
|
+
<head>
|
4
|
+
<title>Start</title>
|
5
|
+
<link href="Css/estrutura.css" rel="stylesheet" type="text/css" />
|
6
|
+
<link href="Css/tema.css" rel="stylesheet" type="text/css" />
|
7
|
+
<script src="http://js.clearsale.com.br/html4/v1/jquery.js" type="text/javascript"></script>
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(function () {
|
10
|
+
$('#logoLink').click(function () {
|
11
|
+
var url = 'http://homologacao.clearsale.com.br/Start/Pedidos/VisualizarPedido?token=xxx';
|
12
|
+
if(url.length > 0)
|
13
|
+
{
|
14
|
+
window.open(url, '_blank');
|
15
|
+
}
|
16
|
+
});
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<form method="post" action="EnviarPedido.aspx" id="ctl00">
|
22
|
+
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="xxx" />
|
23
|
+
|
24
|
+
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="04606CF5" />
|
25
|
+
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="xxx" />
|
26
|
+
<div class="divPrincipal">
|
27
|
+
<div id="cabecalho">
|
28
|
+
<div class="divLogo">
|
29
|
+
<img id="logoLink" style="cursor:pointer" alt="" class="logo" src="http://img.clearsale.com.br/logo/start.png" />
|
30
|
+
</div>
|
31
|
+
<div class="divScore score-baixo">
|
32
|
+
BAIXO
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
<div id="conteudo">
|
37
|
+
<div id="PnlBotoes" class="divBotoes">
|
38
|
+
|
39
|
+
<input type="submit" name="BtnAprovar" value="Aprovar" onclick="return confirm($('#HdfMensagemAprovar').val());" id="BtnAprovar" class="botaoFrame botaoAprovar" />
|
40
|
+
<input type="submit" name="BtnReprovar" value="Reprovar" onclick="return confirm($('#HdfMensagemReprovar').val());" id="BtnReprovar" class="botaoFrame botaoReprovar" />
|
41
|
+
<input type="submit" name="BtnDecisao" value="Decisão Garantida" onclick="return confirm($('#HdfMensagemDecisao').val());" id="BtnDecisao" class="botaoFrame botaoDecisao" />
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
<input type="hidden" name="HdfClasseScore" id="HdfClasseScore" value="score-critico" />
|
46
|
+
<input type="hidden" name="HdfMensagemAprovar" id="HdfMensagemAprovar" value="Deseja aprovar esse pedido?" />
|
47
|
+
<input type="hidden" name="HdfMensagemReprovar" id="HdfMensagemReprovar" value="Deseja reprovar esse pedido?" />
|
48
|
+
<input type="hidden" name="HdfMensagemDecisao" id="HdfMensagemDecisao" value="Deseja enviar esse pedido para análise ClearSale? Operação sujeita a cobrança." />
|
49
|
+
</form>
|
50
|
+
</body>
|
51
|
+
</html>
|
@@ -0,0 +1,51 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
3
|
+
<head>
|
4
|
+
<title>Start</title>
|
5
|
+
<link href="Css/estrutura.css" rel="stylesheet" type="text/css" />
|
6
|
+
<link href="Css/tema.css" rel="stylesheet" type="text/css" />
|
7
|
+
<script src="http://js.clearsale.com.br/html4/v1/jquery.js" type="text/javascript"></script>
|
8
|
+
<script type="text/javascript">
|
9
|
+
$(function () {
|
10
|
+
$('#logoLink').click(function () {
|
11
|
+
var url = 'http://homologacao.clearsale.com.br/Start/Pedidos/VisualizarPedido?token=xxx';
|
12
|
+
if(url.length > 0)
|
13
|
+
{
|
14
|
+
window.open(url, '_blank');
|
15
|
+
}
|
16
|
+
});
|
17
|
+
});
|
18
|
+
</script>
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<form method="post" action="EnviarPedido.aspx" id="ctl00">
|
22
|
+
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="xxx" />
|
23
|
+
|
24
|
+
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="04606CF5" />
|
25
|
+
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="xxx" />
|
26
|
+
<div class="divPrincipal">
|
27
|
+
<div id="cabecalho">
|
28
|
+
<div class="divLogo">
|
29
|
+
<img id="logoLink" style="cursor:pointer" alt="" class="logo" src="http://img.clearsale.com.br/logo/start.png" />
|
30
|
+
</div>
|
31
|
+
<div class="divScore score-medio">
|
32
|
+
MÉDIO
|
33
|
+
</div>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
<div id="conteudo">
|
37
|
+
<div id="PnlBotoes" class="divBotoes">
|
38
|
+
|
39
|
+
<input type="submit" name="BtnAprovar" value="Aprovar" onclick="return confirm($('#HdfMensagemAprovar').val());" id="BtnAprovar" class="botaoFrame botaoAprovar" />
|
40
|
+
<input type="submit" name="BtnReprovar" value="Reprovar" onclick="return confirm($('#HdfMensagemReprovar').val());" id="BtnReprovar" class="botaoFrame botaoReprovar" />
|
41
|
+
<input type="submit" name="BtnDecisao" value="Decisão Garantida" onclick="return confirm($('#HdfMensagemDecisao').val());" id="BtnDecisao" class="botaoFrame botaoDecisao" />
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
<input type="hidden" name="HdfClasseScore" id="HdfClasseScore" value="score-critico" />
|
46
|
+
<input type="hidden" name="HdfMensagemAprovar" id="HdfMensagemAprovar" value="Deseja aprovar esse pedido?" />
|
47
|
+
<input type="hidden" name="HdfMensagemReprovar" id="HdfMensagemReprovar" value="Deseja reprovar esse pedido?" />
|
48
|
+
<input type="hidden" name="HdfMensagemDecisao" id="HdfMensagemDecisao" value="Deseja enviar esse pedido para análise ClearSale? Operação sujeita a cobrança." />
|
49
|
+
</form>
|
50
|
+
</body>
|
51
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Admin::OrdersHelper, type: :helper do
|
4
|
+
context 'verify payments registered' do
|
5
|
+
it 'should return true if one or more payments are registered in ClearSale' do
|
6
|
+
order = FactoryGirl.build(:completed_order_with_pending_payment)
|
7
|
+
order.payments << FactoryGirl.build(:check_payment)
|
8
|
+
order.payments.first.clearsale_score = 'high'
|
9
|
+
|
10
|
+
assign(:order, order)
|
11
|
+
expect(helper.payments_registered_in_clearsale?).to be true
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should return false if any payments are registered in ClearSale' do
|
15
|
+
order = FactoryGirl.build(:completed_order_with_pending_payment)
|
16
|
+
|
17
|
+
assign(:order, order)
|
18
|
+
expect(helper.payments_registered_in_clearsale?).to be false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'show ClearSale score' do
|
23
|
+
it 'should return the label of the score' do
|
24
|
+
expect(helper.clearsale_score_label('low')).to eq "<span class='label label-clearsale-low'>Low</span>"
|
25
|
+
expect(helper.clearsale_score_label('medium')).to eq "<span class='label label-clearsale-medium'>Medium</span>"
|
26
|
+
expect(helper.clearsale_score_label('high')).to eq "<span class='label label-clearsale-high'>High</span>"
|
27
|
+
expect(helper.clearsale_score_label('critical')).to eq "<span class='label label-clearsale-critical'>Critical</span>"
|
28
|
+
# if has not score
|
29
|
+
expect(helper.clearsale_score_label(nil)).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::ClearSaleConfiguration do
|
4
|
+
before do
|
5
|
+
@object = Spree::ClearSaleConfiguration.new
|
6
|
+
end
|
7
|
+
|
8
|
+
[:token, :test_mode, :providers, :doc_customer_attr,
|
9
|
+
:birth_date_customer_attr, :category_taxonomy_id].each do |preference|
|
10
|
+
it "should have the #{preference} preference" do
|
11
|
+
expect(@object.has_preference?(preference)).to be true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should show the providers in get_providers' do
|
16
|
+
@object.providers = {'some_provider' => '1'}
|
17
|
+
response = JSON.parse @object.get_providers
|
18
|
+
|
19
|
+
expect(response.first['id']).to eq 'some_provider'
|
20
|
+
expect(response.first['text']).to eq 'some_provider'
|
21
|
+
expect(response.first['payment_type']).to eq({'id' => '1', 'text' => Spree.t('payment_type_1')})
|
22
|
+
|
23
|
+
# set default
|
24
|
+
@object.providers = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'integration_url' do
|
28
|
+
it 'should return the url of production' do
|
29
|
+
@object.test_mode = false
|
30
|
+
expect(@object.integration_url).to eq 'https://www.clearsale.com.br/start/Entrada/EnviarPedido.aspx'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return the url of test' do
|
34
|
+
@object.test_mode = true
|
35
|
+
expect(@object.integration_url).to eq 'https://homolog.clearsale.com.br/start/Entrada/EnviarPedido.aspx'
|
36
|
+
|
37
|
+
# set default
|
38
|
+
@object.test_mode = false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Spree::ClearSale' do
|
4
|
+
|
5
|
+
let(:dummy_module) { Spree::ClearSale }
|
6
|
+
|
7
|
+
context 'request to ClearSale' do
|
8
|
+
let(:order) { FactoryGirl.build(:completed_order_with_pending_payment) }
|
9
|
+
let(:payment) { FactoryGirl.build(:payment, order: order, created_at: Date.today) }
|
10
|
+
|
11
|
+
it 'should send a request to ClearSale and return the score' do
|
12
|
+
stub = stub_request(:post, Spree::ClearSaleConfig.integration_url).
|
13
|
+
with(:headers => {'Accept'=>'*/*',
|
14
|
+
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
|
15
|
+
'Content-Type'=>'application/x-www-form-urlencoded',
|
16
|
+
'User-Agent'=>'Ruby'},
|
17
|
+
:body => hash_including({'CodigoIntegracao'=>Spree::ClearSaleConfig.token})).
|
18
|
+
to_return(:body => File.read('spec/fixtures/clearsale_high.txt'), :status => 200)
|
19
|
+
|
20
|
+
response = dummy_module.register_payment payment
|
21
|
+
|
22
|
+
expect(stub).to have_been_requested
|
23
|
+
expect(response).to eq 'ALTO'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'information to ClearSale' do
|
28
|
+
it 'should return the code of the credit card' do
|
29
|
+
expect(dummy_module.verify_credit_card_type('diners')).to eq 1
|
30
|
+
expect(dummy_module.verify_credit_card_type('master')).to eq 2
|
31
|
+
expect(dummy_module.verify_credit_card_type('visa')).to eq 3
|
32
|
+
expect(dummy_module.verify_credit_card_type('american_express')).to eq 5
|
33
|
+
expect(dummy_module.verify_credit_card_type('hiper_card')).to eq 6
|
34
|
+
expect(dummy_module.verify_credit_card_type('aura')).to eq 7
|
35
|
+
expect(dummy_module.verify_credit_card_type('carrefour')).to eq 8
|
36
|
+
# Other types
|
37
|
+
expect(dummy_module.verify_credit_card_type('some bank')).to eq 4
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'set params' do
|
41
|
+
let(:order) { FactoryGirl.build(:completed_order_with_pending_payment) }
|
42
|
+
let(:payment) { FactoryGirl.build(:payment, order: order, created_at: Date.today) }
|
43
|
+
|
44
|
+
it 'should set the alternative phone' do
|
45
|
+
# set the alternative phone in Spree
|
46
|
+
Spree::Config[:alternative_shipping_phone] = true
|
47
|
+
params = dummy_module.set_request_params payment
|
48
|
+
|
49
|
+
expect(params.has_key?(:Cobranca_DDD_Telefone_2)).to be true
|
50
|
+
expect(params.has_key?(:Cobranca_Telefone_2)).to be true
|
51
|
+
expect(params.has_key?(:Entrega_DDD_Telefone_2)).to be true
|
52
|
+
expect(params.has_key?(:Entrega_Telefone_2)).to be true
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should show all line items' do
|
56
|
+
line_item1 = FactoryGirl.build(:line_item, order: order, quantity: 1, price: 10)
|
57
|
+
line_item2 = FactoryGirl.build(:line_item, order: order, quantity: 2, price: 7)
|
58
|
+
order.line_items.push [line_item1, line_item2]
|
59
|
+
params = dummy_module.set_request_params payment
|
60
|
+
|
61
|
+
order.line_items.each_with_index do |item, cont|
|
62
|
+
expect(params["Item_ID_#{cont+1}".to_sym]).to eq item.variant.id
|
63
|
+
expect(params["Item_Nome_#{cont+1}".to_sym]).to eq item.variant.name
|
64
|
+
expect(params["Item_Qtd_#{cont+1}".to_sym]).to eq item.quantity
|
65
|
+
expect(params["Item_Valor_#{cont+1}".to_sym]).to eq item.price.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'category of the product' do
|
70
|
+
|
71
|
+
let(:taxon) { FactoryGirl.build(:taxon, name: 'Bags') }
|
72
|
+
let(:product) { FactoryGirl.build(:product, taxons: [taxon]) }
|
73
|
+
let(:line_item) { FactoryGirl.build(:line_item, order: order, quantity: 1, price: 20, variant: product.master) }
|
74
|
+
|
75
|
+
before { order.line_items << line_item }
|
76
|
+
|
77
|
+
it 'should set the first taxon to category when category taxonomy is not defined' do
|
78
|
+
# default
|
79
|
+
Spree::ClearSaleConfig.category_taxonomy_id = 0
|
80
|
+
|
81
|
+
params = dummy_module.set_request_params payment
|
82
|
+
|
83
|
+
expect(params[:Item_Categoria_1]).to eq 'Bags'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should set the first taxon which represents the category taxonomy' do
|
87
|
+
taxonomy = FactoryGirl.build(:taxonomy, name: 'Categories', id: 1)
|
88
|
+
category_taxon = FactoryGirl.build(:taxon, name: 'Shirts', taxonomy: taxonomy)
|
89
|
+
product.taxons << category_taxon
|
90
|
+
Spree::ClearSaleConfig.category_taxonomy_id = taxonomy.id
|
91
|
+
|
92
|
+
# stub method :where of taxons
|
93
|
+
allow(product.taxons).to receive(:where).and_return([category_taxon])
|
94
|
+
params = dummy_module.set_request_params payment
|
95
|
+
|
96
|
+
expect(params[:Item_Categoria_1]).to eq 'Shirts'
|
97
|
+
|
98
|
+
# set default
|
99
|
+
Spree::ClearSaleConfig.category_taxonomy_id = 0
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'set credit card information' do
|
104
|
+
it 'should set credit card information if the payment method is credit card' do
|
105
|
+
pay_credit_card = FactoryGirl.build(:payment, order: order, created_at: Date.today)
|
106
|
+
params = dummy_module.set_request_params pay_credit_card
|
107
|
+
|
108
|
+
expect(params[:TipoCartao]).to eq dummy_module.verify_credit_card_type(pay_credit_card.source.cc_type)
|
109
|
+
expect(params[:Cartao_Bin]).to eq pay_credit_card.source.bin_card
|
110
|
+
expect(params[:Cartao_Fim]).to eq pay_credit_card.source.last_digits
|
111
|
+
expect(params[:Cartao_Numero_Mascarado]).to eq "#{pay_credit_card.source.bin_card}******#{pay_credit_card.source.last_digits}"
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should not set credit card information if the payment method is not credit card' do
|
115
|
+
pay_check = FactoryGirl.build(:check_payment, order: order, created_at: Date.today)
|
116
|
+
params = dummy_module.set_request_params pay_check
|
117
|
+
|
118
|
+
expect(params[:TipoCartao]).to be_blank
|
119
|
+
expect(params[:Cartao_Bin]).to be_blank
|
120
|
+
expect(params[:Cartao_Fim]).to be_blank
|
121
|
+
expect(params[:Cartao_Numero_Mascarado]).to be_blank
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|