pagarme 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +3 -2
  4. data/README.md +285 -4
  5. data/Rakefile +16 -19
  6. data/lib/pagarme.rb +17 -32
  7. data/lib/pagarme/core_ext.rb +9 -0
  8. data/lib/pagarme/errors.rb +39 -25
  9. data/lib/pagarme/model.rb +40 -45
  10. data/lib/pagarme/nested_model.rb +56 -0
  11. data/lib/pagarme/object.rb +133 -92
  12. data/lib/pagarme/request.rb +96 -46
  13. data/lib/pagarme/resources/address.rb +4 -0
  14. data/lib/pagarme/resources/antifraud_analysis.rb +4 -0
  15. data/lib/pagarme/resources/balance.rb +24 -0
  16. data/lib/pagarme/resources/balance_operation.rb +37 -0
  17. data/lib/pagarme/resources/bank_account.rb +4 -0
  18. data/lib/pagarme/resources/bulk_anticipation.rb +65 -0
  19. data/lib/pagarme/resources/card.rb +4 -0
  20. data/lib/pagarme/resources/company.rb +28 -0
  21. data/lib/pagarme/{customer.rb → resources/customer.rb} +0 -0
  22. data/lib/pagarme/resources/payable.rb +11 -0
  23. data/lib/pagarme/resources/phone.rb +4 -0
  24. data/lib/pagarme/{plan.rb → resources/plan.rb} +0 -2
  25. data/lib/pagarme/resources/postal_code.rb +15 -0
  26. data/lib/pagarme/resources/postback.rb +15 -0
  27. data/lib/pagarme/resources/recipient.rb +32 -0
  28. data/lib/pagarme/resources/split_rule.rb +4 -0
  29. data/lib/pagarme/resources/subscription.rb +43 -0
  30. data/lib/pagarme/resources/transaction.rb +41 -0
  31. data/lib/pagarme/{transfer.rb → resources/transfer.rb} +0 -3
  32. data/lib/pagarme/{phone.rb → resources/user.rb} +1 -1
  33. data/lib/pagarme/transaction_common.rb +39 -42
  34. data/lib/pagarme/version.rb +3 -0
  35. data/pagarme.gemspec +16 -13
  36. data/test/assertions.rb +195 -0
  37. data/test/fixtures.rb +222 -0
  38. data/test/pagarme/error_test.rb +13 -0
  39. data/test/pagarme/object_test.rb +19 -0
  40. data/test/pagarme/pagarme_test.rb +10 -0
  41. data/test/pagarme/resources/balance_test.rb +46 -0
  42. data/test/pagarme/resources/bank_account_test.rb +35 -0
  43. data/test/pagarme/resources/bulk_anticipation_test.rb +72 -0
  44. data/test/pagarme/resources/card_test.rb +22 -0
  45. data/test/pagarme/resources/payable_test.rb +30 -0
  46. data/test/pagarme/resources/plan_test.rb +57 -0
  47. data/test/pagarme/resources/postback_test.rb +18 -0
  48. data/test/pagarme/resources/recipient_test.rb +41 -0
  49. data/test/pagarme/resources/subscription_test.rb +100 -0
  50. data/test/pagarme/resources/transaction_test.rb +221 -0
  51. data/test/pagarme/resources/transfer_test.rb +23 -0
  52. data/test/pagarme/resources/zipcode_test.rb +15 -0
  53. data/test/test_helper.rb +52 -175
  54. metadata +102 -30
  55. data/lib/pagarme/address.rb +0 -4
  56. data/lib/pagarme/bank_account.rb +0 -9
  57. data/lib/pagarme/card.rb +0 -7
  58. data/lib/pagarme/subscription.rb +0 -43
  59. data/lib/pagarme/transaction.rb +0 -33
  60. data/lib/pagarme/util.rb +0 -78
  61. data/pagarme.rb +0 -12
  62. data/test/pagarme/bank_account.rb +0 -46
  63. data/test/pagarme/card.rb +0 -26
  64. data/test/pagarme/object.rb +0 -29
  65. data/test/pagarme/pagarme.rb +0 -10
  66. data/test/pagarme/plan.rb +0 -70
  67. data/test/pagarme/subscription.rb +0 -123
  68. data/test/pagarme/transaction.rb +0 -215
  69. data/test/pagarme/transfer.rb +0 -42
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.0.2
4
+ version: 2.1.0
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: 2015-07-21 00:00:00.000000000 Z
12
+ date: 2016-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -67,6 +67,48 @@ dependencies:
67
67
  - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: vcr
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
70
112
  - !ruby/object:Gem::Dependency
71
113
  name: rest-client
72
114
  requirement: !ruby/object:Gem::Requirement
@@ -110,31 +152,52 @@ files:
110
152
  - Rakefile
111
153
  - certs/cabundle.pem
112
154
  - lib/pagarme.rb
113
- - lib/pagarme/address.rb
114
- - lib/pagarme/bank_account.rb
115
- - lib/pagarme/card.rb
116
- - lib/pagarme/customer.rb
155
+ - lib/pagarme/core_ext.rb
117
156
  - lib/pagarme/errors.rb
118
157
  - lib/pagarme/model.rb
158
+ - lib/pagarme/nested_model.rb
119
159
  - lib/pagarme/object.rb
120
- - lib/pagarme/phone.rb
121
- - lib/pagarme/plan.rb
122
160
  - lib/pagarme/request.rb
123
- - lib/pagarme/subscription.rb
124
- - lib/pagarme/transaction.rb
161
+ - lib/pagarme/resources/address.rb
162
+ - lib/pagarme/resources/antifraud_analysis.rb
163
+ - lib/pagarme/resources/balance.rb
164
+ - lib/pagarme/resources/balance_operation.rb
165
+ - lib/pagarme/resources/bank_account.rb
166
+ - lib/pagarme/resources/bulk_anticipation.rb
167
+ - lib/pagarme/resources/card.rb
168
+ - lib/pagarme/resources/company.rb
169
+ - lib/pagarme/resources/customer.rb
170
+ - lib/pagarme/resources/payable.rb
171
+ - lib/pagarme/resources/phone.rb
172
+ - lib/pagarme/resources/plan.rb
173
+ - lib/pagarme/resources/postal_code.rb
174
+ - lib/pagarme/resources/postback.rb
175
+ - lib/pagarme/resources/recipient.rb
176
+ - lib/pagarme/resources/split_rule.rb
177
+ - lib/pagarme/resources/subscription.rb
178
+ - lib/pagarme/resources/transaction.rb
179
+ - lib/pagarme/resources/transfer.rb
180
+ - lib/pagarme/resources/user.rb
125
181
  - lib/pagarme/transaction_common.rb
126
- - lib/pagarme/transfer.rb
127
- - lib/pagarme/util.rb
182
+ - lib/pagarme/version.rb
128
183
  - pagarme.gemspec
129
- - pagarme.rb
130
- - test/pagarme/bank_account.rb
131
- - test/pagarme/card.rb
132
- - test/pagarme/object.rb
133
- - test/pagarme/pagarme.rb
134
- - test/pagarme/plan.rb
135
- - test/pagarme/subscription.rb
136
- - test/pagarme/transaction.rb
137
- - test/pagarme/transfer.rb
184
+ - test/assertions.rb
185
+ - test/fixtures.rb
186
+ - test/pagarme/error_test.rb
187
+ - test/pagarme/object_test.rb
188
+ - test/pagarme/pagarme_test.rb
189
+ - test/pagarme/resources/balance_test.rb
190
+ - test/pagarme/resources/bank_account_test.rb
191
+ - test/pagarme/resources/bulk_anticipation_test.rb
192
+ - test/pagarme/resources/card_test.rb
193
+ - test/pagarme/resources/payable_test.rb
194
+ - test/pagarme/resources/plan_test.rb
195
+ - test/pagarme/resources/postback_test.rb
196
+ - test/pagarme/resources/recipient_test.rb
197
+ - test/pagarme/resources/subscription_test.rb
198
+ - test/pagarme/resources/transaction_test.rb
199
+ - test/pagarme/resources/transfer_test.rb
200
+ - test/pagarme/resources/zipcode_test.rb
138
201
  - test/test_helper.rb
139
202
  homepage: http://pagar.me/
140
203
  licenses: []
@@ -155,18 +218,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
218
  version: '0'
156
219
  requirements: []
157
220
  rubyforge_project:
158
- rubygems_version: 2.2.2
221
+ rubygems_version: 2.5.1
159
222
  signing_key:
160
223
  specification_version: 4
161
224
  summary: Allows integration with Pagar.me
162
225
  test_files:
163
- - test/pagarme/bank_account.rb
164
- - test/pagarme/card.rb
165
- - test/pagarme/object.rb
166
- - test/pagarme/pagarme.rb
167
- - test/pagarme/plan.rb
168
- - test/pagarme/subscription.rb
169
- - test/pagarme/transaction.rb
170
- - test/pagarme/transfer.rb
226
+ - test/assertions.rb
227
+ - test/fixtures.rb
228
+ - test/pagarme/error_test.rb
229
+ - test/pagarme/object_test.rb
230
+ - test/pagarme/pagarme_test.rb
231
+ - test/pagarme/resources/balance_test.rb
232
+ - test/pagarme/resources/bank_account_test.rb
233
+ - test/pagarme/resources/bulk_anticipation_test.rb
234
+ - test/pagarme/resources/card_test.rb
235
+ - test/pagarme/resources/payable_test.rb
236
+ - test/pagarme/resources/plan_test.rb
237
+ - test/pagarme/resources/postback_test.rb
238
+ - test/pagarme/resources/recipient_test.rb
239
+ - test/pagarme/resources/subscription_test.rb
240
+ - test/pagarme/resources/transaction_test.rb
241
+ - test/pagarme/resources/transfer_test.rb
242
+ - test/pagarme/resources/zipcode_test.rb
171
243
  - test/test_helper.rb
172
244
  has_rdoc:
@@ -1,4 +0,0 @@
1
- module PagarMe
2
- class Address < Model
3
- end
4
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module PagarMe
4
- class BankAccount < Model
5
- def self.url
6
- '/bank_accounts'
7
- end
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', 'pagarme')
3
-
4
- module PagarMe
5
- class Card < TransactionCommon
6
- end
7
- end
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', 'pagarme')
3
-
4
- module PagarMe
5
- class Subscription < TransactionCommon
6
- def create
7
- if self.plan
8
- self.plan_id = plan.id
9
- end
10
-
11
- self.plan = nil
12
- super
13
- end
14
-
15
- def save
16
- if self.plan
17
- self.plan_id = plan.id
18
- end
19
-
20
- self.plan = nil
21
- super
22
- end
23
-
24
- def cancel
25
- request = PagarMe::Request.new(self.url + '/cancel', 'POST')
26
- response = request.run
27
- update(response)
28
- end
29
-
30
- def charge(amount, installments = 1)
31
- request = PagarMe::Request.new(self.url + '/transactions', 'POST')
32
- request.parameters = {
33
- :amount => amount,
34
- :installments => installments
35
- }
36
- response = request.run
37
-
38
- request = PagarMe::Request.new(self.url, 'GET')
39
- update(request.run)
40
- end
41
-
42
- end
43
- end
@@ -1,33 +0,0 @@
1
- # encoding: utf-8
2
- require 'openssl'
3
- require 'base64'
4
- require File.join(File.dirname(__FILE__), '..', 'pagarme')
5
-
6
- module PagarMe
7
- class Transaction < TransactionCommon
8
- def self.calculate_installments(params)
9
- request = PagarMe::Request.new('/transactions/calculate_installments_amount', 'GET')
10
- request.query.merge!(params)
11
- response = request.run
12
- response
13
- end
14
-
15
- def charge
16
- create
17
- end
18
-
19
- def capture(params={})
20
- request = PagarMe::Request.new(self.url + '/capture', 'POST')
21
- request.parameters.merge!(params)
22
- response = request.run
23
- update(response)
24
- end
25
-
26
- def refund(params={})
27
- request = PagarMe::Request.new(self.url + '/refund', 'POST')
28
- request.parameters.merge!(params)
29
- response = request.run
30
- update(response)
31
- end
32
- end
33
- end
@@ -1,78 +0,0 @@
1
- # encoding: utf-8
2
- require File.join(File.dirname(__FILE__), '..', 'pagarme')
3
-
4
- module PagarMe
5
- class Util
6
- def self.pagarme_classes
7
- return {
8
- 'transaction' => Transaction,
9
- 'plan' => Plan,
10
- 'customer' => Customer,
11
- 'subscription' => Subscription,
12
- 'address' => Address,
13
- 'phone' => Phone,
14
- }
15
- end
16
-
17
- def self.convert_to_pagarme_object(response)
18
- case response
19
- when Array
20
- response.map{ |i| convert_to_pagarme_object(i)}
21
- when Hash
22
- self.pagarme_classes.fetch(response['object'], PagarMeObject).build(response)
23
- else
24
- response
25
- end
26
- end
27
-
28
- def self.url_encode(key)
29
- URI.encode_www_form_component(key.to_s)
30
- end
31
-
32
-
33
- def self.normalize_params(parameters, parent = nil)
34
- ret = []
35
- parameters.each do |k, v|
36
- current_key = parent ? "#{parent}[#{url_encode(k)}]" : url_encode(k)
37
- case v
38
- when Hash
39
- ret += normalize_params(v, current_key)
40
- when Array
41
- ret += normalize_array_params(v, current_key)
42
- else
43
- ret << [current_key, url_encode(v)]
44
- end
45
- end
46
- ret
47
- end
48
-
49
- def self.normalize_array_params(value, current_key)
50
- ret = []
51
- value.each do |element|
52
- case element
53
- when Hash
54
- ret += normalize_params(element, current_key)
55
- when Array
56
- ret += normalize_array_params(element, current_key)
57
- else
58
- ret << ["#{current_key}[]", url_encode(element)]
59
- end
60
- end
61
- ret
62
- end
63
- end
64
- end
65
-
66
- class Hash
67
- def to_params
68
- self.map{ |key, value| "#{key}=#{value}" }.join('&')
69
- end
70
- end
71
-
72
- class Array
73
- def to_params
74
- self.map{ |key, value| "#{key}=#{value}" }.join('&')
75
- end
76
- end
77
-
78
-
data/pagarme.rb DELETED
@@ -1,12 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '.', 'lib/pagarme')
2
- transaction = PagarMe::Transaction.new
3
- transaction.card_number = "4901720080344448"
4
- transaction.card_holder_name = "Jose da Silva"
5
- transaction.card_expiration_month = "13" # o mês 13 é maior do que 12 (dezembro) -> parâmetro inválido!
6
- transaction.card_expiration_year = "15"
7
- transaction.card_cvv = "314"
8
- transaction.amount = 1000
9
-
10
- transaction.charge
11
-
12
-
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
- require_relative '../test_helper'
3
-
4
- module PagarMe
5
- class BankAccountTest < Test::Unit::TestCase
6
- should 'be able to create a bank_account' do
7
- bank_account = test_bank_account
8
- bank_account.create
9
-
10
- assert bank_account.bank_code == '237'
11
- end
12
-
13
- should 'be able to search by anything' do
14
- bank_account = test_bank_account()
15
- bank_account.create
16
-
17
- bank_accounts = PagarMe::BankAccount.find_by({ bank_code: '237' })
18
-
19
- assert bank_accounts.size
20
- bank_accounts.each do |b|
21
- assert b.bank_code == '237'
22
- end
23
- end
24
-
25
- [
26
- { bank_code: 'foo' },
27
- { agencia: 'abcd' },
28
- { agencia_dv: 'Y'},
29
- { conta: 'ABCD' },
30
- { conta_dv: ''},
31
- { legal_name: '' },
32
- { document_number: 'foooo'}
33
- ].each do |attrs|
34
- attr_key = attrs.keys.first
35
-
36
- should "validate bank_account - #{attr_key.to_s}" do
37
- exception = assert_raises PagarMeError do
38
- bank_account = BankAccount.new(attrs)
39
- bank_account.create
40
- end
41
-
42
- assert exception.errors.map(&:parameter_name).include?(attr_key.to_s)
43
- end
44
- end
45
- end
46
- end
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
- require_relative '../test_helper'
3
-
4
- module PagarMe
5
- class CardTest < Test::Unit::TestCase
6
- should 'be able to create' do
7
- card = test_card
8
- card.create
9
-
10
- assert card.id
11
- assert card.first_digits == '411111'
12
- assert card.last_digits = '1111'
13
- end
14
-
15
- should 'be able to find by id' do
16
- card = test_card
17
- card.create
18
-
19
- card2 = PagarMe::Card.find_by_id(card.id)
20
-
21
- assert card.id == card2.id
22
- assert card.first_digits == card2.first_digits
23
- assert card.last_digits == card2.last_digits
24
- end
25
- end
26
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
- require_relative '../test_helper'
3
-
4
- module PagarMe
5
- class ObjectTest < Test::Unit::TestCase
6
- should 'be able to create object and add any attribute' do
7
- object = PagarMe::PagarMeObject.new({
8
- :attr1 => 2
9
- })
10
-
11
- assert object.attr1 == 2
12
-
13
- object = PagarMe::PagarMeObject.new
14
- object.attr1 = 2
15
-
16
- assert object.attr1 == 2
17
- end
18
-
19
- should 'be able to add nested attributes' do
20
- object = PagarMe::PagarMeObject.new({
21
- :nested => {
22
- :attr => 2
23
- }
24
- })
25
-
26
- assert object.nested.attr = 2
27
- end
28
- end
29
- end