catarse_pagarme 2.9.2 → 2.9.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83df4869aa8964cc63026ac81f1863c72f0827fa
4
- data.tar.gz: b158ae386f50c01b5d28422511a8fe2937ebbd6f
3
+ metadata.gz: 6d2a92f5ca5f17ff3e6b906bb872412f5fa52daf
4
+ data.tar.gz: bb4a1b474f287f901b63d40200410f46504a564b
5
5
  SHA512:
6
- metadata.gz: f88eac6069007922e5ac0916e4ee0902cdd0a6f88b7dfd5d02184f0f43e92a19d93b8e270e65400a116734fa2d40db840722dbcbf3ff9e96e55ee440bc8d3f6d
7
- data.tar.gz: 52c7be5ce9191885d2a2598e90e75cf6324f3e627c1e398c0799ae12632f99fae5ab06df158dd5cb32535fd3f283e0492627e86da8f35edb13191ccb3c152ad1
6
+ metadata.gz: 8ddd2744658fdc06c141d1b37213e02e0959b3eba687fa9563d555cf20f93b12e120cf231012175f036916d9d970f9f60a545b77beb73ba524c438ca3379b047
7
+ data.tar.gz: ff5c36d3ef43a830cf669bc9ffaf5e80ee9f96edff8ddc277fa252accd65d549590cf005f3386944383ef5ed8c4683b291e2b0f05ddf01bc9e998639ed599d12
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- catarse_pagarme (2.9.2)
4
+ catarse_pagarme (2.9.3)
5
5
  pagarme (= 1.10.0)
6
6
  rails (~> 4.0)
7
7
  sidekiq
@@ -52,7 +52,7 @@ GEM
52
52
  connection_pool (2.2.0)
53
53
  database_cleaner (1.5.0)
54
54
  diff-lcs (1.2.5)
55
- domain_name (0.5.20160310)
55
+ domain_name (0.5.20160615)
56
56
  unf (>= 0.0.5, < 1.0.0)
57
57
  erubis (2.7.0)
58
58
  factory_girl (4.5.0)
@@ -0,0 +1,9 @@
1
+ module CatarsePagarme::BalanceTransferPingConcern
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ def pagarme_delegator
6
+ CatarsePagarme::BalanceTransferPingDelegator.new(self)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ module CatarsePagarme
2
+ class BalanceTransferPingDelegator
3
+ attr_accessor :balance_transfer_ping, :transfer
4
+
5
+ def initialize(balance_transfer_ping)
6
+ configure_pagarme
7
+ self.balance_transfer_ping = balance_transfer_ping
8
+ end
9
+
10
+ def transfer_funds
11
+ ActiveRecord::Base.transaction do
12
+ raise "unable to create transfer ping, need to be authorized" if !balance_transfer_ping.authorized?
13
+
14
+ bank_account = PagarMe::BankAccount.new(bank_account_attributes.delete(:bank_account))
15
+ bank_account.create
16
+ raise "unable to create an bank account" unless bank_account.id.present?
17
+
18
+ transfer = PagarMe::Transfer.new({
19
+ bank_account_id: bank_account.id,
20
+ amount: value_for_transaction
21
+ })
22
+ transfer.create
23
+ raise "unable to create a transfer ping" unless transfer.id.present?
24
+
25
+ balance_transfer_ping.update_attributes(transfer_id: transfer.id,
26
+ metadata: transfer.to_hash,
27
+ state: 'processing')
28
+ balance_transfer_ping
29
+ end
30
+ end
31
+
32
+ def bank_account_attributes
33
+ account = balance_transfer_ping.balance_transfer.project.account
34
+
35
+ {
36
+ bank_account: {
37
+ bank_code: (account.bank.code || account.bank.name),
38
+ agencia: account.agency,
39
+ agencia_dv: account.agency_digit,
40
+ conta: account.account,
41
+ conta_dv: account.account_digit,
42
+ legal_name: account.owner_name[0..29],
43
+ document_number: account.owner_document
44
+ }
45
+ }
46
+ end
47
+
48
+ def configure_pagarme
49
+ ::PagarMe.api_key = CatarsePagarme.configuration.api_key
50
+ end
51
+
52
+ def value_for_transaction
53
+ (self.balance_transfer_ping.amount * 100).to_i
54
+ end
55
+ end
56
+ end
@@ -19,11 +19,14 @@ module CatarsePagarme::FeeCalculatorConcern
19
19
 
20
20
  def get_card_fee
21
21
  return nil if self.payment.gateway_data["acquirer_name"].blank? # Here we depend on the acquirer name
22
- if %w(stone pagarme).include? self.payment.gateway_data["acquirer_name"]
22
+ fee = if %w(stone pagarme).include? self.payment.gateway_data["acquirer_name"]
23
23
  get_stone_fee
24
24
  else
25
25
  get_cielo_fee
26
26
  end
27
+
28
+ international = self.payment.contribution.try(:international?)
29
+ fee + (international ? 0 : antifraud_tax)
27
30
  end
28
31
 
29
32
  def get_stone_fee
@@ -56,6 +59,10 @@ module CatarsePagarme::FeeCalculatorConcern
56
59
  (((self.payment.installment_value * self.payment.installments) * pagarme_tax) + cents_fee).round(2) + ((self.payment.installment_value * acquirer_tax).round(2) * self.payment.installments)
57
60
  end
58
61
 
62
+ def antifraud_tax
63
+ CatarsePagarme.configuration.antifraud_tax.to_f
64
+ end
65
+
59
66
  def cents_fee
60
67
  CatarsePagarme.configuration.credit_card_cents_fee.to_f
61
68
  end
@@ -3,13 +3,14 @@ module CatarsePagarme
3
3
  attr_accessor :api_key, :slip_tax, :credit_card_tax, :interest_rate, :host, :subdomain, :protocol,
4
4
  :max_installments, :minimum_value_for_installment, :credit_card_cents_fee, :pagarme_tax, :stone_tax,
5
5
  :stone_installment_tax, :cielo_tax, :cielo_installment_diners_tax, :cielo_installment_not_diners_tax,
6
- :cielo_installment_amex_tax, :cielo_installment_not_amex_tax, :ecr_key, :slip_week_day_interval
6
+ :cielo_installment_amex_tax, :cielo_installment_not_amex_tax, :ecr_key, :slip_week_day_interval, :antifraud_tax
7
7
 
8
8
  def initialize
9
9
  self.api_key = ''
10
10
  self.ecr_key = ''
11
11
  self.slip_tax = 0
12
12
  self.credit_card_tax = 0
13
+ self.antifraud_tax = 0
13
14
  self.interest_rate = 0
14
15
  self.max_installments = 12
15
16
  self.minimum_value_for_installment = 10
@@ -5,6 +5,7 @@ module CatarsePagarme
5
5
  config.to_prepare do
6
6
  ::Payment.send(:include, CatarsePagarme::PaymentConcern)
7
7
  ::BalanceTransfer.send(:include, CatarsePagarme::BalanceTransferConcern)
8
+ ::BalanceTransferPing.send(:include, CatarsePagarme::BalanceTransferPingConcern)
8
9
  end
9
10
  end
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module CatarsePagarme
2
- VERSION = "2.9.2"
2
+ VERSION = "2.9.3"
3
3
  end
@@ -14,6 +14,7 @@ describe CatarsePagarme::PaymentDelegator do
14
14
  pagarme_tax: 0.0063,
15
15
  cielo_tax: 0.038,
16
16
  stone_tax: 0.0307,
17
+ antifraud_tax: 0.39,
17
18
  stone_installment_tax: 0.0307,
18
19
  credit_card_cents_fee: 0.39,
19
20
  api_key: '',
@@ -58,11 +59,23 @@ describe CatarsePagarme::PaymentDelegator do
58
59
  it { expect(subject).to eq(2.00) }
59
60
  end
60
61
 
61
- context 'when choice is credit card' do
62
+ context 'when choice is international credit card' do
62
63
  let(:payment) { create(:payment, value: 10, payment_method: CatarsePagarme::PaymentType::CREDIT_CARD, gateway_data: {acquirer_name: 'stone', card_brand: 'visa'}, installments: 1) }
64
+ before do
65
+ allow(payment.contribution).to receive(:international?).and_return(true)
66
+ end
63
67
  subject { delegator.get_fee }
64
68
  it { expect(subject).to eq(0.76) }
65
69
  end
70
+
71
+ context 'when choice is national credit card' do
72
+ let(:payment) { create(:payment, value: 10, payment_method: CatarsePagarme::PaymentType::CREDIT_CARD, gateway_data: {acquirer_name: 'stone', card_brand: 'visa'}, installments: 1) }
73
+ before do
74
+ allow(payment.contribution).to receive(:international?).and_return(false)
75
+ end
76
+ subject { delegator.get_fee }
77
+ it { expect(subject).to eq(1.15) }
78
+ end
66
79
  end
67
80
 
68
81
  describe "#get_installments" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: catarse_pagarme
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.2
4
+ version: 2.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antônio Roberto Silva
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-16 00:00:00.000000000 Z
12
+ date: 2016-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -152,6 +152,8 @@ files:
152
152
  - app/helpers/catarse_pagarme/application_helper.rb
153
153
  - app/models/catarse_pagarme/balance_transfer_concern.rb
154
154
  - app/models/catarse_pagarme/balance_transfer_delegator.rb
155
+ - app/models/catarse_pagarme/balance_transfer_ping_concern.rb
156
+ - app/models/catarse_pagarme/balance_transfer_ping_delegator.rb
155
157
  - app/models/catarse_pagarme/bank_account_concern.rb
156
158
  - app/models/catarse_pagarme/credit_card_transaction.rb
157
159
  - app/models/catarse_pagarme/fee_calculator_concern.rb