pagarme 2.1.3 → 2.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pagarme.rb +7 -0
- data/lib/pagarme/errors.rb +8 -0
- data/lib/pagarme/model.rb +14 -8
- data/lib/pagarme/nested_model.rb +7 -8
- data/lib/pagarme/object.rb +1 -1
- data/lib/pagarme/resources/balance_operation.rb +7 -6
- data/lib/pagarme/resources/company.rb +1 -1
- data/lib/pagarme/resources/postback.rb +5 -0
- data/lib/pagarme/resources/recipient.rb +4 -3
- data/lib/pagarme/resources/transaction.rb +15 -7
- data/lib/pagarme/version.rb +1 -1
- data/pagarme.gemspec +1 -0
- data/test/pagarme/resources/bank_account_test.rb +5 -5
- data/test/pagarme/resources/recipient_test.rb +1 -1
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 578deddbc00fc81efa0bfd3bc0c2d76503346933
|
4
|
+
data.tar.gz: c1448b5d1f4d746bd67e3c1718b75fecf524194d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 683f3c56c311fc53eedc8bf3888e8a48daf08aa6210e01146d707d06c0fa9f33f13cd6131a2f28d3b71a31a4cea1510c9195854d7dbee60da7ee130dd99b1a13
|
7
|
+
data.tar.gz: 80585f459e4bd2dee596ad344a6004b12d36961ba7488897b5a979cf778fd7875309500a29798886d3ad21a5afa3d0bfaebb458db91f7af561e33485e8a1202b
|
data/lib/pagarme.rb
CHANGED
@@ -31,4 +31,11 @@ module PagarMe
|
|
31
31
|
def self.validate_fingerprint(*args)
|
32
32
|
raise '[Deprecation Error] PagarMe.validate_fingerprint is deprecated, use PagarMe::Postback.valid_request_signature? instead'
|
33
33
|
end
|
34
|
+
|
35
|
+
def self.production?
|
36
|
+
ENV['RACK_ENV'] == 'production' ||
|
37
|
+
ENV['RAILS_ENV'] == 'production' ||
|
38
|
+
ENV['PRODUCTION'] ||
|
39
|
+
ENV['production']
|
40
|
+
end
|
34
41
|
end
|
data/lib/pagarme/errors.rb
CHANGED
@@ -42,6 +42,10 @@ module PagarMe
|
|
42
42
|
end
|
43
43
|
super @errors.map(&:message).join(', ')
|
44
44
|
end
|
45
|
+
|
46
|
+
def to_h
|
47
|
+
@errors.map(&:to_h)
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
class ParamError < PagarMeError
|
@@ -51,5 +55,9 @@ module PagarMe
|
|
51
55
|
@parameter_name, @type, @url = parameter_name, type, url
|
52
56
|
super message
|
53
57
|
end
|
58
|
+
|
59
|
+
def to_h
|
60
|
+
{ parameter_name: parameter_name , type: type , message: message }
|
61
|
+
end
|
54
62
|
end
|
55
63
|
end
|
data/lib/pagarme/model.rb
CHANGED
@@ -28,19 +28,19 @@ module PagarMe
|
|
28
28
|
end
|
29
29
|
alias :find :find_by_id
|
30
30
|
|
31
|
-
def find_by(
|
32
|
-
|
31
|
+
def find_by(params = Hash.new, page = nil, count = nil)
|
32
|
+
params = extract_page_count_or_params(page, count, **params)
|
33
|
+
raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
|
33
34
|
|
34
|
-
PagarMe::Request.get(url, params:
|
35
|
-
page: page,
|
36
|
-
count: count
|
37
|
-
)).call
|
35
|
+
PagarMe::Request.get(url, params: params).call
|
38
36
|
end
|
39
37
|
alias :find_by_hash :find_by
|
40
38
|
|
41
|
-
def all(
|
42
|
-
|
39
|
+
def all(*args, **params)
|
40
|
+
params = extract_page_count_or_params(*args, **params)
|
41
|
+
find_by params
|
43
42
|
end
|
43
|
+
alias :where :all
|
44
44
|
|
45
45
|
def url(*params)
|
46
46
|
["/#{ CGI.escape underscored_class_name }s", *params].join '/'
|
@@ -54,6 +54,12 @@ module PagarMe
|
|
54
54
|
class_name.gsub(/[a-z0-9][A-Z]/){|s| "#{s[0]}_#{s[1]}"}.downcase
|
55
55
|
end
|
56
56
|
|
57
|
+
def extract_page_count_or_params(*args, **params)
|
58
|
+
params[:page] ||= args[0] || 1
|
59
|
+
params[:count] ||= args[1] || 10
|
60
|
+
params
|
61
|
+
end
|
62
|
+
|
57
63
|
end
|
58
64
|
end
|
59
65
|
end
|
data/lib/pagarme/nested_model.rb
CHANGED
@@ -36,21 +36,20 @@ module PagarMe
|
|
36
36
|
end
|
37
37
|
alias :find :find_by_id
|
38
38
|
|
39
|
-
def find_by(parent_id,
|
40
|
-
|
39
|
+
def find_by(parent_id, params = Hash.new, page = nil, count = nil)
|
40
|
+
params = extract_page_count_or_params(page, count, **params)
|
41
|
+
raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
|
41
42
|
|
42
|
-
PagarMe::Request.get(url(parent_id), params:
|
43
|
-
page: page,
|
44
|
-
count: count
|
45
|
-
)).call.map do |object|
|
43
|
+
PagarMe::Request.get(url(parent_id), params: params).call.map do |object|
|
46
44
|
object.parent_id = parent_id
|
47
45
|
object
|
48
46
|
end
|
49
47
|
end
|
50
48
|
alias :find_by_hash :find_by
|
51
49
|
|
52
|
-
def all(parent_id,
|
53
|
-
|
50
|
+
def all(parent_id, *args, **params)
|
51
|
+
params = extract_page_count_or_params(*args, **params)
|
52
|
+
find_by parent_id, params
|
54
53
|
end
|
55
54
|
|
56
55
|
def url(parent_id, *params)
|
data/lib/pagarme/object.rb
CHANGED
@@ -18,17 +18,18 @@ module PagarMe
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
def balance_operations(
|
22
|
-
|
21
|
+
def balance_operations(*args, **params)
|
22
|
+
params = PagarMe::Model.extract_page_count_or_params(*args, **params)
|
23
|
+
raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
|
23
24
|
|
24
|
-
params = { page: page, count: count }
|
25
25
|
PagarMe::Request.get(url, params: params).call
|
26
26
|
end
|
27
27
|
|
28
|
-
def find_by_recipient_id(recipient_id,
|
29
|
-
|
28
|
+
def find_by_recipient_id(recipient_id, *args, **params)
|
29
|
+
params = PagarMe::Model.extract_page_count_or_params(*args, **params)
|
30
|
+
raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
|
31
|
+
raise RequestError.new('Invalid ID') unless recipient_id.present?
|
30
32
|
|
31
|
-
params = { page: page, count: count }
|
32
33
|
PagarMe::Request.get(url(recipient_id), params: params).call
|
33
34
|
end
|
34
35
|
end
|
@@ -4,6 +4,11 @@ module PagarMe
|
|
4
4
|
self.class.valid_request_signature? payload, signature
|
5
5
|
end
|
6
6
|
|
7
|
+
def redirect(url = 'http://localhost:3000/pagarme/postback')
|
8
|
+
uri = URI(url)
|
9
|
+
Net::HTTP.new(uri.host, uri.port).post uri.path, payload, JSON.parse(headers)
|
10
|
+
end
|
11
|
+
|
7
12
|
class << self
|
8
13
|
def valid_request_signature?(payload, signature)
|
9
14
|
kind, raw_signature = signature.split '=', 2
|
@@ -4,9 +4,10 @@ module PagarMe
|
|
4
4
|
PagarMe::BulkAnticipation.bulk_anticipations_limits id, params
|
5
5
|
end
|
6
6
|
|
7
|
-
def bulk_anticipations(
|
8
|
-
|
9
|
-
|
7
|
+
def bulk_anticipations(*args, **params)
|
8
|
+
params = self.class.extract_page_count_or_params(*args, **params)
|
9
|
+
raise RequestError.new('Invalid page count') if params[:page] < 1 or params[:count] < 1
|
10
|
+
PagarMe::BulkAnticipation.all id, params
|
10
11
|
end
|
11
12
|
|
12
13
|
def bulk_anticipate(params = Hash.new)
|
@@ -18,6 +18,14 @@ module PagarMe
|
|
18
18
|
PagarMe::Request.get( url 'postbacks' ).call
|
19
19
|
end
|
20
20
|
|
21
|
+
def operations
|
22
|
+
PagarMe::Request.get( url 'operations' ).call
|
23
|
+
end
|
24
|
+
|
25
|
+
def events
|
26
|
+
PagarMe::Request.get( url 'events' ).call
|
27
|
+
end
|
28
|
+
|
21
29
|
def collect_payment(params={})
|
22
30
|
PagarMe::Request.post(url('collect_payment'), params: params).run
|
23
31
|
end
|
@@ -31,16 +39,16 @@ module PagarMe
|
|
31
39
|
end
|
32
40
|
|
33
41
|
class << self
|
42
|
+
alias :charge :create
|
43
|
+
|
34
44
|
def calculate_installments(params)
|
35
45
|
PagarMe::Request.get(url('calculate_installments_amount'), query: params).run
|
36
46
|
end
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
alias :charge :create
|
47
|
+
|
48
|
+
def generate_card_hash
|
49
|
+
raise RequestError.new('Invalid Encryption Key') if PagarMe.encryption_key.blank?
|
50
|
+
PagarMe::Request.get(url('card_hash_key'), params: { encryption_key: PagarMe.encryption_key }).call
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
46
54
|
end
|
data/lib/pagarme/version.rb
CHANGED
data/pagarme.gemspec
CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'webmock'
|
27
27
|
spec.add_development_dependency 'test-unit'
|
28
|
+
spec.add_development_dependency 'clipboard'
|
28
29
|
|
29
30
|
spec.add_dependency 'rest-client'
|
30
31
|
spec.add_dependency 'multi_json'
|
@@ -18,11 +18,11 @@ module PagarMe
|
|
18
18
|
end
|
19
19
|
|
20
20
|
{
|
21
|
-
bank_code: '
|
22
|
-
agencia: '
|
23
|
-
agencia_dv: '
|
24
|
-
conta: '
|
25
|
-
conta_dv: '
|
21
|
+
bank_code: '123',
|
22
|
+
agencia: '1234',
|
23
|
+
agencia_dv: '1',
|
24
|
+
conta: '4444',
|
25
|
+
conta_dv: '1',
|
26
26
|
legal_name: 'John Doe',
|
27
27
|
document_number: '02476585700'
|
28
28
|
}.each do |key, value|
|
@@ -26,7 +26,7 @@ module PagarMe
|
|
26
26
|
PagarMe::Recipient.create recipient_with_nested_bank_account_params
|
27
27
|
|
28
28
|
bank_account_doc_number = bank_account_params[:document_number]
|
29
|
-
recipients = PagarMe::Recipient.find_by
|
29
|
+
recipients = PagarMe::Recipient.find_by bank_account: { document_number: bank_account_doc_number }
|
30
30
|
|
31
31
|
assert recipients.size > 0
|
32
32
|
recipients.each do |recipient|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagarme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Franceschi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: clipboard
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
126
140
|
- !ruby/object:Gem::Dependency
|
127
141
|
name: rest-client
|
128
142
|
requirement: !ruby/object:Gem::Requirement
|
@@ -254,4 +268,3 @@ test_files:
|
|
254
268
|
- test/pagarme/resources/transfer_test.rb
|
255
269
|
- test/pagarme/resources/zipcode_test.rb
|
256
270
|
- test/test_helper.rb
|
257
|
-
has_rdoc:
|