spree_zaez_komerci 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +9 -0
- data/Guardfile +90 -0
- data/LICENSE +26 -0
- data/README.md +52 -0
- data/Rakefile +21 -0
- data/app/assets/images/rede-credit-cards/rede-dinersclub.png +0 -0
- data/app/assets/images/rede-credit-cards/rede-hipercard.png +0 -0
- data/app/assets/images/rede-credit-cards/rede-jcb.png +0 -0
- data/app/assets/images/rede-credit-cards/rede-mastercard.png +0 -0
- data/app/assets/images/rede-credit-cards/rede-visa.png +0 -0
- data/app/assets/javascripts/spree/backend/spree_zaez_komerci.js +1 -0
- data/app/assets/javascripts/spree/frontend/app/komerci_credit_card.js.coffee +26 -0
- data/app/assets/javascripts/spree/frontend/spree_zaez_komerci.js +1 -0
- data/app/assets/stylesheets/spree/frontend/spree_zaez_komerci.css +7 -0
- data/app/controllers/spree/admin/komerci_settings_controller.rb +20 -0
- data/app/models/spree/credit_card_decorator.rb +7 -0
- data/app/models/spree/komerci_transaction.rb +8 -0
- data/app/models/spree/payment/gateway_options_decorator.rb +14 -0
- data/app/models/spree/payment_method/komerci.rb +250 -0
- data/app/overrides/spree/admin/shared/sub_menu/_configuration/add_komerci_settings_to_configuration_tab.html.erb.deface +2 -0
- data/app/views/spree/admin/komerci_settings/edit.html.erb +67 -0
- data/app/views/spree/admin/payments/source_forms/_komerci.html.erb +62 -0
- data/app/views/spree/admin/payments/source_views/_komerci.html.erb +33 -0
- data/app/views/spree/checkout/payment/_komerci.html.erb +62 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +31 -0
- data/config/locales/pt-br.yml +32 -0
- data/config/routes.rb +5 -0
- data/db/migrate/20160630132716_add_portions_to_spree_payments.rb +5 -0
- data/db/migrate/20160630161016_create_spree_komerci_transaction.rb +14 -0
- data/db/migrate/20160701184408_add_payment_id_to_spree_komerci_transactions.rb +5 -0
- data/db/migrate/20160704120859_add_total_to_spree_komerci_transactions.rb +5 -0
- data/lib/generators/spree_zaez_komerci/install/install_generator.rb +30 -0
- data/lib/spree/komerci_configuration.rb +190 -0
- data/lib/spree_zaez_komerci/engine.rb +30 -0
- data/lib/spree_zaez_komerci/factories.rb +30 -0
- data/lib/spree_zaez_komerci.rb +5 -0
- data/spec/features/admin/komerci_actions_spec.rb +80 -0
- data/spec/features/admin/komerci_settings_spec.rb +77 -0
- data/spec/features/checkout_with_komerci_spec.rb +75 -0
- data/spec/fixtures/authorize_error.txt +14 -0
- data/spec/fixtures/authorize_success.txt +14 -0
- data/spec/fixtures/conf_authorize_error.txt +7 -0
- data/spec/fixtures/conf_authorize_success.txt +7 -0
- data/spec/fixtures/error.txt +1 -0
- data/spec/fixtures/void_error.txt +7 -0
- data/spec/fixtures/void_success.txt +7 -0
- data/spec/lib/spree/komerci_configuration_spec.rb +82 -0
- data/spec/models/spree/payment_method/komerci_spec.rb +206 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/support/capybara_login.rb +11 -0
- data/spec/support/shared_contexts/checkout_setup.rb +9 -0
- data/spree_zaez_komerci.gemspec +42 -0
- data/vendor/assets/javascripts/jquery.payment.js +612 -0
- metadata +423 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Komerci Settings', type: :feature do
|
4
|
+
before { create_admin_and_sign_in }
|
5
|
+
|
6
|
+
context 'visit Komerci settings' do
|
7
|
+
|
8
|
+
it 'should be a link to Komerci' do
|
9
|
+
within('.sidebar') { page.find_link('Komerci Settings')['/admin/komerci_settings/edit'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'show Komerci settings' do
|
15
|
+
|
16
|
+
it 'should be the fields of Komerci settings' do
|
17
|
+
visit spree.edit_admin_komerci_settings_path
|
18
|
+
|
19
|
+
expect(page).to have_selector '#afiliation_key'
|
20
|
+
expect(page).to have_selector '#test_mode'
|
21
|
+
expect(page).to have_selector '#minimum_value'
|
22
|
+
expect(page).to have_selector '#portion_without_tax'
|
23
|
+
expect(page).to have_selector '#tax_value'
|
24
|
+
expect(page).to have_selector '#max_portion'
|
25
|
+
expect(page).to have_selector '[name=portions_type]'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'edit Cielo cielo_settings' do
|
31
|
+
|
32
|
+
before { visit spree.edit_admin_komerci_settings_path }
|
33
|
+
|
34
|
+
it 'can edit test mode' do
|
35
|
+
find(:css, '#test_mode').set true
|
36
|
+
click_button 'Update'
|
37
|
+
|
38
|
+
expect(Spree::KomerciConfig.test_mode).to be true
|
39
|
+
expect(find_field('test_mode')).to be_checked
|
40
|
+
|
41
|
+
# set default
|
42
|
+
Spree::KomerciConfig.test_mode = false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'can edit portions type' do
|
46
|
+
find(:css, '#portions_type_08').set true
|
47
|
+
click_button 'Update'
|
48
|
+
|
49
|
+
expect(Spree::KomerciConfig.portions_type).to eq '08'
|
50
|
+
expect(find_field('portions_type_08')).to be_checked
|
51
|
+
|
52
|
+
# set default
|
53
|
+
Spree::KomerciConfig.portions_type = '06'
|
54
|
+
end
|
55
|
+
|
56
|
+
{komerci_user: 'test',
|
57
|
+
komerci_password: '12345',
|
58
|
+
afiliation_key: '12345678',
|
59
|
+
minimum_value: '1',
|
60
|
+
portion_without_tax: 1,
|
61
|
+
tax_value: '1.5',
|
62
|
+
max_portion: 12}.each do |key, value|
|
63
|
+
|
64
|
+
it "can edit #{key.to_s.humanize}" do
|
65
|
+
fill_in key.to_s, with: value
|
66
|
+
click_button 'Update'
|
67
|
+
|
68
|
+
expect(Spree::KomerciConfig[key]).to eq value
|
69
|
+
expect(find_field(key).value).to eq value.to_s
|
70
|
+
|
71
|
+
# set default
|
72
|
+
Spree::KomerciConfig[key] = ''
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Checkout with Komerci Payment Method', { type: :feature, js: true } do
|
4
|
+
|
5
|
+
include_context 'checkout setup'
|
6
|
+
let!(:payment_method) { create(:komerci_payment_method, id: 1) }
|
7
|
+
|
8
|
+
before { Spree::KomerciConfig[:test_mode] = true }
|
9
|
+
|
10
|
+
it 'should create an valid Komerci payment' do
|
11
|
+
mock_komerci_request 'spec/fixtures/authorize_success.txt'
|
12
|
+
navigate_to_payment
|
13
|
+
fill_credit_card_data
|
14
|
+
|
15
|
+
expect(page).to have_text 'Your order has been processed successfully'
|
16
|
+
expect(page).to have_text 'Ending in 1111'
|
17
|
+
|
18
|
+
expect(Spree::Order.complete.count).to eq 1
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should show an error message when the response of Komerci is unauthorized' do
|
22
|
+
mock_komerci_request 'spec/fixtures/authorize_error.txt'
|
23
|
+
navigate_to_payment
|
24
|
+
fill_credit_card_data
|
25
|
+
|
26
|
+
expect(page).to have_text '99: Credenciais invalidas'
|
27
|
+
expect(Spree::Order.first.payments.last.state).to eq 'failed'
|
28
|
+
end
|
29
|
+
|
30
|
+
def navigate_to_payment
|
31
|
+
# add mug to cart
|
32
|
+
visit spree.root_path
|
33
|
+
click_link mug.name
|
34
|
+
click_button 'add-to-cart-button'
|
35
|
+
click_button 'Checkout'
|
36
|
+
|
37
|
+
fill_in 'spree_user_email', with: 'test@example.com'
|
38
|
+
fill_in 'spree_user_password', with: 'spree123'
|
39
|
+
fill_in 'spree_user_password_confirmation', with: 'spree123'
|
40
|
+
click_on 'Create'
|
41
|
+
|
42
|
+
# set address
|
43
|
+
address = 'order_bill_address_attributes'
|
44
|
+
fill_in "#{address}_firstname", with: 'Ryan'
|
45
|
+
fill_in "#{address}_lastname", with: 'Bigg'
|
46
|
+
fill_in "#{address}_address1", with: '143 Swan Street'
|
47
|
+
fill_in "#{address}_city", with: 'Richmond'
|
48
|
+
select 'United States of America', from: "#{address}_country_id"
|
49
|
+
select 'Alabama', from: "#{address}_state_id"
|
50
|
+
fill_in "#{address}_zipcode", with: '12345'
|
51
|
+
fill_in "#{address}_phone", with: '(555) 555-5555'
|
52
|
+
# confirm address
|
53
|
+
click_button 'Save and Continue'
|
54
|
+
|
55
|
+
# confirm shipping method
|
56
|
+
click_button 'Save and Continue'
|
57
|
+
end
|
58
|
+
|
59
|
+
def fill_credit_card_data
|
60
|
+
fill_in 'Name on card', with: 'Spree Commerce'
|
61
|
+
# set the fields with javascript
|
62
|
+
page.execute_script "$('#cielo_card_number').val('4111111111111111');"
|
63
|
+
page.execute_script "$('#card_expiry').val('04 / 20');"
|
64
|
+
fill_in 'Card Code', with: '123'
|
65
|
+
# confirm payment method
|
66
|
+
click_button 'Save and Continue'
|
67
|
+
end
|
68
|
+
|
69
|
+
def mock_komerci_request(filename)
|
70
|
+
stub_request(:post, Spree::KomerciConfig.authorize_uri).
|
71
|
+
with(body: hash_including({ 'filiacao' => Spree::KomerciConfig[:afiliation_key] })).
|
72
|
+
to_return(:body => File.read(filename), :status => 200)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version=”1.0” encoding=”utf-8”?>
|
2
|
+
<AUTHORIZATION>
|
3
|
+
<CODRET>99</CODRET>
|
4
|
+
<MSGRET>Credenciais invalidas</MSGRET>
|
5
|
+
<NUMPEDIDO>R12345678</NUMPEDIDO>
|
6
|
+
<DATA>99999999</DATA>
|
7
|
+
<NUMAUTOR></NUMAUTOR>
|
8
|
+
<NUMCV></NUMCV>
|
9
|
+
<NUMAUTENT></NUMAUTENT>
|
10
|
+
<NUMSQN></NUMSQN>
|
11
|
+
<ORIGEM_BIN>BRL</ORIGEM_BIN>
|
12
|
+
<CONFCODRET>9</CONFCODRET>
|
13
|
+
<CONFMSGRET>Mensagem</CONFMSGRET>
|
14
|
+
</AUTHORIZATION>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version=”1.0” encoding=”utf-8”?>
|
2
|
+
<AUTHORIZATION>
|
3
|
+
<CODRET>0</CODRET>
|
4
|
+
<MSGRET></MSGRET>
|
5
|
+
<NUMPEDIDO>R12345678</NUMPEDIDO>
|
6
|
+
<DATA>99999999</DATA>
|
7
|
+
<NUMAUTOR>NA1234</NUMAUTOR>
|
8
|
+
<NUMCV>NCV1234</NUMCV>
|
9
|
+
<NUMAUTENT>NAU1234</NUMAUTENT>
|
10
|
+
<NUMSQN>123</NUMSQN>
|
11
|
+
<ORIGEM_BIN>BRL</ORIGEM_BIN>
|
12
|
+
<CONFCODRET>9</CONFCODRET>
|
13
|
+
<CONFMSGRET>Mensagem</CONFMSGRET>
|
14
|
+
</AUTHORIZATION>
|
@@ -0,0 +1 @@
|
|
1
|
+
Missing parameter: Total.
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::KomerciConfiguration do
|
4
|
+
|
5
|
+
let(:config) { subject.class.new }
|
6
|
+
|
7
|
+
[:afiliation_key, :test_mode, :minimum_value, :tax_value,
|
8
|
+
:portion_without_tax, :max_portion, :portions_type].each do |preference|
|
9
|
+
it "should has the #{preference} preference" do
|
10
|
+
expect(config.has_preference?(preference)).to be_truthy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
Spree::KomerciConfig.max_portion = 10
|
16
|
+
Spree::KomerciConfig.tax_value = 0.0
|
17
|
+
Spree::KomerciConfig.minimum_value = 5.0
|
18
|
+
Spree::KomerciConfig.portion_without_tax = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'calculate a single portion' do
|
22
|
+
|
23
|
+
it 'should calculate without tax' do
|
24
|
+
order = create(:order, total: 100.0)
|
25
|
+
config.portion_without_tax = 10
|
26
|
+
portion_value = config.calculate_portion_value order, 4
|
27
|
+
expect(portion_value).to eq 25.0
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should calculate with tax' do
|
31
|
+
order = create(:order, total: 100.0)
|
32
|
+
config.portion_without_tax = 1
|
33
|
+
config.tax_value = 5.0
|
34
|
+
portion_value = config.calculate_portion_value order, 4
|
35
|
+
expect(portion_value).to eq 30.387656250000006
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'calculating some portions' do
|
41
|
+
|
42
|
+
it 'should calculate portions without tax' do
|
43
|
+
order = create(:order, total: 100.0)
|
44
|
+
config.portion_without_tax = 10
|
45
|
+
config.max_portion = 5
|
46
|
+
portions = config.calculate_portions order
|
47
|
+
|
48
|
+
expect(portions[0]).to eq({portion: 1, value: 100.0, total: 100.0, tax_message: :komerci_without_tax})
|
49
|
+
expect(portions[1]).to eq({portion: 2, value: 50.0, total: 100.0, tax_message: :komerci_without_tax})
|
50
|
+
expect(portions[2]).to eq({portion: 3, value: 33.333333333333336, total: 100.0, tax_message: :komerci_without_tax})
|
51
|
+
expect(portions[3]).to eq({portion: 4, value: 25.0, total: 100.0, tax_message: :komerci_without_tax})
|
52
|
+
expect(portions[4]).to eq({portion: 5, value: 20.0, total: 100.0, tax_message: :komerci_without_tax})
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return the number of portions respecting the minimum value' do
|
56
|
+
order = create(:order, total: 50.0)
|
57
|
+
config.max_portion = 10
|
58
|
+
config.minimum_value = 20
|
59
|
+
config.portion_without_tax = 12
|
60
|
+
portions = config.calculate_portions order
|
61
|
+
|
62
|
+
expect(portions.size).to eq 2
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should calculate portions with tax' do
|
66
|
+
order = create(:order, total: 100.0)
|
67
|
+
config.max_portion = 6
|
68
|
+
config.minimum_value = 10
|
69
|
+
config.portion_without_tax = 1
|
70
|
+
config.tax_value = 1.0
|
71
|
+
portions = config.calculate_portions order
|
72
|
+
|
73
|
+
expect(portions[0]).to eq({portion: 1, value: 100.0, total: 100.0, tax_message: :komerci_without_tax})
|
74
|
+
expect(portions[1]).to eq({portion: 2, value: 51.005, total: 102.01, tax_message: :komerci_with_tax})
|
75
|
+
expect(portions[2]).to eq({portion: 3, value: 34.343366666666675, total: 103.03010000000003, tax_message: :komerci_with_tax})
|
76
|
+
expect(portions[3]).to eq({portion: 4, value: 26.01510025, total: 104.060401, tax_message: :komerci_with_tax})
|
77
|
+
expect(portions[4]).to eq({portion: 5, value: 21.020201002, total: 105.10100501, tax_message: :komerci_with_tax})
|
78
|
+
expect(portions[5]).to eq({portion: 6, value: 17.692002510016668, total: 106.15201506010001, tax_message: :komerci_with_tax})
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::PaymentMethod::Komerci do
|
4
|
+
|
5
|
+
let(:komerci) { FactoryGirl.build(:komerci_payment_method) }
|
6
|
+
let(:credit_card) { FactoryGirl.build(:credit_card_komerci) }
|
7
|
+
let!(:payment) { create(:komerci_payment, source: credit_card) }
|
8
|
+
let(:order) { create(:order) }
|
9
|
+
let(:gateway_options) { {order_id: "#{order.number}-#{payment.number}", portions: 2} }
|
10
|
+
|
11
|
+
before do
|
12
|
+
payment
|
13
|
+
Spree::KomerciConfig[:test_mode] = true
|
14
|
+
Spree::KomerciConfig[:afiliation_key] = 'ABC1234'
|
15
|
+
end
|
16
|
+
|
17
|
+
after(:all) do
|
18
|
+
Spree::KomerciConfig[:test_mode] = false
|
19
|
+
Spree::KomerciConfig[:afiliation_key] = ''
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'authorize' do
|
23
|
+
|
24
|
+
let(:request_url) { Spree::KomerciConfig.authorize_uri }
|
25
|
+
|
26
|
+
it 'should authorize the payment' do
|
27
|
+
mock_komerci_request request_url, 'spec/fixtures/authorize_success.txt'
|
28
|
+
|
29
|
+
response = komerci.authorize(1000, credit_card, gateway_options)
|
30
|
+
expect(response.success?).to be_truthy
|
31
|
+
expect(response.message).to eq 'Komerci: transaction authorized successfully'
|
32
|
+
|
33
|
+
komerci_transaction = Spree::KomerciTransaction.find_by order_number: 'NCV1234'
|
34
|
+
expect(komerci_transaction.authorization_number).to eq 'NA1234'
|
35
|
+
expect(komerci_transaction.authentication_number).to eq 'NAU1234'
|
36
|
+
expect(komerci_transaction.sequencial_number).to eq '123'
|
37
|
+
expect(komerci_transaction.bin).to eq 'BRL'
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'error' do
|
41
|
+
|
42
|
+
it 'should return an error when the payment do not have any portions' do
|
43
|
+
gateway_options = { order_id: "#{order.number}-#{payment.number}" }
|
44
|
+
|
45
|
+
response = komerci.authorize(1000, credit_card, gateway_options)
|
46
|
+
expect(response.success?).to be_falsey
|
47
|
+
expect(response.message).to eq 'Komerci: The number of portions is required'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should return an error when the request to Komerci is invalid' do
|
51
|
+
mock_komerci_request request_url, 'spec/fixtures/error.txt'
|
52
|
+
|
53
|
+
response = komerci.authorize(1000, credit_card, gateway_options)
|
54
|
+
expect(response.success?).to be_falsey
|
55
|
+
expect(response.message).to eq 'Missing parameter: Total.'
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should return an error when the request to Komerci is unauthorized' do
|
59
|
+
mock_komerci_request request_url, 'spec/fixtures/authorize_error.txt'
|
60
|
+
|
61
|
+
response = komerci.authorize(1000, credit_card, gateway_options)
|
62
|
+
expect(response.success?).to be_falsey
|
63
|
+
expect(response.message).to eq '99: Credenciais invalidas'
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'purchase' do
|
71
|
+
|
72
|
+
let(:request_url) { Spree::KomerciConfig.authorize_uri }
|
73
|
+
|
74
|
+
it 'should purchase the payment' do
|
75
|
+
mock_komerci_request request_url, 'spec/fixtures/authorize_success.txt'
|
76
|
+
|
77
|
+
response = komerci.purchase(1500, credit_card, gateway_options)
|
78
|
+
expect(response.success?).to be_truthy
|
79
|
+
expect(response.message).to eq 'Komerci: transaction purchased successfully'
|
80
|
+
|
81
|
+
komerci_transaction = Spree::KomerciTransaction.find_by order_number: 'NCV1234'
|
82
|
+
expect(komerci_transaction.authorization_number).to eq 'NA1234'
|
83
|
+
expect(komerci_transaction.authentication_number).to eq 'NAU1234'
|
84
|
+
expect(komerci_transaction.sequencial_number).to eq '123'
|
85
|
+
expect(komerci_transaction.bin).to eq 'BRL'
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'error' do
|
89
|
+
|
90
|
+
it 'should return an error when the payment do not have any portions' do
|
91
|
+
gateway_options = { order_id: "#{order.number}-#{payment.number}" }
|
92
|
+
|
93
|
+
response = komerci.purchase(1500, credit_card, gateway_options)
|
94
|
+
expect(response.success?).to be_falsey
|
95
|
+
expect(response.message).to eq 'Komerci: The number of portions is required'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should return an error when the request to Komerci is invalid' do
|
99
|
+
mock_komerci_request request_url, 'spec/fixtures/error.txt'
|
100
|
+
|
101
|
+
response = komerci.purchase(1500, credit_card, gateway_options)
|
102
|
+
expect(response.success?).to be_falsey
|
103
|
+
expect(response.message).to eq 'Missing parameter: Total.'
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should return an error when the request to Komerci is unauthorized' do
|
107
|
+
mock_komerci_request request_url, 'spec/fixtures/authorize_error.txt'
|
108
|
+
|
109
|
+
response = komerci.purchase(1500, credit_card, gateway_options)
|
110
|
+
expect(response.success?).to be_falsey
|
111
|
+
expect(response.message).to eq '99: Credenciais invalidas'
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'capture' do
|
119
|
+
|
120
|
+
let(:request_url) { Spree::KomerciConfig.conf_authorization_uri }
|
121
|
+
let!(:komerci_transaction) { create(:komerci_transaction, order_number: 'NCV1234') }
|
122
|
+
|
123
|
+
it 'should capture the payment' do
|
124
|
+
mock_komerci_request request_url, 'spec/fixtures/conf_authorize_success.txt'
|
125
|
+
|
126
|
+
response = komerci.capture(1900, 'NCV1234', {})
|
127
|
+
expect(response.success?).to be_truthy
|
128
|
+
expect(response.message).to eq 'Komerci: captured successfully'
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'error' do
|
132
|
+
|
133
|
+
it 'should return an error when the request to Komerci is invalid' do
|
134
|
+
mock_komerci_request request_url, 'spec/fixtures/error.txt'
|
135
|
+
|
136
|
+
response = komerci.capture(1900, 'NCV1234', {})
|
137
|
+
expect(response.success?).to be_falsey
|
138
|
+
expect(response.message).to eq 'Missing parameter: Total.'
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should return an error when the request to Komerci is unauthorized' do
|
142
|
+
mock_komerci_request request_url, 'spec/fixtures/conf_authorize_error.txt'
|
143
|
+
|
144
|
+
response = komerci.capture(1900, 'NCV1234', {})
|
145
|
+
expect(response.success?).to be_falsey
|
146
|
+
expect(response.message).to eq '98: Cartão inválido'
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'void' do
|
153
|
+
|
154
|
+
let(:request_url) { Spree::KomerciConfig.void_transaction_uri }
|
155
|
+
let!(:komerci_transaction) { create(:komerci_transaction, order_number: 'NCV1234') }
|
156
|
+
|
157
|
+
it 'should void the payment' do
|
158
|
+
mock_komerci_request request_url, 'spec/fixtures/void_success.txt'
|
159
|
+
|
160
|
+
response = komerci.void('NCV1234', {})
|
161
|
+
expect(response.success?).to be_truthy
|
162
|
+
expect(response.message).to eq 'Komerci: Voided successfully'
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'error' do
|
166
|
+
|
167
|
+
it 'should return an error when the request to Komerci is invalid' do
|
168
|
+
mock_komerci_request request_url, 'spec/fixtures/error.txt'
|
169
|
+
|
170
|
+
response = komerci.void('NCV1234', {})
|
171
|
+
expect(response.success?).to be_falsey
|
172
|
+
expect(response.message).to eq 'Missing parameter: Total.'
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should return an error when the request to Komerci is unauthorized' do
|
176
|
+
mock_komerci_request request_url, 'spec/fixtures/void_error.txt'
|
177
|
+
|
178
|
+
response = komerci.void('NCV1234', {})
|
179
|
+
expect(response.success?).to be_falsey
|
180
|
+
expect(response.message).to eq '97: Data de estorno expirou'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'cancel' do
|
187
|
+
|
188
|
+
let(:request_url) { Spree::KomerciConfig.void_transaction_uri }
|
189
|
+
let!(:komerci_transaction) { create(:komerci_transaction, order_number: 'NCV1234') }
|
190
|
+
|
191
|
+
it 'should cancel the payment' do
|
192
|
+
mock_komerci_request request_url, 'spec/fixtures/void_success.txt'
|
193
|
+
|
194
|
+
response = komerci.cancel('NCV1234')
|
195
|
+
expect(response.success?).to be_truthy
|
196
|
+
expect(response.message).to eq 'Komerci: Canceled successfully'
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
def mock_komerci_request(url, filename)
|
202
|
+
stub_request(:post, url).
|
203
|
+
with(body: hash_including({ 'filiacao' => Spree::KomerciConfig[:afiliation_key] })).
|
204
|
+
to_return(:body => File.read(filename), :status => 200)
|
205
|
+
end
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure Rails Environment
|
14
|
+
ENV['RAILS_ENV'] = 'test'
|
15
|
+
|
16
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'database_cleaner'
|
20
|
+
require 'ffaker'
|
21
|
+
|
22
|
+
require 'capybara/poltergeist'
|
23
|
+
Capybara.javascript_driver = :poltergeist
|
24
|
+
|
25
|
+
require 'webmock/rspec'
|
26
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
27
|
+
|
28
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
29
|
+
# in spec/support/ and its subdirectories.
|
30
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
31
|
+
|
32
|
+
# Requires factories and other useful helpers defined in spree_core.
|
33
|
+
require 'spree/testing_support/authorization_helpers'
|
34
|
+
require 'spree/testing_support/capybara_ext'
|
35
|
+
require 'spree/testing_support/controller_requests'
|
36
|
+
require 'spree/testing_support/factories'
|
37
|
+
require 'spree/testing_support/url_helpers'
|
38
|
+
|
39
|
+
# Requires factories defined in lib/spree_zaez_komerci/factories.rb
|
40
|
+
require 'spree_zaez_komerci/factories'
|
41
|
+
|
42
|
+
RSpec.configure do |config|
|
43
|
+
config.include FactoryGirl::Syntax::Methods
|
44
|
+
|
45
|
+
# Infer an example group's spec type from the file location.
|
46
|
+
config.infer_spec_type_from_file_location!
|
47
|
+
|
48
|
+
# == URL Helpers
|
49
|
+
#
|
50
|
+
# Allows access to Spree's routes in specs:
|
51
|
+
#
|
52
|
+
# visit spree.admin_path
|
53
|
+
# current_path.should eql(spree.products_path)
|
54
|
+
config.include Spree::TestingSupport::UrlHelpers
|
55
|
+
|
56
|
+
# == Requests support
|
57
|
+
#
|
58
|
+
# Adds convenient methods to request Spree's controllers
|
59
|
+
# spree_get :index
|
60
|
+
config.include Spree::TestingSupport::ControllerRequests, type: :controller
|
61
|
+
|
62
|
+
# == Mock Framework
|
63
|
+
#
|
64
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
65
|
+
#
|
66
|
+
# config.mock_with :mocha
|
67
|
+
# config.mock_with :flexmock
|
68
|
+
# config.mock_with :rr
|
69
|
+
config.mock_with :rspec
|
70
|
+
config.color = true
|
71
|
+
|
72
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
73
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
74
|
+
|
75
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
76
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
77
|
+
# to setup a test will be unavailable to the browser, which runs under a separate server instance.
|
78
|
+
config.use_transactional_fixtures = false
|
79
|
+
|
80
|
+
# Ensure Suite is set to use transactions for speed.
|
81
|
+
config.before :suite do
|
82
|
+
DatabaseCleaner.strategy = :transaction
|
83
|
+
DatabaseCleaner.clean_with :truncation
|
84
|
+
end
|
85
|
+
|
86
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
87
|
+
config.before :each do
|
88
|
+
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
|
89
|
+
DatabaseCleaner.start
|
90
|
+
end
|
91
|
+
|
92
|
+
# After each spec clean the database.
|
93
|
+
config.after :each do
|
94
|
+
DatabaseCleaner.clean
|
95
|
+
end
|
96
|
+
|
97
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
98
|
+
config.order = "random"
|
99
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
shared_context 'checkout setup' do
|
2
|
+
let!(:country) { create(:country, states_required: true) }
|
3
|
+
let!(:state) { create(:state, country: country) }
|
4
|
+
let!(:shipping_method) { create(:shipping_method) }
|
5
|
+
let!(:stock_location) { create(:stock_location) }
|
6
|
+
let!(:mug) { create(:product, name: 'RoR Mug', price: 10.0) }
|
7
|
+
let!(:zone) { create(:zone) }
|
8
|
+
let!(:store) { create(:store) }
|
9
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree_zaez_komerci'
|
5
|
+
s.version = '3.0.4'
|
6
|
+
s.summary = 'Adds Komerci as a Payment Method to Spree Commerce'
|
7
|
+
s.description = s.summary
|
8
|
+
s.required_ruby_version = '>= 2.0.0'
|
9
|
+
|
10
|
+
s.author = 'Zaez Team'
|
11
|
+
s.email = 'contato@zaez.net'
|
12
|
+
s.homepage = 'http://www.spreecommerce.com'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
s.add_dependency 'spree_core', '~> 3.0.4'
|
20
|
+
s.add_dependency 'httparty'
|
21
|
+
|
22
|
+
s.add_development_dependency 'poltergeist', '~> 1.5.0'
|
23
|
+
s.add_development_dependency 'capybara', '~> 2.4'
|
24
|
+
s.add_development_dependency 'coffee-rails'
|
25
|
+
s.add_development_dependency 'database_cleaner'
|
26
|
+
s.add_development_dependency 'factory_girl', '~> 4.5'
|
27
|
+
s.add_development_dependency 'factory_girl_rails'
|
28
|
+
s.add_development_dependency 'ffaker'
|
29
|
+
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
30
|
+
s.add_development_dependency 'sass-rails', '~> 5.0.0.beta1'
|
31
|
+
s.add_development_dependency 'selenium-webdriver'
|
32
|
+
s.add_development_dependency 'simplecov'
|
33
|
+
s.add_development_dependency 'sqlite3'
|
34
|
+
s.add_development_dependency 'guard'
|
35
|
+
s.add_development_dependency 'guard-bundler'
|
36
|
+
s.add_development_dependency 'guard-rspec'
|
37
|
+
s.add_development_dependency 'guard-shell'
|
38
|
+
s.add_development_dependency 'http_logger'
|
39
|
+
s.add_development_dependency 'better_errors'
|
40
|
+
s.add_development_dependency 'binding_of_caller'
|
41
|
+
s.add_development_dependency 'webmock'
|
42
|
+
end
|