catarse_pagarme 1.5.3 → 2.0.0
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 +4 -4
- data/Gemfile.lock +7 -7
- data/app/assets/javascripts/catarse_pagarme/application.js +1 -1
- data/app/assets/javascripts/catarse_pagarme/credit_card.js +19 -21
- data/app/assets/javascripts/catarse_pagarme/payment_choice.js +0 -1
- data/app/assets/javascripts/catarse_pagarme/payment_slip.js +6 -6
- data/app/controllers/catarse_pagarme/credit_card_base_controller.rb +4 -4
- data/app/controllers/catarse_pagarme/notifications_controller.rb +1 -14
- data/app/controllers/catarse_pagarme/slip_controller.rb +3 -3
- data/app/helpers/catarse_pagarme/application_helper.rb +1 -1
- data/app/models/catarse_pagarme/contribution_delegator.rb +10 -14
- data/app/models/catarse_pagarme/transaction_base.rb +2 -11
- data/app/views/catarse_pagarme/pagarme/_terms.html.slim +6 -0
- data/app/views/catarse_pagarme/pagarme/review.html.slim +103 -104
- data/catarse_pagarme.gemspec +1 -1
- data/config/routes.rb +1 -4
- data/lib/catarse_pagarme/configuration.rb +1 -10
- data/lib/catarse_pagarme/version.rb +1 -1
- data/spec/controllers/catarse_pagarme/credit_cards_controller_spec.rb +3 -3
- data/spec/controllers/catarse_pagarme/notifications_controller_spec.rb +2 -10
- data/spec/models/catarse_pagarme/contribution_delegator_spec.rb +1 -14
- data/spec/models/catarse_pagarme/credit_card_transaction_spec.rb +2 -15
- data/spec/models/catarse_pagarme/slip_transaction_spec.rb +2 -15
- data/spec/spec_helper.rb +1 -1
- data/spec/support/factories.rb +3 -8
- metadata +5 -8
- data/app/models/catarse_pagarme/bank_account_concern.rb +0 -58
- data/app/models/catarse_pagarme/fee_calculator_concern.rb +0 -66
- data/spec/models/catarse_pagarme/bank_account_concern_spec.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea2622f55d3204092b95029e30222ee11d53ef09
|
4
|
+
data.tar.gz: db723fbfa732d4415e27ac35f277aebc5bfe8435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 959cc0e8544a66213446bf515ab834087d1ac24750aa8eb8ed400db618261e7406fb20eaf55ab2bf31a9e9c4b2a58536d8516f11c9d19698fc0880aca35b8f8b
|
7
|
+
data.tar.gz: 53922520a96378bc0387cfdccbadbba0e00e6bc68c00cf79f25d6972850d13216dcb53e06e9035963868ee43cf8254002dbe04db7b3241e2307514040eead0ff
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
catarse_pagarme (
|
5
|
-
pagarme (~> 1.9.
|
4
|
+
catarse_pagarme (2.0.0)
|
5
|
+
pagarme (~> 1.9.5)
|
6
6
|
rails (~> 4.0)
|
7
7
|
|
8
8
|
GEM
|
@@ -52,8 +52,8 @@ GEM
|
|
52
52
|
mime-types (1.25.1)
|
53
53
|
minitest (5.4.0)
|
54
54
|
multi_json (1.10.1)
|
55
|
-
netrc (0.
|
56
|
-
pagarme (1.9.
|
55
|
+
netrc (0.7.7)
|
56
|
+
pagarme (1.9.6)
|
57
57
|
multi_json
|
58
58
|
rest-client
|
59
59
|
pg (0.17.1)
|
@@ -92,15 +92,15 @@ GEM
|
|
92
92
|
rspec-core (~> 2.14.0)
|
93
93
|
rspec-expectations (~> 2.14.0)
|
94
94
|
rspec-mocks (~> 2.14.0)
|
95
|
-
sprockets (2.12.
|
95
|
+
sprockets (2.12.2)
|
96
96
|
hike (~> 1.2)
|
97
97
|
multi_json (~> 1.0)
|
98
98
|
rack (~> 1.0)
|
99
99
|
tilt (~> 1.1, != 1.3.0)
|
100
|
-
sprockets-rails (2.
|
100
|
+
sprockets-rails (2.1.4)
|
101
101
|
actionpack (>= 3.0)
|
102
102
|
activesupport (>= 3.0)
|
103
|
-
sprockets (
|
103
|
+
sprockets (~> 2.8)
|
104
104
|
thor (0.19.1)
|
105
105
|
thread_safe (0.3.4)
|
106
106
|
tilt (1.4.1)
|
@@ -3,7 +3,7 @@ App.addChild('PagarmeForm', {
|
|
3
3
|
|
4
4
|
activate: function() {
|
5
5
|
this.message = this.$('.next_step_after_valid_document .alert-danger');
|
6
|
-
this.loader = this.$('.loader');
|
6
|
+
this.loader = this.$('.loader img');
|
7
7
|
|
8
8
|
this.contributionId = $('input#contribution_id').val();
|
9
9
|
this.projectId = $('input#project_id').val();
|
@@ -5,30 +5,28 @@ App.views.PagarmeForm.addChild('PaymentCard', {
|
|
5
5
|
'keyup input[type="text"]' : 'creditCardInputValidator',
|
6
6
|
'keyup #payment_card_number' : 'onKeyupPaymentCardNumber',
|
7
7
|
'click input#credit_card_submit' : 'onSubmit',
|
8
|
-
'
|
8
|
+
'change .creditcard-records' : 'onChangeCard'
|
9
|
+
},
|
10
|
+
|
11
|
+
onChangeCard: function(event){
|
12
|
+
var $target = $(event.currentTarget);
|
13
|
+
$target.siblings().removeClass('selected');
|
14
|
+
$target.addClass('selected');
|
15
|
+
if($(event.target).val() == 0){
|
16
|
+
this.$('.type_card_data').slideDown('slow');
|
17
|
+
}
|
18
|
+
else{
|
19
|
+
this.$('.type_card_data').slideUp('slow');
|
20
|
+
}
|
9
21
|
},
|
10
22
|
|
11
23
|
activate: function(options){
|
12
24
|
var that = this;
|
13
25
|
this.pagarmeForm = this.parent;
|
14
|
-
this.message = this.$('.
|
26
|
+
this.message = this.$('.payment-error-message');
|
15
27
|
this.$('input#payment_card_date').mask('99/99');
|
16
28
|
},
|
17
29
|
|
18
|
-
showCreditCardForm: function(e) {
|
19
|
-
var that = this;
|
20
|
-
e.preventDefault();
|
21
|
-
|
22
|
-
that.$('ul.my_credit_cards').hide();
|
23
|
-
that.$('a.use_another-card ').hide();
|
24
|
-
that.$('.type_card_data').show();
|
25
|
-
that.$('.save_card').show();
|
26
|
-
|
27
|
-
$.each(that.$('.my_credit_cards input:radio[name=payment_subscription_card]'), function(i, item) {
|
28
|
-
$(item).prop('checked', false);
|
29
|
-
});
|
30
|
-
},
|
31
|
-
|
32
30
|
getUrl: function(){
|
33
31
|
var that = this;
|
34
32
|
var url = '';
|
@@ -52,7 +50,7 @@ App.views.PagarmeForm.addChild('PaymentCard', {
|
|
52
50
|
},
|
53
51
|
|
54
52
|
selectedCard: function() {
|
55
|
-
return this.$('
|
53
|
+
return this.$('input:radio[data-stored][name=payment_subscription_card]:checked');
|
56
54
|
},
|
57
55
|
|
58
56
|
hasSelectedSomeCard: function() {
|
@@ -81,7 +79,7 @@ App.views.PagarmeForm.addChild('PaymentCard', {
|
|
81
79
|
|
82
80
|
getInstallments: function() {
|
83
81
|
if(this.hasSelectedSomeCard()) {
|
84
|
-
return this.$('.
|
82
|
+
return this.$('.my-credit-cards .selected select#payment_card_installments').val();
|
85
83
|
} else {
|
86
84
|
return this.$('.type_card_data select#payment_card_installments').val();
|
87
85
|
}
|
@@ -102,8 +100,8 @@ App.views.PagarmeForm.addChild('PaymentCard', {
|
|
102
100
|
that.parent.loader.hide();
|
103
101
|
|
104
102
|
if(response.payment_status == 'failed'){
|
105
|
-
that.message.find('
|
106
|
-
that.message.
|
103
|
+
that.message.find('.message-text').html(response.message);
|
104
|
+
that.message.slideDown('slow')
|
107
105
|
|
108
106
|
$(e.currentTarget).show();
|
109
107
|
} else {
|
@@ -120,7 +118,7 @@ App.views.PagarmeForm.addChild('PaymentCard', {
|
|
120
118
|
},
|
121
119
|
|
122
120
|
onKeyupPaymentCardNumber: function(e){
|
123
|
-
this.$('
|
121
|
+
this.$('#payment_card_flag').html(this.getCardFlag($(e.currentTarget).val()))
|
124
122
|
},
|
125
123
|
|
126
124
|
getCardFlag: function(number) {
|
@@ -8,7 +8,7 @@ App.views.PagarmeForm.addChild('PaymentSlip', {
|
|
8
8
|
|
9
9
|
activate: function(options){
|
10
10
|
this.PagarmeForm = this.parent;
|
11
|
-
this.message = this.$('.
|
11
|
+
this.message = this.$('.payment-error-message');
|
12
12
|
this.$('#user_bank_account_attributes_name').brbanks();
|
13
13
|
},
|
14
14
|
|
@@ -44,18 +44,18 @@ App.views.PagarmeForm.addChild('PaymentSlip', {
|
|
44
44
|
}
|
45
45
|
};
|
46
46
|
|
47
|
-
$.post('/payment/pagarme/'+that.PagarmeForm.contributionId+'/pay_slip
|
47
|
+
$.post('/payment/pagarme/'+that.PagarmeForm.contributionId+'/pay_slip', bankAccountAttributes).success(function(response){
|
48
48
|
parent.loader.hide();
|
49
49
|
if(response.payment_status == 'failed'){
|
50
|
-
that.message.find('
|
51
|
-
that.message.
|
50
|
+
that.message.find('.message-text').html(response.message);
|
51
|
+
that.message.slideDown('slow')
|
52
52
|
|
53
53
|
$(e.currentTarget).show();
|
54
54
|
} else if(response.boleto_url) {
|
55
|
-
var link = $('<a target="__blank">'+response.boleto_url+'</a>')
|
55
|
+
var link = $('<a class="alt-link" target="__blank">'+response.boleto_url+'</a>')
|
56
56
|
link.attr('href', response.boleto_url);
|
57
57
|
that.$('.link_content').empty().html(link);
|
58
|
-
that.$('
|
58
|
+
that.$('#payment-slip-link').slideDown('slow');
|
59
59
|
}
|
60
60
|
});
|
61
61
|
}
|
@@ -18,7 +18,7 @@ module CatarsePagarme
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def get_installment
|
21
|
-
if contribution.value
|
21
|
+
if contribution.value < CatarsePagarme.configuration.minimum_value_for_installment
|
22
22
|
1
|
23
23
|
elsif params[:payment_card_installments].to_i > 0
|
24
24
|
params[:payment_card_installments].to_i
|
@@ -36,9 +36,9 @@ module CatarsePagarme
|
|
36
36
|
card_expiration_year: splited_month_and_year[1],
|
37
37
|
card_cvv: params[:payment_card_source],
|
38
38
|
amount: delegator.value_with_installment_tax(get_installment),
|
39
|
-
postback_url:
|
40
|
-
|
41
|
-
|
39
|
+
postback_url: ipn_pagarme_url(contribution, host: CatarsePagarme.configuration.host,
|
40
|
+
subdomain: CatarsePagarme.configuration.subdomain,
|
41
|
+
protocol: CatarsePagarme.configuration.protocol),
|
42
42
|
installments: get_installment,
|
43
43
|
customer: {
|
44
44
|
email: contribution.user.email,
|
@@ -8,25 +8,12 @@ module CatarsePagarme
|
|
8
8
|
contribution.payment_notifications.create(extra_data: params.to_json)
|
9
9
|
|
10
10
|
if PagarMe::validate_fingerprint(contribution.try(:payment_id), params[:fingerprint])
|
11
|
-
|
12
|
-
if params[:current_status] == 'paid' && params[:desired_status] == 'refunded'
|
13
|
-
contribution.try(:invalid_refund)
|
14
|
-
else
|
15
|
-
delegator.change_status_by_transaction(params[:current_status])
|
16
|
-
delegator.fill_acquirer_data
|
17
|
-
end
|
18
|
-
|
11
|
+
delegator.change_status_by_transaction(params[:current_status])
|
19
12
|
return render nothing: true, status: 200
|
20
13
|
end
|
21
14
|
end
|
22
15
|
|
23
16
|
render nothing: true, status: 404
|
24
17
|
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def contribution
|
29
|
-
@contribution ||= PaymentEngines.find_payment({ payment_id: params[:id] })
|
30
|
-
end
|
31
18
|
end
|
32
19
|
end
|
@@ -21,9 +21,9 @@ module CatarsePagarme
|
|
21
21
|
payment_method: 'boleto',
|
22
22
|
boleto_expiration_date: 2.days.from_now,
|
23
23
|
amount: delegator.value_for_transaction,
|
24
|
-
postback_url:
|
25
|
-
|
26
|
-
|
24
|
+
postback_url: ipn_pagarme_url(contribution, host: CatarsePagarme.configuration.host,
|
25
|
+
subdomain: CatarsePagarme.configuration.subdomain,
|
26
|
+
protocol: CatarsePagarme.configuration.protocol),
|
27
27
|
customer: {
|
28
28
|
email: contribution.user.email,
|
29
29
|
name: contribution.user.name
|
@@ -6,7 +6,7 @@ module CatarsePagarme
|
|
6
6
|
|
7
7
|
collection = installments.map do |installment|
|
8
8
|
installment_number = installment[0].to_i
|
9
|
-
if installment_number <= CatarsePagarme.configuration.max_installments
|
9
|
+
if installment_number <= CatarsePagarme.configuration.max_installments
|
10
10
|
amount = installment[1]['installment_amount'] / 100.0
|
11
11
|
|
12
12
|
optional_text = nil
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module CatarsePagarme
|
2
2
|
class ContributionDelegator
|
3
3
|
attr_accessor :contribution, :transaction
|
4
|
-
include FeeCalculatorConcern
|
5
4
|
|
6
5
|
def initialize(contribution)
|
7
6
|
configure_pagarme
|
@@ -21,15 +20,6 @@ module CatarsePagarme
|
|
21
20
|
end
|
22
21
|
end
|
23
22
|
|
24
|
-
def fill_acquirer_data
|
25
|
-
if !contribution.acquirer_name.present? || !contribution.acquirer_tid.present?
|
26
|
-
contribution.update_attributes({
|
27
|
-
acquirer_name: transaction.acquirer_name,
|
28
|
-
acquirer_tid: transaction.tid
|
29
|
-
})
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
23
|
def refund
|
34
24
|
if contribution.is_credit_card?
|
35
25
|
transaction.refund
|
@@ -52,10 +42,6 @@ module CatarsePagarme
|
|
52
42
|
end
|
53
43
|
end
|
54
44
|
|
55
|
-
def value_for_installment(installment)
|
56
|
-
get_installment(installment).try(:[], "installment_amount")
|
57
|
-
end
|
58
|
-
|
59
45
|
def transaction
|
60
46
|
@transaction ||= ::PagarMe::Transaction.find_by_id(self.contribution.payment_id)
|
61
47
|
end
|
@@ -75,6 +61,16 @@ module CatarsePagarme
|
|
75
61
|
})
|
76
62
|
end
|
77
63
|
|
64
|
+
def get_fee(payment_method, acquirer_name = nil)
|
65
|
+
if payment_method == PaymentType::SLIP
|
66
|
+
CatarsePagarme.configuration.slip_tax.to_f
|
67
|
+
else
|
68
|
+
if acquirer_name != 'cielo'
|
69
|
+
(self.contribution.value * CatarsePagarme.configuration.credit_card_tax.to_f) + CatarsePagarme.configuration.credit_card_cents_fee.to_f
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
78
74
|
protected
|
79
75
|
|
80
76
|
def bank_account_attributes
|
@@ -11,7 +11,6 @@ module CatarsePagarme
|
|
11
11
|
|
12
12
|
def change_contribution_state
|
13
13
|
self.contribution.update_attributes(attributes_to_contribution)
|
14
|
-
update_fee
|
15
14
|
self.contribution.payment_notifications.create(extra_data: self.transaction.to_json)
|
16
15
|
delegator.change_status_by_transaction(self.transaction.status)
|
17
16
|
end
|
@@ -23,22 +22,14 @@ module CatarsePagarme
|
|
23
22
|
def attributes_to_contribution
|
24
23
|
{
|
25
24
|
payment_choice: payment_method,
|
25
|
+
payment_service_fee: delegator.get_fee(payment_method, self.transaction.acquirer_name),
|
26
26
|
payment_id: self.transaction.id,
|
27
27
|
payment_method: 'Pagarme',
|
28
28
|
slip_url: self.transaction.boleto_url,
|
29
|
-
installments: (self.transaction.installments || 1)
|
30
|
-
installment_value: (delegator.value_for_installment(self.transaction.installments || 0) / 100.0).to_f,
|
31
|
-
acquirer_name: self.transaction.acquirer_name,
|
32
|
-
acquirer_tid: self.transaction.tid
|
29
|
+
installments: (self.transaction.installments || 1)
|
33
30
|
}
|
34
31
|
end
|
35
32
|
|
36
|
-
def update_fee
|
37
|
-
self.contribution.update_attributes({
|
38
|
-
payment_service_fee: delegator.get_fee(payment_method, self.transaction.acquirer_name),
|
39
|
-
})
|
40
|
-
end
|
41
|
-
|
42
33
|
def delegator
|
43
34
|
self.contribution.pagarme_delegator
|
44
35
|
end
|
@@ -3,111 +3,110 @@
|
|
3
3
|
= form_tag 'javascript:void(0);', :class => 'pagarme' do
|
4
4
|
|
5
5
|
.next_step_after_valid_document
|
6
|
+
.w-row.list_payment.w-form
|
7
|
+
.w-col.w-col-7.w-col-small-7.back-payment-moip-options-column
|
8
|
+
= radio_button_tag 'payment_type', "credit_card", false, class: 'w-radio-input back-payment-radio-button'
|
9
|
+
= label_tag :payment_type_credit_card, nil, class: "cards w-form-label" do
|
10
|
+
= image_tag 'catarse_bootstrap/payment_cards.jpg'
|
11
|
+
.w-col.w-col-5.w-col-small-5.back-payment-moip-options-column
|
12
|
+
= radio_button_tag 'payment_type', "slip", false, class: 'w-radio-input back-payment-radio-button'
|
13
|
+
= label_tag :payment_type_slip, class: "boleto w-form-label" do
|
14
|
+
= image_tag 'catarse_bootstrap/payment_boleto.jpg'
|
6
15
|
|
7
|
-
|
8
|
-
.input
|
9
|
-
= radio_button_tag 'payment_type', "credit_card"
|
10
|
-
= label_tag :payment_type_credit_card, nil, :class => "cards"
|
11
|
-
|
12
|
-
= radio_button_tag 'payment_type', "slip"
|
13
|
-
= label_tag :payment_type_slip, 'Boleto', :class => "boleto"
|
14
|
-
|
16
|
+
.formwrapper
|
15
17
|
#payment_type_credit_card_section.payment_section
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
.choose_card
|
28
|
-
ul class="my_credit_cards #{(current_user.credit_cards.present? ? '' : 'hide')}"
|
29
|
-
- current_user.credit_cards.each_with_index do |credit_card, i|
|
30
|
-
li.credit_card
|
31
|
-
.radio_button
|
32
|
-
= radio_button_tag :payment_subscription_card, credit_card.subscription_id, { checked: (i == 0) }
|
33
|
-
.select_installments
|
34
|
-
- if @contribution.value.to_f >= CatarsePagarme.configuration.minimum_value_for_installment.to_f
|
35
|
-
= select_tag :payment_card_installments, options_for_select(installments_for_select(@contribution))
|
36
|
-
.card_info
|
18
|
+
div[class="my-credit-cards w-form back-payment-form-creditcard formwrapper records-choice #{(current_user.credit_cards.present? ? '' : 'w-hidden')}"]
|
19
|
+
- current_user.credit_cards.each_with_index do |credit_card, i|
|
20
|
+
.w-row.creditcard-records
|
21
|
+
.w-col.w-col-1
|
22
|
+
.w-radio.w-clearfix.back-payment-credit-card-radio-field
|
23
|
+
= radio_button_tag :payment_subscription_card, credit_card.subscription_id, i == 0, {"data-stored" => true}
|
24
|
+
.w-col.w-col-2
|
25
|
+
.fontsize-small.fontweight-semibold.text-success
|
26
|
+
= credit_card.card_brand.upcase
|
27
|
+
.w-col.w-col-5
|
28
|
+
.fontsize-small.fontweight-semibold.u-marginbottom-20
|
37
29
|
= "XXXX.XXXX.XXXX.#{credit_card.last_digits}"
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
.bootstrap-twitter style="float: none;"
|
88
|
-
.alert.alert-danger.hide
|
89
|
-
p.error_msg
|
90
|
-
.clearfix
|
91
|
-
.bootstrap-twitter
|
92
|
-
.bootstrap-form
|
93
|
-
|
94
|
-
.bootstrap-alert
|
95
|
-
.alert.credit_alert
|
96
|
-
= t('users.current_user_fields.bank_account_hint')
|
30
|
+
.w-col.w-col-4
|
31
|
+
= select_tag :payment_card_installments, options_for_select(installments_for_select(@contribution)), class: 'w-select text-field text-field-creditcard'
|
32
|
+
.w-row.creditcard-records
|
33
|
+
.w-col.w-col-1
|
34
|
+
.w-radio.w-clearfix.back-payment-credit-card-radio-field
|
35
|
+
= radio_button_tag :payment_subscription_card, 0
|
36
|
+
.w-col.w-col-11
|
37
|
+
.fontsize-small.fontweight-semibold.fontcolor-secondary
|
38
|
+
= t('projects.contributions.edit.form_labels.user_another_card')
|
39
|
+
div[class="w-form formwrapper type_card_data #{(current_user.credit_cards.present? ? 'w-hidden' : '')}"]
|
40
|
+
.w-row
|
41
|
+
.w-col.w-col-12
|
42
|
+
.field-label.fontweight-semibold
|
43
|
+
= label_tag :payment_card_name, t('projects.contributions.edit.form_labels.payment_card_name'), class: 'field-label fontweight-semibold'
|
44
|
+
= text_field_tag :payment_card_name, nil, class: 'w-input text-field'
|
45
|
+
.w-row
|
46
|
+
.w-col.w-col-6.w-sub-col
|
47
|
+
= label_tag :payment_card_number, t('projects.contributions.edit.form_labels.payment_card_number'), class: 'fontweight-semibold field-label'
|
48
|
+
.card-brand.prefix.text-field
|
49
|
+
#payment_card_flag.fontsize-smallest.fontcolor-secondary.u-text-center
|
50
|
+
|
|
51
|
+
.card-number
|
52
|
+
= text_field_tag :payment_card_number, nil, class: 'w-input text-field postfix'
|
53
|
+
.w-col.w-col-6
|
54
|
+
.w-row
|
55
|
+
.w-col.w-col-6.w-col-small-6.w-col-tiny-6.w-sub-col-middle
|
56
|
+
= label_tag :payment_card_source, t('projects.contributions.edit.form_labels.payment_card_source'), class: 'field-label fontweight-semibold'
|
57
|
+
= text_field_tag :payment_card_source, nil, class: 'w-input text-field'
|
58
|
+
.w-col.w-col-6.w-col-small-6.w-col-tiny-6
|
59
|
+
= label_tag :payment_card_date, t('projects.contributions.edit.form_labels.payment_card_date'), class: 'field-label fontweight-semibold'
|
60
|
+
= text_field_tag :payment_card_date, nil, class: 'w-input text-field'
|
61
|
+
- if @contribution.value >= CatarsePagarme.configuration.minimum_value_for_installment
|
62
|
+
.w-row
|
63
|
+
.w-col.w-col-6.w-sub-col
|
64
|
+
= label_tag :payment_card_installments, t('projects.contributions.edit.form_labels.payment_card_installments'), class: 'field-label fontweight-semibold'
|
65
|
+
= select_tag :payment_card_installments, options_for_select(installments_for_select(@contribution)), class: 'w-select text-field'
|
66
|
+
.w-checkbox.w-clearfix
|
67
|
+
= check_box_tag :payment_save_card, 1, false, class: 'w-checkbox-input'
|
68
|
+
= label_tag :payment_save_card, t('projects.contributions.edit.payment_save_card'), class: 'w-form-label'
|
69
|
+
.w-row
|
70
|
+
.w-col.w-col-12
|
71
|
+
.payment-error-message.card.card-error.u-radius.zindex-10.u-marginbottom-30.w-hidden
|
72
|
+
.fontsize-smaller.fontweight-bold.u-marginbottom-10= t('projects.contributions.edit.review_errors_title')
|
73
|
+
.message-text.fontsize-smaller = t('.review_errors')
|
74
|
+
.w-row
|
75
|
+
.w-col.w-col-push-3.w-col-6
|
76
|
+
#card-loading.loader.u-text-center.w-col.w-col-12.u-marginbottom-30 = image_tag "catarse_bootstrap/loader.gif"
|
77
|
+
= submit_tag t('projects.contributions.review.form.labels.submit'), :class => 'btn btn-large u-marginbottom-20', :id => "credit_card_submit"
|
78
|
+
= render partial: 'terms'
|
97
79
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
80
|
+
#payment_type_slip_section.payment_section.w-hidden
|
81
|
+
= simple_form_for current_user, url: 'javascript:void(0)' do |f|
|
82
|
+
.bank_accounts
|
83
|
+
= f.simple_fields_for :bank_account do |bank_form|
|
84
|
+
.w-row
|
85
|
+
= bank_form.input :bank_id, as: :select, collection: Bank.order(:code, :name).to_collection, wrapper_html: {class: 'w-col w-col-12'}
|
86
|
+
.w-row
|
87
|
+
= bank_form.input :agency, as: :string, wrapper_html: {class: 'w-col w-sub-col-middle w-col-4 w-col-small-8'}
|
88
|
+
= bank_form.input :agency_digit, as: :string, wrapper_html: {class: 'w-col w-sub-col-middle w-sub-col w-col-2 w-col-small-4'}
|
89
|
+
= bank_form.input :account, as: :string, wrapper_html: {class: 'w-col w-sub-col-middle w-col-4 w-col-small-8'}
|
90
|
+
= bank_form.input :account_digit, as: :string, wrapper_html: {class: 'w-col w-col-2 w-col-small-4'}
|
91
|
+
.w-row
|
92
|
+
= bank_form.input :owner_name, as: :string, input_html: { value: bank_form.object.owner_name || current_user.full_name }, wrapper_html: {class: 'w-col w-sub-col w-col-6'}
|
93
|
+
= bank_form.input :owner_document, as: :string, input_html: { value: bank_form.object.owner_document || current_user.cpf }, wrapper_html: {class: 'w-col w-col-6'}
|
94
|
+
.w-row
|
95
|
+
.w-col.w-col-12
|
96
|
+
.card.card-message.u-radius.fontsize-small.zindex-10.u-marginbottom-30
|
97
|
+
| Após clicar no botão abaixo, você receberá um link com o boleto para completar o pagamento.
|
98
|
+
.w-row
|
99
|
+
.w-col.w-col-12
|
100
|
+
.payment-error-message.card.card-error.u-radius.zindex-10.u-marginbottom-30.w-hidden
|
101
|
+
.fontsize-smaller.fontweight-bold.u-marginbottom-10= t('projects.contributions.edit.review_errors_title')
|
102
|
+
.message-text.fontsize-smaller = t('.review_errors')
|
103
|
+
.w-row
|
104
|
+
.w-col.w-col-12
|
105
|
+
#payment-slip-link.card.card-message.fontsize-small.u-radius.u-marginbottom-30.zindex-10.w-hidden
|
106
|
+
.link_content.fontsize-smaller
|
107
|
+
.fontsize-smaller Você também receberá um email com esse boleto.
|
108
|
+
.w-row
|
109
|
+
.w-col.w-col-push-3.w-col-6
|
110
|
+
#card-loading.loader.u-text-center.w-col.w-col-12.u-marginbottom-30 = image_tag "catarse_bootstrap/loader.gif"
|
111
|
+
= submit_tag t('projects.contributions.review.form.labels.build_boleto'), :class => 'btn btn-large u-marginbottom-20', :id => "build_boleto"
|
112
|
+
= render partial: 'terms'
|
data/catarse_pagarme.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
19
19
|
|
20
20
|
s.add_dependency "rails", "~> 4.0"
|
21
|
-
s.add_dependency "pagarme", "~> 1.9.
|
21
|
+
s.add_dependency "pagarme", "~> 1.9.5"
|
22
22
|
|
23
23
|
s.add_development_dependency "rspec-rails", "~> 2.14.0"
|
24
24
|
s.add_development_dependency "factory_girl_rails"
|
data/config/routes.rb
CHANGED
@@ -4,15 +4,12 @@ CatarsePagarme::Engine.routes.draw do
|
|
4
4
|
member do
|
5
5
|
get :review
|
6
6
|
put :second_slip, to: 'slip#update'
|
7
|
+
post :ipn, to: 'notifications#create'
|
7
8
|
post :pay_credit_card, to: 'credit_cards#create'
|
8
9
|
post :pay_slip, to: 'slip#create'
|
9
10
|
post :pay_with_subscription, to: 'subscriptions#create'
|
10
11
|
put :pay_with_subscription, to: 'subscriptions#update'
|
11
12
|
end
|
12
13
|
|
13
|
-
collection do
|
14
|
-
post :ipn, to: 'notifications#create'
|
15
|
-
end
|
16
|
-
|
17
14
|
end
|
18
15
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module CatarsePagarme
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :api_key, :slip_tax, :credit_card_tax, :interest_rate, :host, :subdomain, :protocol,
|
4
|
-
:max_installments, :minimum_value_for_installment, :credit_card_cents_fee
|
5
|
-
:cielo_tax, :cielo_installment_diners_tax, :cielo_installment_not_diners_tax,
|
6
|
-
:cielo_installment_amex_tax, :cielo_installment_not_amex_tax
|
4
|
+
:max_installments, :minimum_value_for_installment, :credit_card_cents_fee
|
7
5
|
|
8
6
|
def initialize
|
9
7
|
self.api_key = ''
|
@@ -16,13 +14,6 @@ module CatarsePagarme
|
|
16
14
|
self.host = 'catarse.me'
|
17
15
|
self.subdomain = 'www'
|
18
16
|
self.protocol = 'http'
|
19
|
-
self.pagarme_tax = 0.0063
|
20
|
-
self.stone_tax = 0.0307
|
21
|
-
self.cielo_tax = 0.038
|
22
|
-
self.cielo_installment_diners_tax = 0.048
|
23
|
-
self.cielo_installment_not_diners_tax = 0.0455
|
24
|
-
self.cielo_installment_amex_tax = 0.058
|
25
|
-
self.cielo_installment_not_amex_tax = 0.048
|
26
17
|
end
|
27
18
|
end
|
28
19
|
end
|
@@ -27,12 +27,12 @@ describe CatarsePagarme::CreditCardsController do
|
|
27
27
|
before do
|
28
28
|
post :create, {
|
29
29
|
locale: :pt, project_id: project.id, contribution_id: contribution.id, use_route: 'catarse_pagarme',
|
30
|
-
payment_card_date: '10/17', payment_card_number: '
|
31
|
-
payment_card_source: '
|
30
|
+
payment_card_date: '10/17', payment_card_number: '4901720080344448', payment_card_name: 'Foo bar',
|
31
|
+
payment_card_source: '143', payment_card_installments: '1' }
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
|
-
it 'payment_status should be filled' do
|
35
|
+
it 'payment_status should be filled and not failed' do
|
36
36
|
expect(ActiveSupport::JSON.decode(response.body)['payment_status']).not_to be_nil
|
37
37
|
end
|
38
38
|
|
@@ -1,20 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe CatarsePagarme::NotificationsController do
|
4
|
-
let(:fake_transaction) {
|
5
|
-
t = double
|
6
|
-
t.stub(:card_brand).and_return('visa')
|
7
|
-
t.stub(:acquirer_name).and_return('stone')
|
8
|
-
t.stub(:tid).and_return('404040404')
|
9
|
-
t
|
10
|
-
}
|
11
4
|
before do
|
12
5
|
PagarMe.stub(:validate_fingerprint).and_return(true)
|
13
|
-
PagarMe::Transaction.stub(:find_by_id).and_return(fake_transaction)
|
14
6
|
end
|
15
7
|
|
16
8
|
let(:project) { create(:project, goal: 10_000, state: 'online') }
|
17
|
-
let(:contribution) { create(:contribution, value: 10, project: project
|
9
|
+
let(:contribution) { create(:contribution, value: 10, project: project) }
|
18
10
|
let(:credit_card) { create(:credit_card, subscription_id: '1542')}
|
19
11
|
|
20
12
|
describe 'CREATE' do
|
@@ -32,7 +24,7 @@ describe CatarsePagarme::NotificationsController do
|
|
32
24
|
context "with valid contribution" do
|
33
25
|
before do
|
34
26
|
PaymentEngines.stub(:find_payment).and_return(contribution)
|
35
|
-
post :create, { locale: :pt, id:
|
27
|
+
post :create, { locale: :pt, id: contribution.id, use_route: 'catarse_pagarme' }
|
36
28
|
end
|
37
29
|
|
38
30
|
it "should save an extra_data into payment_notifications" do
|
@@ -30,22 +30,9 @@ describe CatarsePagarme::ContributionDelegator do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
context "#get_fee" do
|
33
|
-
let(:fake_transaction) {
|
34
|
-
t = double
|
35
|
-
t.stub(:card_brand).and_return('visa')
|
36
|
-
t.stub(:acquirer_name).and_return('stone')
|
37
|
-
t.stub(:acquirer_tid).and_return('404040404')
|
38
|
-
t
|
39
|
-
}
|
40
|
-
|
41
33
|
before do
|
42
34
|
CatarsePagarme.configuration.stub(:slip_tax).and_return(2.00)
|
43
35
|
CatarsePagarme.configuration.stub(:credit_card_tax).and_return(0.01)
|
44
|
-
CatarsePagarme.configuration.stub(:pagarme_tax).and_return(0.0063)
|
45
|
-
CatarsePagarme.configuration.stub(:cielo_tax).and_return(0.038)
|
46
|
-
CatarsePagarme.configuration.stub(:stone_tax).and_return(0.0307)
|
47
|
-
|
48
|
-
delegator.stub(:transaction).and_return(fake_transaction)
|
49
36
|
end
|
50
37
|
|
51
38
|
context 'when choice is slip' do
|
@@ -55,7 +42,7 @@ describe CatarsePagarme::ContributionDelegator do
|
|
55
42
|
|
56
43
|
context 'when choice is credit card' do
|
57
44
|
subject { delegator.get_fee(CatarsePagarme::PaymentType::CREDIT_CARD).to_f }
|
58
|
-
it { expect(subject).to eq(0.
|
45
|
+
it { expect(subject).to eq(0.49) }
|
59
46
|
end
|
60
47
|
end
|
61
48
|
|
@@ -11,7 +11,6 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
11
11
|
transaction.stub(:boleto_url).and_return(nil)
|
12
12
|
transaction.stub(:installments).and_return(3)
|
13
13
|
transaction.stub(:acquirer_name).and_return('stone')
|
14
|
-
transaction.stub(:tid).and_return('123123')
|
15
14
|
transaction
|
16
15
|
}
|
17
16
|
|
@@ -40,7 +39,7 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
40
39
|
describe '#charge!' do
|
41
40
|
describe 'with valid attributes' do
|
42
41
|
before do
|
43
|
-
contribution.should_receive(:update_attributes).
|
42
|
+
contribution.should_receive(:update_attributes).and_call_original
|
44
43
|
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
45
44
|
|
46
45
|
card_transaction.charge!
|
@@ -52,7 +51,7 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
52
51
|
end
|
53
52
|
|
54
53
|
it "should update contribution payment_service_fee" do
|
55
|
-
expect(contribution.payment_service_fee.to_f).to eq(
|
54
|
+
expect(contribution.payment_service_fee.to_f).to eq(1.39)
|
56
55
|
end
|
57
56
|
|
58
57
|
it "should update contribution payment_method" do
|
@@ -66,18 +65,6 @@ describe CatarsePagarme::CreditCardTransaction do
|
|
66
65
|
it "should update contribution payment_choice" do
|
67
66
|
expect(contribution.payment_choice).to eq(CatarsePagarme::PaymentType::CREDIT_CARD)
|
68
67
|
end
|
69
|
-
|
70
|
-
it "should update contribution acquirer_name" do
|
71
|
-
expect(contribution.acquirer_name).to eq('stone')
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should update contribution acquirer_tid" do
|
75
|
-
expect(contribution.acquirer_tid).to eq('123123')
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should update contribution installment_value" do
|
79
|
-
expect(contribution.installment_value).to_not be_nil
|
80
|
-
end
|
81
68
|
end
|
82
69
|
end
|
83
70
|
|
@@ -8,9 +8,8 @@ describe CatarsePagarme::SlipTransaction do
|
|
8
8
|
transaction.stub(:charge).and_return(true)
|
9
9
|
transaction.stub(:status).and_return('paid')
|
10
10
|
transaction.stub(:boleto_url).and_return('boleto url')
|
11
|
-
transaction.stub(:installments).and_return(
|
11
|
+
transaction.stub(:installments).and_return(nil)
|
12
12
|
transaction.stub(:acquirer_name).and_return('pagarme')
|
13
|
-
transaction.stub(:tid).and_return('123123')
|
14
13
|
transaction
|
15
14
|
}
|
16
15
|
let(:valid_attributes) do
|
@@ -72,7 +71,7 @@ describe CatarsePagarme::SlipTransaction do
|
|
72
71
|
before do
|
73
72
|
slip_transaction.should_receive(:update_user_bank_account).and_call_original
|
74
73
|
slip_transaction.user.should_receive(:update_attributes).and_return(true)
|
75
|
-
contribution.should_receive(:update_attributes).
|
74
|
+
contribution.should_receive(:update_attributes).and_call_original
|
76
75
|
CatarsePagarme::ContributionDelegator.any_instance.should_receive(:change_status_by_transaction).with('paid')
|
77
76
|
|
78
77
|
slip_transaction.charge!
|
@@ -98,18 +97,6 @@ describe CatarsePagarme::SlipTransaction do
|
|
98
97
|
it "should update contribution payment_choice" do
|
99
98
|
expect(contribution.payment_choice).to eq(CatarsePagarme::PaymentType::SLIP)
|
100
99
|
end
|
101
|
-
|
102
|
-
it "should update contribution acquirer_name" do
|
103
|
-
expect(contribution.acquirer_name).to eq('pagarme')
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should update contribution acquirer_tid" do
|
107
|
-
expect(contribution.acquirer_tid).to eq('123123')
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should update contribution installment_value" do
|
111
|
-
expect(contribution.installment_value).to_not be_nil
|
112
|
-
end
|
113
100
|
end
|
114
101
|
end
|
115
102
|
|
data/spec/spec_helper.rb
CHANGED
@@ -30,7 +30,7 @@ RSpec.configure do |config|
|
|
30
30
|
end
|
31
31
|
|
32
32
|
config.before(:each) do
|
33
|
-
PagarMe.stub(:api_key).and_return('
|
33
|
+
PagarMe.stub(:api_key).and_return('ak_test_Rw4JR98FmYST2ngEHtMvVf5QJW7Eoo')
|
34
34
|
PaymentEngines.stub(:configuration).and_return({})
|
35
35
|
end
|
36
36
|
end
|
data/spec/support/factories.rb
CHANGED
@@ -32,19 +32,14 @@ FactoryGirl.define do
|
|
32
32
|
f.name_pt { generate(:name) }
|
33
33
|
end
|
34
34
|
|
35
|
-
factory :bank do |f|
|
36
|
-
f.name { generate(:uid) }
|
37
|
-
f.code { generate(:uid) }
|
38
|
-
end
|
39
|
-
|
40
35
|
factory :bank_account do |f|
|
41
|
-
f.
|
36
|
+
f.name 'Foo bar'
|
42
37
|
f.account '1234'
|
43
38
|
f.account_digit '1'
|
44
39
|
f.agency '1'
|
45
40
|
f.agency_digit '2'
|
46
|
-
f.
|
47
|
-
f.
|
41
|
+
f.user_name 'fooo'
|
42
|
+
f.user_document '9889'
|
48
43
|
end
|
49
44
|
|
50
45
|
factory :project do |f|
|
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:
|
4
|
+
version: 2.0.0
|
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:
|
12
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 1.9.
|
34
|
+
version: 1.9.5
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 1.9.
|
41
|
+
version: 1.9.5
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec-rails
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,18 +110,17 @@ files:
|
|
110
110
|
- app/controllers/catarse_pagarme/slip_controller.rb
|
111
111
|
- app/controllers/catarse_pagarme/subscriptions_controller.rb
|
112
112
|
- app/helpers/catarse_pagarme/application_helper.rb
|
113
|
-
- app/models/catarse_pagarme/bank_account_concern.rb
|
114
113
|
- app/models/catarse_pagarme/contribution_concern.rb
|
115
114
|
- app/models/catarse_pagarme/contribution_delegator.rb
|
116
115
|
- app/models/catarse_pagarme/credit_card_concern.rb
|
117
116
|
- app/models/catarse_pagarme/credit_card_delegator.rb
|
118
117
|
- app/models/catarse_pagarme/credit_card_transaction.rb
|
119
|
-
- app/models/catarse_pagarme/fee_calculator_concern.rb
|
120
118
|
- app/models/catarse_pagarme/payment_type.rb
|
121
119
|
- app/models/catarse_pagarme/save_credit_card_transaction.rb
|
122
120
|
- app/models/catarse_pagarme/slip_transaction.rb
|
123
121
|
- app/models/catarse_pagarme/subscription_transaction.rb
|
124
122
|
- app/models/catarse_pagarme/transaction_base.rb
|
123
|
+
- app/views/catarse_pagarme/pagarme/_terms.html.slim
|
125
124
|
- app/views/catarse_pagarme/pagarme/review.html.slim
|
126
125
|
- app/views/layouts/catarse_pagarme/application.html.erb
|
127
126
|
- bin/rails
|
@@ -191,7 +190,6 @@ files:
|
|
191
190
|
- spec/dummy/public/500.html
|
192
191
|
- spec/dummy/public/favicon.ico
|
193
192
|
- spec/helpers/catarse_pagarme/application_helper_spec.rb
|
194
|
-
- spec/models/catarse_pagarme/bank_account_concern_spec.rb
|
195
193
|
- spec/models/catarse_pagarme/contribution_delegator_spec.rb
|
196
194
|
- spec/models/catarse_pagarme/credit_card_transaction_spec.rb
|
197
195
|
- spec/models/catarse_pagarme/slip_transaction_spec.rb
|
@@ -278,7 +276,6 @@ test_files:
|
|
278
276
|
- spec/dummy/public/500.html
|
279
277
|
- spec/dummy/public/favicon.ico
|
280
278
|
- spec/helpers/catarse_pagarme/application_helper_spec.rb
|
281
|
-
- spec/models/catarse_pagarme/bank_account_concern_spec.rb
|
282
279
|
- spec/models/catarse_pagarme/contribution_delegator_spec.rb
|
283
280
|
- spec/models/catarse_pagarme/credit_card_transaction_spec.rb
|
284
281
|
- spec/models/catarse_pagarme/slip_transaction_spec.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module CatarsePagarme::BankAccountConcern
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
|
6
|
-
validate :must_be_valid_on_pagarme
|
7
|
-
|
8
|
-
def must_be_valid_on_pagarme
|
9
|
-
pagarme_errors.each do |p_error|
|
10
|
-
_attr = attributes_parsed_from_pagarme[p_error.parameter_name.to_sym]
|
11
|
-
errors.add(_attr, :invalid)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def pagarme_errors
|
18
|
-
configure_pagarme
|
19
|
-
bank_account = ::PagarMe::BankAccount.new(attributes_parsed_to_pagarme)
|
20
|
-
|
21
|
-
begin
|
22
|
-
bank_account.create
|
23
|
-
|
24
|
-
[]
|
25
|
-
rescue Exception => e
|
26
|
-
e.errors
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def attributes_parsed_to_pagarme
|
31
|
-
{
|
32
|
-
bank_code: self.bank.try(:code),
|
33
|
-
agencia: self.agency,
|
34
|
-
agencia_dv: self.agency_digit,
|
35
|
-
conta: self.account,
|
36
|
-
conta_dv: self.account_digit,
|
37
|
-
legal_name: self.owner_name,
|
38
|
-
document_number: self.owner_document
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
def attributes_parsed_from_pagarme
|
43
|
-
{
|
44
|
-
bank_code: :bank,
|
45
|
-
agencia: :agency,
|
46
|
-
agencia_dv: :agency_digit,
|
47
|
-
conta: :account,
|
48
|
-
conta_dv: :account_digit,
|
49
|
-
legal_name: :owner_name,
|
50
|
-
document_number: :owner_document
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def configure_pagarme
|
55
|
-
::PagarMe.api_key = CatarsePagarme.configuration.api_key
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module CatarsePagarme::FeeCalculatorConcern
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
|
6
|
-
def get_fee(payment_method, acquirer_name = nil)
|
7
|
-
if payment_method == ::CatarsePagarme::PaymentType::SLIP
|
8
|
-
CatarsePagarme.configuration.slip_tax.to_f
|
9
|
-
else
|
10
|
-
if acquirer_name == 'stone'
|
11
|
-
self.contribution.installments > 1 ? tax_calc_for_installment(stone_tax) : tax_calc(stone_tax)
|
12
|
-
else
|
13
|
-
if self.transaction.card_brand == 'amex'
|
14
|
-
self.contribution.installments > 1 ? tax_calc_for_installment(cielo_installment_amex_tax) : tax_calc(cielo_installment_not_amex_tax)
|
15
|
-
else
|
16
|
-
current_tax = self.transaction.card_brand == 'diners' ? installment_diners_tax : installment_not_diners_tax
|
17
|
-
self.contribution.installments > 1 ? tax_calc_for_installment(current_tax) : tax_calc(cielo_tax)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
protected
|
24
|
-
|
25
|
-
def tax_calc acquirer_tax
|
26
|
-
((self.contribution.value * pagarme_tax) + cents_fee).round(2) + (self.contribution.value * acquirer_tax).round(2)
|
27
|
-
end
|
28
|
-
|
29
|
-
def tax_calc_for_installment acquirer_tax
|
30
|
-
(((self.contribution.installment_value * self.contribution.installments) * pagarme_tax) + cents_fee).round(2) + ((self.contribution.installment_value * acquirer_tax).round(2) * self.contribution.installments)
|
31
|
-
end
|
32
|
-
|
33
|
-
def cents_fee
|
34
|
-
CatarsePagarme.configuration.credit_card_cents_fee.to_f
|
35
|
-
end
|
36
|
-
|
37
|
-
def pagarme_tax
|
38
|
-
CatarsePagarme.configuration.pagarme_tax.to_f
|
39
|
-
end
|
40
|
-
|
41
|
-
def cielo_tax
|
42
|
-
CatarsePagarme.configuration.cielo_tax.to_f
|
43
|
-
end
|
44
|
-
|
45
|
-
def stone_tax
|
46
|
-
CatarsePagarme.configuration.stone_tax.to_f
|
47
|
-
end
|
48
|
-
|
49
|
-
def installment_diners_tax
|
50
|
-
CatarsePagarme.configuration.cielo_installment_diners_tax.to_f
|
51
|
-
end
|
52
|
-
|
53
|
-
def installment_not_diners_tax
|
54
|
-
CatarsePagarme.configuration.cielo_installment_not_diners_tax.to_f
|
55
|
-
end
|
56
|
-
|
57
|
-
def cielo_installment_amex_tax
|
58
|
-
CatarsePagarme.configuration.cielo_installment_amex_tax.to_f
|
59
|
-
end
|
60
|
-
|
61
|
-
def cielo_installment_not_amex_tax
|
62
|
-
CatarsePagarme.configuration.cielo_installment_not_amex_tax.to_f
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class FakeBankAccount < BankAccount
|
4
|
-
include CatarsePagarme::BankAccountConcern
|
5
|
-
end
|
6
|
-
|
7
|
-
describe FakeBankAccount do
|
8
|
-
let(:bank) { create(:bank) }
|
9
|
-
|
10
|
-
let(:valid_attr) do
|
11
|
-
vb = build(:bank_account, bank: bank)
|
12
|
-
vb.attributes
|
13
|
-
end
|
14
|
-
|
15
|
-
let(:valid_attr_on_pagarme) do
|
16
|
-
{
|
17
|
-
bank_id: bank.id,
|
18
|
-
agency: '1732',
|
19
|
-
agency_dv: '8',
|
20
|
-
account: '25483',
|
21
|
-
account_dv: 'X',
|
22
|
-
owner_name: 'Lorem Ipsum',
|
23
|
-
owner_document: '111.111.111-11'
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "validate :must_be_valid_on_pagarme" do
|
28
|
-
context "when bank account has invalid data on pagarme" do
|
29
|
-
let(:bank_account_on_pagarme) { FakeBankAccount.new(valid_attr) }
|
30
|
-
let(:local_bank_account) { BankAccount.new(valid_attr) }
|
31
|
-
|
32
|
-
it "local_bank_account should be valid" do
|
33
|
-
expect(local_bank_account.valid?).to be_true
|
34
|
-
end
|
35
|
-
|
36
|
-
it "bank_account_on_pagarme should be not valid with these attrs" do
|
37
|
-
expect(bank_account_on_pagarme.valid?).to be_false
|
38
|
-
end
|
39
|
-
|
40
|
-
it "bank_account_on_pagarme should be valid with another attrs" do
|
41
|
-
subject { FakeBankAccount.new(valid_attr_on_pagarme).valid? }
|
42
|
-
expect(subject).to be_true
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|