catarse_moip 2.3.6 → 2.4.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 +3 -2
- 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: 854311602c06cc63096b63f16afcd185651f9785
|
4
|
+
data.tar.gz: 408660bff34b36cd055506a66b41ab06c41a4c0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb65373e9e9a4833fe388782bc5a54d32a714db952b6c7a360bf4101d1d30af47c8b3fdf1e410f4e642b5d32525f84f802b868a8ba70af5ac66993984636be8c
|
7
|
+
data.tar.gz: 8d5da792104b78a35ca04b81644a5c22ec0189173ce3cc92e24069380146e746b07ec718f524b2bea2110229f229eb86296c315a4c003ccced3b748da6b00d59
|
data/Gemfile.lock
CHANGED
@@ -10,8 +10,9 @@ GIT
|
|
10
10
|
PATH
|
11
11
|
remote: .
|
12
12
|
specs:
|
13
|
-
catarse_moip (2.
|
13
|
+
catarse_moip (2.4.0)
|
14
14
|
enumerate_it
|
15
|
+
httparty
|
15
16
|
libxml-ruby (~> 2.6.0)
|
16
17
|
rails (~> 4.0)
|
17
18
|
|
@@ -98,7 +99,7 @@ GEM
|
|
98
99
|
rspec-core (~> 2.14.0)
|
99
100
|
rspec-expectations (~> 2.14.0)
|
100
101
|
rspec-mocks (~> 2.14.0)
|
101
|
-
sprockets (2.12.
|
102
|
+
sprockets (2.12.3)
|
102
103
|
hike (~> 1.2)
|
103
104
|
multi_json (~> 1.0)
|
104
105
|
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: 2.
|
4
|
+
version: 2.4.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-
|
13
|
+
date: 2014-11-27 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/review.html.slim
|
125
140
|
- catarse_moip.gemspec
|
126
141
|
- config/initializers/moip.rb
|