spree_zaez_cielo 3.0.6 → 3.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/orders_controller_decorator.rb +1 -1
- data/app/models/spree/payment_method/cielo_credit.rb +7 -6
- data/app/views/spree/api/orders/portions.html.erb +6 -4
- data/lib/spree/cielo_configuration.rb +6 -8
- data/spec/lib/spree/cielo_configuration_spec.rb +10 -5
- data/spec/models/spree/payment_method/cielo_credit_spec.rb +2 -1
- data/spree_zaez_cielo.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33939f91d3e3e96cd2005fced635dc2203866743
|
4
|
+
data.tar.gz: 87e324acb1727d18705a7786075eb37630c077c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7abd8efdde3f24e2c8884facdaee45dc6cba8f79234457f1f67e7af95d57893ee6b5f9858003ba5a89361be0211df938d107af5df46c9708dd910e2deda7620
|
7
|
+
data.tar.gz: c803b20c01a69019e2c3b4c8c57cfe98eea3fa33d930c97af33773321f5ce3faad333a217ec6d9f605e37364d48e0eabc6c37036685f7b95b51ce1c4138306e5
|
@@ -21,7 +21,7 @@ module Spree
|
|
21
21
|
# set the prefix if exists
|
22
22
|
@prefix = params[:prefix].present? ? params[:prefix] : nil
|
23
23
|
|
24
|
-
@portions = Spree::CieloConfig.calculate_portions @order
|
24
|
+
@portions = Spree::CieloConfig.calculate_portions @order, @cc_type
|
25
25
|
@portions.each do |item|
|
26
26
|
item[:total] = Spree::Money.new(item[:total], {currency: @order.currency}).to_html
|
27
27
|
item[:value] = Spree::Money.new(item[:value], {currency: @order.currency}).to_html
|
@@ -16,7 +16,7 @@ module Spree
|
|
16
16
|
return ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.invalid_portions'), {}, {})
|
17
17
|
end
|
18
18
|
|
19
|
-
total_value = update_payment_amount amount,
|
19
|
+
total_value = update_payment_amount amount, gateway_options
|
20
20
|
total_value.delete!('.')
|
21
21
|
default_params = {
|
22
22
|
parcelas: gateway_options[:portions],
|
@@ -67,7 +67,7 @@ module Spree
|
|
67
67
|
return ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.invalid_portions'), {}, {})
|
68
68
|
end
|
69
69
|
|
70
|
-
total_value = update_payment_amount amount,
|
70
|
+
total_value = update_payment_amount amount, gateway_options
|
71
71
|
total_value.delete!('.')
|
72
72
|
default_params = {
|
73
73
|
parcelas: gateway_options[:portions],
|
@@ -213,17 +213,18 @@ module Spree
|
|
213
213
|
# @author Isabella Santos
|
214
214
|
#
|
215
215
|
# @param amount [Integer]
|
216
|
-
# @param source [Spree::CreditCard]
|
217
216
|
# @param gateway_options [Hash]
|
218
217
|
#
|
219
218
|
# @return [Integer]
|
220
219
|
#
|
221
|
-
def update_payment_amount(amount,
|
220
|
+
def update_payment_amount(amount, gateway_options)
|
222
221
|
if gateway_options[:portions] > 1
|
223
|
-
|
222
|
+
order_number, payment_number = gateway_options[:order_id].split('-')
|
223
|
+
order = Spree::Order.friendly.find order_number
|
224
|
+
portion_value = Spree::CieloConfig.calculate_portion_value order, gateway_options[:portions]
|
224
225
|
total_value = sprintf('%0.2f', portion_value * gateway_options[:portions])
|
225
226
|
|
226
|
-
payment = Spree::Payment.
|
227
|
+
payment = Spree::Payment.friendly.find payment_number
|
227
228
|
payment.update_attributes(amount: total_value)
|
228
229
|
|
229
230
|
total_value
|
@@ -8,7 +8,9 @@
|
|
8
8
|
<% end %>
|
9
9
|
<%= tag(:br) %>
|
10
10
|
<% end %>
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
<div data-hook="cielo_tax_info">
|
12
|
+
<% if @show_tax_value == true %>
|
13
|
+
<%= tag(:br) %>
|
14
|
+
<%= content_tag :span, Spree.t(:cielo_tax_message, tax: @tax), style: 'font-size: smaller;' %>
|
15
|
+
<% end %>
|
16
|
+
</div>
|
@@ -14,14 +14,13 @@ class Spree::CieloConfiguration < Spree::Preferences::Configuration
|
|
14
14
|
# Calculates the portions of credit card type
|
15
15
|
# based on Cielo configuration
|
16
16
|
#
|
17
|
-
# @param
|
18
|
-
# amount of the order
|
17
|
+
# @param order [Spree::Order]
|
19
18
|
# @param cc_type [String]
|
20
|
-
# name of the credit card
|
21
19
|
#
|
22
20
|
# @return [Array]
|
23
21
|
#
|
24
|
-
def calculate_portions(
|
22
|
+
def calculate_portions(order, cc_type)
|
23
|
+
amount = order.total.to_f
|
25
24
|
ret = []
|
26
25
|
if preferred_credit_cards.has_key? cc_type
|
27
26
|
portions_number = preferred_credit_cards[cc_type]
|
@@ -51,14 +50,13 @@ class Spree::CieloConfiguration < Spree::Preferences::Configuration
|
|
51
50
|
# Calculate the value of the portion based on Cielo configuration
|
52
51
|
# (verify if the portion has tax)
|
53
52
|
#
|
54
|
-
# @param
|
55
|
-
# total amount of the order
|
53
|
+
# @param order [Spree::Order]
|
56
54
|
# @param portion [Integer]
|
57
|
-
# value of the portion
|
58
55
|
#
|
59
56
|
# @return [Float]
|
60
57
|
#
|
61
|
-
def calculate_portion_value(
|
58
|
+
def calculate_portion_value(order, portion)
|
59
|
+
amount = order.total.to_f
|
62
60
|
amount = amount / 100 if amount.is_a? Integer
|
63
61
|
tax = preferred_tax_value.to_f
|
64
62
|
|
@@ -20,24 +20,27 @@ describe Spree::CieloConfiguration do
|
|
20
20
|
|
21
21
|
context 'calculate a single portion' do
|
22
22
|
it 'should calculate without tax' do
|
23
|
+
order = create(:order, total: 100.0)
|
23
24
|
config.portion_without_tax = 10
|
24
|
-
portion_value = config.calculate_portion_value
|
25
|
+
portion_value = config.calculate_portion_value order, 4
|
25
26
|
expect(portion_value).to eq 25.0
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'should calculate with tax' do
|
30
|
+
order = create(:order, total: 100.0)
|
29
31
|
config.portion_without_tax = 1
|
30
32
|
config.tax_value = '5.00'
|
31
|
-
portion_value = config.calculate_portion_value
|
33
|
+
portion_value = config.calculate_portion_value order, 4
|
32
34
|
expect(portion_value).to eq 30.387656250000006
|
33
35
|
end
|
34
36
|
end
|
35
37
|
|
36
38
|
context 'calculating some portions' do
|
37
39
|
it 'should calculate portions without tax' do
|
40
|
+
order = create(:order, total: 100.0)
|
38
41
|
config.portion_without_tax = 10
|
39
42
|
config.credit_cards = {'visa' => 5}
|
40
|
-
portions = config.calculate_portions
|
43
|
+
portions = config.calculate_portions order, 'visa'
|
41
44
|
|
42
45
|
expect(portions[0]).to eq({portion: 1, value: 100.0, total: 100.0, tax_message: :cielo_without_tax})
|
43
46
|
expect(portions[1]).to eq({portion: 2, value: 50.0, total: 100.0, tax_message: :cielo_without_tax})
|
@@ -47,20 +50,22 @@ describe Spree::CieloConfiguration do
|
|
47
50
|
end
|
48
51
|
|
49
52
|
it 'should return the number of portions respecting the minimum value' do
|
53
|
+
order = create(:order, total: 50.0)
|
50
54
|
config.credit_cards = {'master' => 10}
|
51
55
|
config.minimum_value = 20
|
52
56
|
config.portion_without_tax = 12
|
53
|
-
portions = config.calculate_portions
|
57
|
+
portions = config.calculate_portions order, 'master'
|
54
58
|
|
55
59
|
expect(portions.size).to eq 2
|
56
60
|
end
|
57
61
|
|
58
62
|
it 'should calculate portions with tax' do
|
63
|
+
order = create(:order, total: 100.0)
|
59
64
|
config.credit_cards = {'master' => 6}
|
60
65
|
config.minimum_value = 10
|
61
66
|
config.portion_without_tax = 1
|
62
67
|
config.tax_value = '1'
|
63
|
-
portions = config.calculate_portions
|
68
|
+
portions = config.calculate_portions order, 'master'
|
64
69
|
|
65
70
|
expect(portions[0]).to eq({portion: 1, value: 100.0, total: 100.0, tax_message: :cielo_without_tax})
|
66
71
|
expect(portions[1]).to eq({portion: 2, value: 51.005, total: 102.01, tax_message: :cielo_with_tax})
|
@@ -4,8 +4,9 @@ describe Spree::PaymentMethod::CieloCredit do
|
|
4
4
|
|
5
5
|
let(:cielo) { FactoryGirl.build(:cielo_credit_payment_method) }
|
6
6
|
let!(:payment) { create(:cielo_credit_payment, source: credit_card) }
|
7
|
+
let(:order) { create(:order) }
|
7
8
|
let(:credit_card) { FactoryGirl.build(:credit_card_cielo) }
|
8
|
-
let(:gateway_options) { {order_id: "
|
9
|
+
let(:gateway_options) { {order_id: "#{order.number}-#{payment.number}", portions: 2} }
|
9
10
|
|
10
11
|
before do
|
11
12
|
payment
|
data/spree_zaez_cielo.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_zaez_cielo'
|
5
|
-
s.version = '3.0.
|
5
|
+
s.version = '3.0.7'
|
6
6
|
s.summary = 'Adds Cielo as a Payment Method to Spree Commerce'
|
7
7
|
s.description = s.summary
|
8
8
|
s.required_ruby_version = '>= 2.0.0'
|