catarse_moip 3.0.5 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/app/controllers/catarse_moip/moip_controller.rb +1 -1
- data/app/models/catarse_moip/v2/refund.rb +121 -0
- data/catarse_moip.gemspec +1 -0
- data/config/initializers/moip.rb +10 -0
- data/lib/catarse_moip.rb +2 -0
- data/lib/catarse_moip/payment_engine.rb +3 -3
- data/lib/catarse_moip/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d12d6661c0c2fea0cf6db1f31417dea3fe3ff9
|
4
|
+
data.tar.gz: fcb733a18ebefe201573ae0477e670f734bd78e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec4fe6c6f10891dee83d88e70b99364f409606490d35bbde96e43c0b80614afe9e0b1d892af0ef6a4ae3217bb08b3638dddb9836beb5698333d2305639531f4b
|
7
|
+
data.tar.gz: 71f9e3ed025c76154eaa6b8179dfba1f866bac8ee299e067d0eceb9629b8df767f48c9d60b076d2ff1af475e4919a4305f82384f9451c2c986f167bb5d52590d
|
data/Gemfile.lock
CHANGED
@@ -12,6 +12,7 @@ PATH
|
|
12
12
|
specs:
|
13
13
|
catarse_moip (3.0.5)
|
14
14
|
enumerate_it
|
15
|
+
httparty
|
15
16
|
libxml-ruby (~> 2.6.0)
|
16
17
|
rails (~> 4.0)
|
17
18
|
|
@@ -104,7 +105,7 @@ GEM
|
|
104
105
|
rspec-core (~> 2.14.0)
|
105
106
|
rspec-expectations (~> 2.14.0)
|
106
107
|
rspec-mocks (~> 2.14.0)
|
107
|
-
sprockets (2.12.
|
108
|
+
sprockets (2.12.3)
|
108
109
|
hike (~> 1.2)
|
109
110
|
multi_json (~> 1.0)
|
110
111
|
rack (~> 1.0)
|
@@ -137,7 +137,7 @@ module CatarseMoip
|
|
137
137
|
case params[:status_pagamento].to_i
|
138
138
|
when TransactionStatus::PROCESS
|
139
139
|
payment_notification.deliver_process_notification
|
140
|
-
when TransactionStatus::AUTHORIZED
|
140
|
+
when TransactionStatus::AUTHORIZED, TransactionStatus::FINISHED
|
141
141
|
contribution.confirm! unless contribution.confirmed?
|
142
142
|
when TransactionStatus::WRITTEN_BACK, TransactionStatus::REFUNDED
|
143
143
|
contribution.refund! unless contribution.refunded?
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module CatarseMoip
|
2
|
+
module V2
|
3
|
+
class Refund
|
4
|
+
include ::HTTParty
|
5
|
+
|
6
|
+
base_uri ::MOIP_V2_ENDPOINT
|
7
|
+
|
8
|
+
attr_accessor :contribution, :refund_options
|
9
|
+
|
10
|
+
def self.start(contribution)
|
11
|
+
_instance = new(contribution)
|
12
|
+
_instance.refund
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(contribution)
|
16
|
+
self.contribution = contribution
|
17
|
+
self.refund_options = define_refund_options
|
18
|
+
end
|
19
|
+
|
20
|
+
def refund
|
21
|
+
self.class.post("/v2/payments/#{parsed_payment_id}/refunds", {
|
22
|
+
body: self.refund_options.to_json
|
23
|
+
}.merge!(basic_auth_params))
|
24
|
+
end
|
25
|
+
|
26
|
+
def define_refund_options
|
27
|
+
if refund_method == 'BANK_ACCOUNT'
|
28
|
+
check_bank_account!
|
29
|
+
{
|
30
|
+
amount: amount_to_refund,
|
31
|
+
method: refund_method,
|
32
|
+
refundingInstrument: refund_instrument
|
33
|
+
}
|
34
|
+
else
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def check_bank_account!
|
42
|
+
unless bank_account.valid?
|
43
|
+
raise "Invalid bank account"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def refund_instrument
|
48
|
+
{
|
49
|
+
method: refund_method,
|
50
|
+
bankAccount: {
|
51
|
+
type: 'CHECKING',
|
52
|
+
bankNumber: bank_account.bank_code,
|
53
|
+
agencyNumber: bank_account.agency.to_i,
|
54
|
+
agencyCheckNumber: bank_account.agency_digit.to_i,
|
55
|
+
accountNumber: bank_account.account.to_i,
|
56
|
+
accountCheckNumber: bank_account.account_digit.to_i,
|
57
|
+
holder: {
|
58
|
+
fullname: bank_account.owner_name,
|
59
|
+
taxDocument: {
|
60
|
+
type: bank_account_document_type,
|
61
|
+
number: parsed_holder_document
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def bank_account
|
69
|
+
self.contribution.user.bank_account
|
70
|
+
end
|
71
|
+
|
72
|
+
def bank_account_document_type
|
73
|
+
if parsed_holder_document.size > 11
|
74
|
+
'CNPJ'
|
75
|
+
else
|
76
|
+
'CPF'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def parsed_holder_document
|
81
|
+
bank_account.owner_document.gsub(/[\.\-\/\s]/,'')
|
82
|
+
end
|
83
|
+
|
84
|
+
def amount_to_refund
|
85
|
+
if already_expired_refund_deadline?
|
86
|
+
((self.contribution.value - self.contribution.payment_service_fee.to_f) * 100).to_i
|
87
|
+
else
|
88
|
+
self.contribution.price_in_cents
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def refund_method
|
93
|
+
if already_expired_refund_deadline? || !self.contribution.is_credit_card?
|
94
|
+
'BANK_ACCOUNT'
|
95
|
+
else
|
96
|
+
'CREDIT_CARD'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def already_expired_refund_deadline?
|
101
|
+
self.contribution.confirmed_at < 170.days.ago
|
102
|
+
end
|
103
|
+
|
104
|
+
def basic_auth_params
|
105
|
+
{
|
106
|
+
basic_auth: {
|
107
|
+
username: PaymentEngines.configuration[:moip_token],
|
108
|
+
password: PaymentEngines.configuration[:moip_key],
|
109
|
+
},
|
110
|
+
headers: {
|
111
|
+
'Content-Type' => 'application/json'
|
112
|
+
}
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
def parsed_payment_id
|
117
|
+
contribution.payment_id.gsub('.', '')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/catarse_moip.gemspec
CHANGED
data/config/initializers/moip.rb
CHANGED
@@ -3,3 +3,13 @@
|
|
3
3
|
config.token = (PaymentEngines.configuration.get_without_cache(:moip_token) rescue nil) || ''
|
4
4
|
config.key = (PaymentEngines.configuration.get_without_cache(:moip_key) rescue nil) || ''
|
5
5
|
end
|
6
|
+
|
7
|
+
MOIP_V2_ENDPOINT = begin
|
8
|
+
if PaymentEngines.configuration.get_without_cache(:moip_test) == 'true'
|
9
|
+
'https://test.moip.com.br'
|
10
|
+
else
|
11
|
+
'https://api.moip.com.br'
|
12
|
+
end
|
13
|
+
rescue Exception => e
|
14
|
+
'https://test.moip.com.br'
|
15
|
+
end
|
data/lib/catarse_moip.rb
CHANGED
data/lib/catarse_moip/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catarse_moip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antônio Roberto Silva
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-11-
|
13
|
+
date: 2014-11-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - "~>"
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: '4.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: httparty
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: libxml-ruby
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,6 +135,7 @@ files:
|
|
121
135
|
- app/assets/javascripts/catarse_moip/payment_slip.js
|
122
136
|
- app/assets/javascripts/catarse_moip/user_document.js
|
123
137
|
- app/controllers/catarse_moip/moip_controller.rb
|
138
|
+
- app/models/catarse_moip/v2/refund.rb
|
124
139
|
- app/views/catarse_moip/moip/_terms.html.slim
|
125
140
|
- app/views/catarse_moip/moip/review.html.slim
|
126
141
|
- catarse_moip.gemspec
|