spree_zaez_cielo 3.0.6 → 3.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017cbe5e938dea65db1858b8241304a43badbafe
4
- data.tar.gz: f5dc6a5e902ddcffdba343d0a2b8fac4d5c564e4
3
+ metadata.gz: 33939f91d3e3e96cd2005fced635dc2203866743
4
+ data.tar.gz: 87e324acb1727d18705a7786075eb37630c077c7
5
5
  SHA512:
6
- metadata.gz: 8053ec101393f5caa6afea11c66b3cf51546be4c046b0be2b7295a935a3d0caf2e60bef9ea92e234fce5a62fe98bb15524be68d6b2f86830dfc17a28034db40b
7
- data.tar.gz: 0aac3e20e5e689dced9d0a631248041c2163cd6ec0d8ce7e365b82c47f130cbe69b7e6d4ea7b3f3ad3b33275aa7b6d3aacc108c1458fd4f1fd1b5f292fc9f789
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.total, @cc_type
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, source, gateway_options
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, source, gateway_options
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, source, gateway_options)
220
+ def update_payment_amount(amount, gateway_options)
222
221
  if gateway_options[:portions] > 1
223
- portion_value = Spree::CieloConfig.calculate_portion_value amount, gateway_options[:portions]
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.find_by number: gateway_options[:order_id].split('-')[1]
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
- <% if @show_tax_value == true %>
12
- <%= tag(:br) %>
13
- <%= content_tag :span, Spree.t(:cielo_tax_message, tax: @tax), style: 'font-size: smaller;' %>
14
- <% end %>
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 amount [Float]
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(amount, cc_type)
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 amount [Float]
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(amount, portion)
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 100.0, 4
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 100.0, 4
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 100.0, 'visa'
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 50.0, 'master'
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 100.0, 'master'
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: "test-#{payment.number}", portions: 2} }
9
+ let(:gateway_options) { {order_id: "#{order.number}-#{payment.number}", portions: 2} }
9
10
 
10
11
  before do
11
12
  payment
@@ -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.6'
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'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_zaez_cielo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.6
4
+ version: 3.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaez Team