spree_zaez_cielo 3.0.9 → 3.0.10

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: 74317f9fef3be962b0cdf836a217cf798046d18c
4
- data.tar.gz: 356da3dd659544563dfa2d4d3b9a6230bb713120
3
+ metadata.gz: 0e29af900cc55139f21ad1986fe85666d732ad2b
4
+ data.tar.gz: 667976b4851817c46e6bbcefbab2ed47b4818610
5
5
  SHA512:
6
- metadata.gz: 28c37b24361658bf3661cb31e62775669e90cd988c1e2eb5206bbe5e21f8794e6138557c6dd82081effde2f17e5b1ac78e3b21f90b1faba979dd361de60aed4d
7
- data.tar.gz: b8523d37c7b8a8a86df31a00b63ec7bf8eec4fa1d8fff4a30f5d82c628c80593d860df240b6182a0de68b83aeb9efec286ae73727326e7d541b18b4fd1e5301d
6
+ metadata.gz: 676e7a99747ed60657beeae88e77241539daf39b92f28f9328977f29cf35bcf201a5fb2815157015329366fba7a697cce2c0ec0e5416b9902bb5216815a9760e
7
+ data.tar.gz: 79a8ec780ef94caf7eaa70237f7d68028c2140dfe98727ce5b4dc60a2924cedda854cace3c8e458045787e3a5718718032d1f7ea1ac14fd656109a4442215641
@@ -11,13 +11,17 @@ module Spree
11
11
  #
12
12
  # @return [ActiveMerchant::Billing::Response]
13
13
  #
14
- def purchase(amount, source, gateway_options)
14
+ def purchase(_amount, source, gateway_options)
15
15
  if gateway_options[:portions].nil?
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, gateway_options
19
+ order_number = gateway_options[:order_id].split('-').first
20
+ order = Spree::Order.friendly.find order_number
21
+ portion_value = Spree::CieloConfig.calculate_portion_value order, gateway_options[:portions]
22
+ total_value = sprintf('%0.2f', portion_value * gateway_options[:portions])
20
23
  total_value.delete!('.')
24
+
21
25
  default_params = {
22
26
  parcelas: gateway_options[:portions],
23
27
  capturar: 'true'
@@ -50,6 +54,9 @@ module Spree
50
54
  storage_token source, response[:transacao]
51
55
  end
52
56
 
57
+ # Salva o valor do pagamento (e pedido) com o juros (se houver)
58
+ update_payment_amount gateway_options
59
+
53
60
  ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.purchase_success'), {}, authorization: response[:transacao][:tid])
54
61
  else
55
62
  ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.purchase_fail'), {}, authorization: response[:transacao][:tid])
@@ -64,13 +71,17 @@ module Spree
64
71
  #
65
72
  # @return [ActiveMerchant::Billing::Response]
66
73
  #
67
- def authorize(amount, source, gateway_options)
74
+ def authorize(_amount, source, gateway_options)
68
75
  if gateway_options[:portions].nil?
69
76
  return ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.invalid_portions'), {}, {})
70
77
  end
71
78
 
72
- total_value = update_payment_amount amount, gateway_options
79
+ order_number = gateway_options[:order_id].split('-').first
80
+ order = Spree::Order.friendly.find order_number
81
+ portion_value = Spree::CieloConfig.calculate_portion_value order, gateway_options[:portions]
82
+ total_value = sprintf('%0.2f', portion_value * gateway_options[:portions])
73
83
  total_value.delete!('.')
84
+
74
85
  default_params = {
75
86
  parcelas: gateway_options[:portions],
76
87
  capturar: 'false'
@@ -103,6 +114,9 @@ module Spree
103
114
  storage_token source, response[:transacao]
104
115
  end
105
116
 
117
+ # Salva o valor do pagamento (e pedido) com o juros (se houver)
118
+ update_payment_amount gateway_options
119
+
106
120
  ActiveMerchant::Billing::Response.new(true, Spree.t('cielo.messages.authorize_success'), {}, authorization: response[:transacao][:tid])
107
121
  else
108
122
  ActiveMerchant::Billing::Response.new(false, Spree.t('cielo.messages.authorize_fail'), {}, authorization: response[:transacao][:tid])
@@ -240,24 +254,26 @@ module Spree
240
254
  #
241
255
  # @author Isabella Santos
242
256
  #
243
- # @param amount [Integer]
244
257
  # @param gateway_options [Hash]
245
258
  #
246
259
  # @return [Integer]
247
260
  #
248
- def update_payment_amount(amount, gateway_options)
249
- if gateway_options[:portions] > 1
250
- order_number, payment_number = gateway_options[:order_id].split('-')
251
- order = Spree::Order.friendly.find order_number
252
- portion_value = Spree::CieloConfig.calculate_portion_value order, gateway_options[:portions]
253
- total_value = sprintf('%0.2f', portion_value * gateway_options[:portions])
261
+ def update_payment_amount(gateway_options)
262
+ order_number, payment_number = gateway_options[:order_id].split('-')
263
+ order = Spree::Order.friendly.find order_number
264
+ total = Spree::CieloConfig.calculate_portion_value(order, gateway_options[:portions]) * gateway_options[:portions]
265
+
266
+ if total > order.total
267
+ Spree::Adjustment.create(adjustable: order,
268
+ amount: (total - order.total),
269
+ label: Spree.t(:cielo_adjustment_tax),
270
+ eligible: true,
271
+ order: order)
272
+ order.updater.update
254
273
 
255
274
  payment = Spree::Payment.friendly.find payment_number
256
- payment.update_attributes(amount: total_value)
275
+ payment.update_attributes(amount: order.total)
257
276
 
258
- total_value
259
- else
260
- amount.to_s
261
277
  end
262
278
  end
263
279
 
@@ -59,6 +59,7 @@ en:
59
59
  cielo_card_fail: "The card is not supported. The available cards are:"
60
60
  cielo_unavailable_credit_card: "The credit card is not supported."
61
61
  invalid_guest_token: "The guest token passed is invalid!"
62
+ cielo_adjustment_tax: Credit Card Tax
62
63
  activerecord:
63
64
  attributes:
64
65
  spree/payment:
@@ -59,6 +59,7 @@ pt-BR:
59
59
  cielo_card_fail: "O cartão digitado não é suportado. Os tipos de cartões disponíveis são:"
60
60
  cielo_unavailable_credit_card: "O cartão informado não é suportado."
61
61
  invalid_guest_token: "O token informado é inválido!"
62
+ cielo_adjustment_tax: "Juros Cartão de Crédito"
62
63
  activerecord:
63
64
  attributes:
64
65
  spree/credit_card:
@@ -18,6 +18,7 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
18
18
  require 'rspec/rails'
19
19
  require 'database_cleaner'
20
20
  require 'ffaker'
21
+
21
22
  require 'capybara/poltergeist'
22
23
  Capybara.javascript_driver = :poltergeist
23
24
 
@@ -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.9'
5
+ s.version = '3.0.10'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_zaez_cielo
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.9
4
+ version: 3.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaez Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core