pagarme 2.1.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 578deddbc00fc81efa0bfd3bc0c2d76503346933
4
- data.tar.gz: c1448b5d1f4d746bd67e3c1718b75fecf524194d
3
+ metadata.gz: '09cbd478941d7e533cc69f34d79544eadff6f8df'
4
+ data.tar.gz: 5ab0f69c6eb9ca71e1bf74e3416b1af98b98c6b5
5
5
  SHA512:
6
- metadata.gz: 683f3c56c311fc53eedc8bf3888e8a48daf08aa6210e01146d707d06c0fa9f33f13cd6131a2f28d3b71a31a4cea1510c9195854d7dbee60da7ee130dd99b1a13
7
- data.tar.gz: 80585f459e4bd2dee596ad344a6004b12d36961ba7488897b5a979cf778fd7875309500a29798886d3ad21a5afa3d0bfaebb458db91f7af561e33485e8a1202b
6
+ metadata.gz: bc8bdcf0f45d79fbed47c7951e7bc6dc24f4805bffb82a308a019317e479c4b8794d912cd179525877468b75ae8b62a6bc3df8093bfb2e70c77c5deb42c9f6d0
7
+ data.tar.gz: 2bf71508679143a2c743bab7ecd52f5915687ebd9584f2e6ad6e5c8a33ac661a4c2751a7019f4711ea8771f16a7e256020613da980d4580ff8370e6ba0249ece
data/README.md CHANGED
@@ -5,8 +5,8 @@ Pagar.me Ruby library
5
5
 
6
6
  ## Documentation
7
7
 
8
- * [Documentation](https://pagar.me/docs)
9
- * [Full API Guide](https://docs.pagar.me/api)
8
+ * [Documentation](https://docs.pagar.me)
9
+ * [Full API Guide](https://docs.pagar.me/reference)
10
10
 
11
11
  ## Getting Started
12
12
 
@@ -38,13 +38,13 @@ and _PAGARME\_ENCRYPTION\_KEY_ (**recommended if needed**)
38
38
 
39
39
  See our [demo checkout](https://pagar.me/checkout).
40
40
 
41
- More about how to use it [here](https://docs.pagar.me/checkout).
41
+ More about how to use it [here](https://docs.pagar.me/docs/overview-checkout).
42
42
 
43
43
  ### Transactions
44
44
 
45
45
  #### Creating a Credit Card Transaction
46
46
 
47
- To create a credit card transaction, you need a [card\_hash](https://docs.pagar.me/capturing-card-data).
47
+ To create a credit card transaction, you need a [card\_hash](https://docs.pagar.me/docs/obtendo-os-dados-do-cartao).
48
48
 
49
49
  ```ruby
50
50
  PagarMe::Transaction.new(
@@ -53,7 +53,26 @@ To create a credit card transaction, you need a [card\_hash](https://docs.pagar.
53
53
  ).charge
54
54
  ```
55
55
 
56
- More about [Creating a Credit Card Transaction](https://docs.pagar.me/transactions/#realizando-uma-transacao-de-cartao-de-credito).
56
+ More about [Creating a Credit Card Transaction](https://docs.pagar.me/docs/realizando-uma-transacao-de-cartao-de-credito).
57
+
58
+ #### Creating a Customer
59
+
60
+ ```ruby
61
+ customer = PagarMe::Customer.create(
62
+ name: 'Morpheus Fishburne',
63
+ email: 'mopheus@nabucodonozor.com',
64
+ type: 'individual',
65
+ external_id: "#3311",
66
+ country: 'br',
67
+ birthday: "1965-01-01",
68
+ documents: [
69
+ {type: "cpf", number: "86870624194"}
70
+ ],
71
+ phone_numbers: ["+5511999998888", "+5511888889999"]
72
+ )
73
+ ```
74
+
75
+ More about [Creating a Customer](https://docs.pagar.me/v2017-08-28/reference#criando-um-cliente).
57
76
 
58
77
  #### Creating a Boleto Transaction
59
78
 
@@ -68,7 +87,7 @@ More about [Creating a Credit Card Transaction](https://docs.pagar.me/transactio
68
87
  transaction.boleto_barcode # => boleto's barcode
69
88
  ```
70
89
 
71
- More about [Creating a Boleto Transaction](https://docs.pagar.me/transactions/#realizando-uma-transacao-de-boleto-bancario).
90
+ More about [Creating a Boleto Transaction](https://docs.pagar.me/docs/realizando-uma-transacao-de-boleto-bancario).
72
91
 
73
92
  #### Split Rules
74
93
 
@@ -79,20 +98,20 @@ For example, splitting equally a transaction:
79
98
  PagarMe::Transaction.new(
80
99
  amount: 1000, # in cents
81
100
  card_hash: card_hash, # how to get a card hash: docs.pagar.me/capturing-card-data
82
- split\_rules: [
101
+ split_rules: [
83
102
  { recipient_id: recipient_id_1, percentage: 50 },
84
103
  { recipient_id: recipient_id_2, percentage: 50 }
85
104
  ]
86
105
  ).charge
87
106
  ```
88
107
 
89
- More about [Split Rules](https://docs.pagar.me/api/#regras-do-split).
108
+ More about [Split Rules](https://docs.pagar.me/reference#retornando-uma-regra-de-divis%C3%A3o-espec%C3%ADfica).
90
109
 
91
110
  ### Plans & Subscriptions
92
111
 
93
- You can use recurring charges, learn more [here](https://docs.pagar.me/plans-subscriptions).
112
+ You can use recurring charges, learn more [here](https://docs.pagar.me/docs/overview-recorrencia).
94
113
 
95
- It's important to understand the charges flow, learn more [here](https://docs.pagar.me/plans-subscriptions/#fluxo-de-cobranca)
114
+ It's important to understand the charges flow, learn more [here](https://docs.pagar.me/docs/fluxo-de-cobranca)
96
115
 
97
116
  #### Creating a Plan
98
117
 
@@ -104,7 +123,7 @@ It's important to understand the charges flow, learn more [here](https://docs.pa
104
123
  ).create
105
124
  ```
106
125
 
107
- More about [Creating a Plan](https://docs.pagar.me/plans-subscriptions/#criando-um-plano).
126
+ More about [Creating a Plan](https://docs.pagar.me/docs/criando-um-plano).
108
127
 
109
128
  #### Creating a Subscription
110
129
 
@@ -116,7 +135,7 @@ More about [Creating a Plan](https://docs.pagar.me/plans-subscriptions/#criando-
116
135
  ).create
117
136
  ```
118
137
 
119
- More about [Creating a Subscription](https://docs.pagar.me/plans-subscriptions/#criando-uma-assinatura).
138
+ More about [Creating a Subscription](https://docs.pagar.me/docs/criando-uma-assinatura).
120
139
 
121
140
  ### Recipients
122
141
 
@@ -139,7 +158,7 @@ To create a recipient, so it can receive payments through split rules or transfe
139
158
  )
140
159
  ```
141
160
 
142
- More about [Creating a Recipient](https://docs.pagar.me/api/#recebedores).
161
+ More about [Creating a Recipient](https://docs.pagar.me/reference#criando-um-recebedor).
143
162
 
144
163
  #### Transfer Available Amout to Bank Account Manually
145
164
 
@@ -163,7 +182,7 @@ _transfer\_interval_ and _transfer\_day_ will handle it automatically.
163
182
 
164
183
  Just that!
165
184
 
166
- More about [Balance](https://docs.pagar.me/api/#saldo)
185
+ More about [Balance](https://docs.pagar.me/docs/overview-gerenciamento-de-saldo)
167
186
 
168
187
  #### Checking Balance Operations
169
188
 
@@ -179,7 +198,7 @@ Paginating:
179
198
  PagarMe::BalanceOperation.balance_operations 2, 50 # second page, 50 per page
180
199
  ```
181
200
 
182
- More about [Balance Operations](https://docs.pagar.me/api/#operacoes-de-saldo)
201
+ More about [Balance Operations](https://docs.pagar.me/docs/composicao-do-saldo)
183
202
 
184
203
  #### Checking Recipient Balance
185
204
 
@@ -208,7 +227,7 @@ Paginating:
208
227
  PagarMe::Recipient.find(recipient_id).balance_operations 2, 50 # second page, 50 per page
209
228
  ```
210
229
 
211
- More about [Recipient Balance Operations](https://docs.pagar.me/api/#operacoes-de-saldo-de-um-recebedor)
230
+ More about [Recipient Balance Operations](https://docs.pagar.me/reference#opera%C3%A7%C3%B5es-de-saldo-de-um-recebedor)
212
231
 
213
232
  ### Request Bulk Anticipation
214
233
 
@@ -218,7 +237,7 @@ More about [Recipient Balance Operations](https://docs.pagar.me/api/#operacoes-d
218
237
  PagarMe::Recipient.default.bulk_anticipations_limits
219
238
  ```
220
239
 
221
- More about [Checking Bulk Anticipation Limits](https://docs.pagar.me/api/#obtendo-os-limites-de-antecipacao)
240
+ More about [Checking Bulk Anticipation Limits](https://docs.pagar.me/reference#obtendo-os-limites-de-antecipa%C3%A7%C3%A3o)
222
241
 
223
242
  #### Requesting Bulk Anticipation
224
243
 
@@ -230,7 +249,7 @@ More about [Checking Bulk Anticipation Limits](https://docs.pagar.me/api/#obtend
230
249
  )
231
250
  ```
232
251
 
233
- More about [Requesting Bulk Anticipation](https://docs.pagar.me/api/#criando-uma-antecipacao)
252
+ More about [Requesting Bulk Anticipation](https://docs.pagar.me/reference#criando-uma-antecipa%C3%A7%C3%A3o)
234
253
 
235
254
  #### Getting Bulk Anticipation
236
255
 
@@ -238,7 +257,7 @@ More about [Requesting Bulk Anticipation](https://docs.pagar.me/api/#criando-uma
238
257
  PagarMe::BulkAnticipation.all page, count
239
258
  ```
240
259
 
241
- More about [Getting Bulk Anticipation](https://docs.pagar.me/api/#retornando-todas-as-antecipacoes)
260
+ More about [Getting Bulk Anticipation](https://docs.pagar.me/reference#retornando-todas-as-antecipa%C3%A7%C3%B5es)
242
261
 
243
262
  ### Payables
244
263
 
@@ -248,7 +267,7 @@ More about [Getting Bulk Anticipation](https://docs.pagar.me/api/#retornando-tod
248
267
  PagarMe::Payable.find 'payable_id'
249
268
  ```
250
269
 
251
- More about [Getting Payable](https://docs.pagar.me/api/#retornando-um-recebivel)
270
+ More about [Getting Payable](https://docs.pagar.me/reference#retornando-um-receb%C3%ADvel)
252
271
 
253
272
  #### Querying Payables
254
273
 
@@ -260,7 +279,7 @@ More about [Getting Payable](https://docs.pagar.me/api/#retornando-um-recebivel)
260
279
  PagarMe::Payable.find_by status: 'paid'
261
280
  ```
262
281
 
263
- More about [Querying Payables](https://docs.pagar.me/api/#retornando-recebiveis)
282
+ More about [Querying Payables](https://docs.pagar.me/reference#retornando-receb%C3%ADveis)
264
283
 
265
284
  #### Querying Payables by Transaction
266
285
 
@@ -269,7 +288,7 @@ More about [Querying Payables](https://docs.pagar.me/api/#retornando-recebiveis)
269
288
  transaction.payables
270
289
  ```
271
290
 
272
- More about [Payable Transactions](https://docs.pagar.me/api/#retornando-pagamentos-da-transacao)
291
+ More about [Payable Transactions](https://docs.pagar.me/reference#retornando-pagamentos-da-transa%C3%A7%C3%A3o)
273
292
 
274
293
  ### Validating Postback
275
294
 
@@ -329,7 +348,7 @@ This README is just a quick abstract of it's main features.
329
348
  You can easily browse it's source code to see all [supported resources](https://github.com/pagarme/pagarme-ruby/tree/master/lib/pagarme/resources).
330
349
 
331
350
  We will document everything while adding support to all resources listed in
332
- [Full API Guide](https://docs.pagar.me/api).
351
+ [Full API Guide](https://docs.pagar.me/reference).
333
352
 
334
353
  Feel free to help us to add support to features sending pull requests.
335
354
 
@@ -337,7 +356,7 @@ Thanks!
337
356
 
338
357
  ### TODO
339
358
 
340
- Add support to [ElasticSearch Query DSL](https://docs.pagar.me/api/#buscas-avancadas),
359
+ Add support to [ElasticSearch Query DSL](https://docs.pagar.me/reference#elasticsearch),
341
360
  so you can search your data optimally.
342
361
 
343
362
  And document all the source code.
@@ -10,7 +10,8 @@ module PagarMe
10
10
  DEFAULT_HEADERS = {
11
11
  'Content-Type' => 'application/json; charset=utf8',
12
12
  'Accept' => 'application/json',
13
- 'User-Agent' => "pagarme-ruby/#{PagarMe::VERSION}"
13
+ 'User-Agent' => "pagarme-ruby/#{PagarMe::VERSION}",
14
+ 'X-PagarMe-User-Agent' => "pagarme-ruby/#{PagarMe::VERSION}"
14
15
  }
15
16
 
16
17
  def initialize(path, method, options={})
@@ -85,7 +86,8 @@ module PagarMe
85
86
  open_timeout: PagarMe.open_timeout,
86
87
  timeout: PagarMe.timeout,
87
88
  ssl_ca_file: SSL_CA_FILEPATH,
88
- headers: DEFAULT_HEADERS.merge(headers)
89
+ headers: DEFAULT_HEADERS.merge(headers),
90
+ ssl_version: 'TLSv1_2'
89
91
  }
90
92
  end
91
93
 
@@ -2,11 +2,13 @@ module PagarMe
2
2
  class BalanceOperation < PagarMeObject
3
3
 
4
4
  def method_missing(name, *args, &block)
5
+ super name, *args, &block
6
+ rescue NameError
5
7
  if @attributes['movement_object'] && @attributes['movement_object'].respond_to?(name)
6
- return movement_object.public_send(name, *args, &block)
8
+ return @attributes['movement_object'].public_send(name, *args, &block)
7
9
  end
8
10
 
9
- super name, *args, &block
11
+ raise $!
10
12
  end
11
13
 
12
14
  class << self
@@ -0,0 +1,4 @@
1
+ module PagarMe
2
+ class Billing < PagarMeObject
3
+ end
4
+ end
@@ -21,8 +21,8 @@ module PagarMe
21
21
  PagarMe::Request.get('/company').call
22
22
  end
23
23
 
24
- def self.temporary
25
- PagarMe::Request.post('/companies/temporary').call
24
+ def self.temporary(params = Hash.new)
25
+ PagarMe::Request.post('/companies/temporary', params: params).call
26
26
  end
27
27
  end
28
28
  end
@@ -0,0 +1,4 @@
1
+ module PagarMe
2
+ class FeeCollection < PagarMeObject
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module PagarMe
2
+ class Item < PagarMeObject
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module PagarMe
2
+ class PaymentLink < Model
3
+ def cancel()
4
+ update PagarMe::Request.post(url('cancel')).run
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module PagarMe
2
+ class Shipping < PagarMeObject
3
+ end
4
+ end
@@ -19,6 +19,10 @@ module PagarMe
19
19
  update PagarMe::Request.post( url 'cancel' ).run
20
20
  end
21
21
 
22
+ def settle_charge
23
+ update PagarMe::Request.post( url 'settle_charge' ).run
24
+ end
25
+
22
26
  def transactions
23
27
  PagarMe::Request.get( url 'transactions' ).call
24
28
  end
@@ -1,3 +1,3 @@
1
1
  module PagarMe
2
- VERSION = '2.1.4'
2
+ VERSION = '2.4.0'
3
3
  end
data/pagarme.gemspec CHANGED
@@ -20,10 +20,10 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency 'bundler', '~> 1.3'
21
21
  spec.add_development_dependency 'shoulda', '~> 3.4.0'
22
22
  spec.add_development_dependency 'activesupport', '~> 3.0'
23
+ spec.add_development_dependency 'webmock', '~> 2.3'
23
24
  spec.add_development_dependency 'pry'
24
25
  spec.add_development_dependency 'vcr'
25
26
  spec.add_development_dependency 'rake'
26
- spec.add_development_dependency 'webmock'
27
27
  spec.add_development_dependency 'test-unit'
28
28
  spec.add_development_dependency 'clipboard'
29
29
 
data/test/fixtures.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  class Fixtures
2
3
  def transaction
3
4
  { amount: 1000 }
@@ -47,6 +48,10 @@ class Fixtures
47
48
  }
48
49
  end
49
50
 
51
+ def invalid_card_number
52
+ card.merge card_number: '4043405'
53
+ end
54
+
50
55
  def refused_card
51
56
  # In test environment CVV's that starts with digit 6 are refused by acquirer
52
57
  card.merge card_cvv: '600'
@@ -78,6 +83,60 @@ class Fixtures
78
83
  }
79
84
  end
80
85
 
86
+ def address
87
+ {
88
+ street: 'Av. Brigadeiro Faria Lima',
89
+ street_number: '2941',
90
+ neighborhood: 'Itaim bibi',
91
+ zipcode: '01452000',
92
+ city: 'São Paulo',
93
+ state: 'sp',
94
+ country: 'br'
95
+ }
96
+ end
97
+
98
+ def billing
99
+ {
100
+ billing: {
101
+ name: 'Jon Snow',
102
+ address: address
103
+ }
104
+ }
105
+ end
106
+
107
+ def shipping
108
+ {
109
+ shipping: {
110
+ name: 'Daenerys Targeryen',
111
+ fee: 100,
112
+ delivery_date: "2000-12-21",
113
+ expedited: "true",
114
+ address: address
115
+ }
116
+ }
117
+ end
118
+
119
+ def item
120
+ {
121
+ items: [
122
+ {
123
+ id: "r123",
124
+ title: "Red pill",
125
+ unit_price: 10000,
126
+ quantity: 1,
127
+ tangible: true
128
+ },
129
+ {
130
+ id: "b123",
131
+ title: "Blue pill",
132
+ unit_price: 10000,
133
+ quantity: 1,
134
+ tangible: true
135
+ }
136
+ ]
137
+ }
138
+ end
139
+
81
140
  def bank_account
82
141
  {
83
142
  bank_code: '237',
@@ -139,12 +198,27 @@ class Fixtures
139
198
  gender: 'M',
140
199
  born_at: '1970-10-11',
141
200
  phone: { ddd: '21', number: '922334455' },
142
- address: {
143
- street: 'Av. Brigadeiro Faria Lima',
144
- neighborhood: 'Itaim bibi',
145
- zipcode: '01452000',
146
- street_number: '2941'
147
- }
201
+ address: address
202
+ }
203
+ }
204
+ end
205
+
206
+ def external_id_customer
207
+ {
208
+ customer: {
209
+ external_id: "#3311",
210
+ name: "Morpheus Fishburne",
211
+ type: "individual",
212
+ country: "br",
213
+ email: "mopheus@nabucodonozor.com",
214
+ documents: [
215
+ {
216
+ type: "cpf",
217
+ number: "86870624194"
218
+ }
219
+ ],
220
+ phone_numbers: ["+5511999998888", "+5511888889999"],
221
+ birthday: "1965-01-01"
148
222
  }
149
223
  }
150
224
  end
@@ -4,7 +4,7 @@ module PagarMe
4
4
  class BalanceTest < PagarMeTestCase
5
5
 
6
6
  should 'change amount amount after transaction being paid' do
7
- transaction = PagarMe::Transaction.charge transaction_with_boleto_params
7
+ transaction = PagarMe::Transaction.charge transaction_with_customer_with_boleto_params
8
8
  previous_balance = PagarMe::Balance.balance
9
9
 
10
10
  transaction.status = :paid
@@ -17,7 +17,7 @@ module PagarMe
17
17
  should 'change recipient amount after transaction being paid' do
18
18
  recipient = PagarMe::Recipient.create recipient_with_nested_bank_account_params
19
19
  split_rules = [ { recipient_id: recipient.id, percentage: 100 } ]
20
- transaction = PagarMe::Transaction.charge transaction_with_boleto_params(split_rules: split_rules)
20
+ transaction = PagarMe::Transaction.charge transaction_with_customer_with_boleto_params(split_rules: split_rules)
21
21
 
22
22
  assert_empty_balance recipient.balance
23
23
 
@@ -30,7 +30,7 @@ module PagarMe
30
30
  should 'change recipient amount after recipient receive money' do
31
31
  recipient = PagarMe::Recipient.create recipient_with_nested_bank_account_params
32
32
  split_rules = [ { recipient_id: recipient.id, percentage: 100 } ]
33
- transaction = PagarMe::Transaction.charge transaction_with_boleto_params(split_rules: split_rules)
33
+ transaction = PagarMe::Transaction.charge transaction_with_customer_with_boleto_params(split_rules: split_rules)
34
34
 
35
35
  assert_empty_balance recipient.balance
36
36
 
@@ -41,12 +41,12 @@ module PagarMe
41
41
  assert_equal anticipation.id, anticipation.confirm.id
42
42
  end
43
43
 
44
- should 'create a building anticipation an later delete it' do
44
+ should 'create a building anticipation and later delete it' do
45
45
  recipient = PagarMe::Recipient.default
46
46
  anticipation = recipient.bulk_anticipate anticipation_params(build: true)
47
47
 
48
48
  assert_equal anticipation.id, PagarMe::BulkAnticipation.find(recipient.id, anticipation.id).id
49
- PagarMe::BulkAnticipation.delete(recipient.id, anticipation.id).id
49
+ PagarMe::BulkAnticipation.delete(recipient.id, anticipation.id)
50
50
  assert_raises PagarMe::NotFound do
51
51
  PagarMe::BulkAnticipation.find recipient.id, anticipation.id
52
52
  end
@@ -0,0 +1,23 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module PagarMe
4
+ class CustomerTest < PagarMeTestCase
5
+ should 'be able to create' do
6
+ customer = PagarMe::Customer.create external_id_customer_params[:customer]
7
+ assert customer.id
8
+ assert_equal customer.name, 'Morpheus Fishburne'
9
+ assert_equal customer.type, 'individual'
10
+ assert_equal customer.external_id, "#3311"
11
+ assert_equal customer.country, 'br'
12
+ assert_equal customer.birthday, "1965-01-01"
13
+ assert customer.phone_numbers.any?
14
+ assert_equal customer.phone_numbers, ["+5511999998888", "+5511888889999"]
15
+ end
16
+
17
+ should 'be able to find by id' do
18
+ customer = PagarMe::Customer.create external_id_customer_params[:customer]
19
+ found_customer = PagarMe::Customer.find_by_id customer.id
20
+ assert_equal customer.id, found_customer.id
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../../test_helper'
2
+
3
+ module PagarMe
4
+ class PaymentLinkTest < PagarMeTestCase
5
+ should 'be able to create a payment_link' do
6
+ payment_link = PagarMe::PaymentLink.create payment_link_params
7
+ assert_equal payment_link.amount, 1000
8
+ end
9
+
10
+ should 'be able to cancel a payment_link' do
11
+ payment_link = PagarMe::PaymentLink.create payment_link_params
12
+ payment_link.cancel
13
+ assert_equal payment_link.status, 'canceled'
14
+ end
15
+
16
+ should 'be able to search by short_id' do
17
+ pl = PagarMe::PaymentLink.create payment_link_params
18
+ payment_links = PagarMe::PaymentLink.find short_id: pl.short_id
19
+
20
+ assert payment_links.size > 0
21
+ payment_links.each do |payment_link|
22
+ assert_equal payment_link.short_id, pl.short_id
23
+ end
24
+ end
25
+ end
26
+ end
@@ -20,7 +20,8 @@ module PagarMe
20
20
  assert_plan_created PagarMe::Plan.create(plan_params)
21
21
 
22
22
  # find_by_hash is possibly consistent, wait to try to ensure!!!
23
- sleep 1
23
+ sleep 5
24
+
24
25
  found_plans = PagarMe::Plan.find_by trial_days: 5
25
26
 
26
27
  assert found_plans.size > 0
@@ -1,7 +1,7 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  module PagarMe
4
- class TransactionTest < PagarMeTestCase
4
+ class PostbackTest < PagarMeTestCase
5
5
  should 'be valid when has valid signature' do
6
6
  fixed_api_key do
7
7
  postback = PagarMe::Postback.new postback_response_params
@@ -9,7 +9,7 @@ module PagarMe
9
9
  end
10
10
  end
11
11
 
12
- should 'be valid when has invalid signature' do
12
+ should 'not be valid when has invalid signature' do
13
13
  postback = PagarMe::Postback.new postback_response_params(signature: 'sha1=invalid signature')
14
14
  assert !postback.valid?
15
15
  end
@@ -12,10 +12,11 @@ module PagarMe
12
12
 
13
13
  should 'be able to see subscription transactions' do
14
14
  plan = PagarMe::Plan.create no_trial_plan_params
15
- subscription = PagarMe::Subscription.create subscription_with_customer_params(plan: plan)
15
+ subscription = PagarMe::Subscription.create subscription_with_customer_with_card_params(plan: plan)
16
16
  assert_no_trial_subscription_created subscription, plan
17
17
 
18
- sleep 1
18
+ sleep 5
19
+
19
20
  assert subscription.transactions.count > 0
20
21
  assert_equal subscription.transactions.first.status, 'paid'
21
22
  end
@@ -96,5 +97,14 @@ module PagarMe
96
97
  subscription.cancel
97
98
  assert_equal subscription.status, 'canceled'
98
99
  end
100
+
101
+ should 'be able to settle_charge a subscription' do
102
+ plan = PagarMe::Plan.create no_trial_plan_params
103
+ subscription = PagarMe::Subscription.create boleto_with_customer_params(plan: plan)
104
+ assert_equal subscription.status, 'unpaid'
105
+
106
+ subscription.settle_charge
107
+ assert_equal subscription.status, 'paid'
108
+ end
99
109
  end
100
110
  end
@@ -48,8 +48,8 @@ module PagarMe
48
48
  assert_equal transaction.status, 'refunded'
49
49
  end
50
50
 
51
- should 'be able to create transaciton with boleto' do
52
- transaction = PagarMe::Transaction.charge transaction_with_boleto_params
51
+ should 'be able to create transaction with boleto' do
52
+ transaction = PagarMe::Transaction.charge transaction_with_customer_with_boleto_params
53
53
  assert_transaction_with_bolelo_on_waiting_payment transaction
54
54
  end
55
55
 
@@ -89,7 +89,7 @@ module PagarMe
89
89
  end
90
90
 
91
91
  should 'require parameters on the refund with boleto' do
92
- transaction = PagarMe::Transaction.create transaction_with_boleto_params
92
+ transaction = PagarMe::Transaction.create transaction_with_customer_with_boleto_params
93
93
  assert_equal transaction.status, 'waiting_payment'
94
94
 
95
95
  assert_raises(PagarMe::ValidationError){ transaction.refund }
@@ -137,11 +137,27 @@ module PagarMe
137
137
  assert_equal transaction.refunded_amount, 0
138
138
  end
139
139
 
140
- should 'validate transaction with invalid card_number' do
141
- exception = assert_raises PagarMe::ValidationError do
142
- PagarMe::Transaction.charge transaction_with_card_params(card_number: '123456')
140
+ should 'be able to create a transaction with billing shipping and items' do
141
+ change_company(api_version: { test: '2017-08-28', live: '2017-08-28'}) do
142
+ transaction = PagarMe::Transaction.create transaction_with_external_id_customer_with_billing_with_shipping_with_item_with_card_params
143
+ found_transaction = PagarMe::Transaction.find_by_id transaction.id
144
+
145
+ assert_equal found_transaction.billing, transaction.billing
146
+ assert_equal found_transaction.shipping, transaction.shipping
147
+ assert_equal found_transaction.items, transaction.items
148
+
149
+ assert found_transaction.billing
150
+ assert found_transaction.shipping
151
+ assert found_transaction.items
152
+
153
+ assert_transaction_successfully_paid transaction
143
154
  end
144
- assert exception.errors.any?{ |error| error.parameter_name == 'card_number' }
155
+ end
156
+
157
+ should 'validate transaction with invalid card_number' do
158
+ transaction = PagarMe::Transaction.new transaction_with_customer_with_invalid_card_number_params
159
+ transaction.charge
160
+ assert_equal transaction.status, 'refused'
145
161
  end
146
162
 
147
163
  should 'validate transaction missing card_holder_name' do
data/test/test_helper.rb CHANGED
@@ -35,7 +35,7 @@ class PagarMeTestCase < Test::Unit::TestCase
35
35
  protected
36
36
  def ensure_positive_balance
37
37
  VCR.use_cassette 'TestCase/ensure_positive_balance' do
38
- transaction = PagarMe::Transaction.charge transaction_with_boleto_params(amount: 100_000_00)
38
+ transaction = PagarMe::Transaction.charge transaction_with_customer_with_boleto_params(amount: 100_000_00)
39
39
  transaction.status = :paid
40
40
  transaction.save
41
41
  end
@@ -55,18 +55,28 @@ class PagarMeTestCase < Test::Unit::TestCase
55
55
  end
56
56
  end
57
57
 
58
- def fixed_api_key
59
- PagarMe.encryption_key = FIXED_ENCRYPTION_KEY
60
- PagarMe.api_key = FIXED_API_KEY
58
+ def change_company(api_version: nil, &block)
59
+ company = temporary_company api_version: api_version
60
+ change_api_and_encryption_keys api_key: company.api_key.test, encryption_key: company.encryption_key.test, &block
61
+ end
62
+
63
+ def change_api_and_encryption_keys(api_key: FIXED_API_KEY, encryption_key: FIXED_ENCRYPTION_KEY)
64
+ previous_encryption_key = PagarMe.encryption_key
65
+ previous_api_key = PagarMe.api_key
66
+
67
+ PagarMe.encryption_key = encryption_key
68
+ PagarMe.api_key = api_key
61
69
  yield
62
- PagarMe.encryption_key = temporary_company.encryption_key.test
63
- PagarMe.api_key = temporary_company.api_key.test
70
+
71
+ PagarMe.encryption_key = previous_encryption_key
72
+ PagarMe.api_key = previous_api_key
64
73
  end
74
+ alias :fixed_api_key :change_api_and_encryption_keys
65
75
 
66
- def temporary_company
67
- VCR.use_cassette 'TestCase/tmp_company' do
76
+ def temporary_company(api_version: nil)
77
+ VCR.use_cassette "TestCase/tmp_company/api_key/#{api_version}" do
68
78
  PagarMe.api_key = FIXED_API_KEY
69
- PagarMe::Company.temporary
79
+ PagarMe::Company.temporary api_version: api_version
70
80
  end
71
81
  end
72
82
 
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
4
+ version: 2.4.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: 2016-11-29 00:00:00.000000000 Z
12
+ date: 2019-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -54,21 +54,21 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: pry
57
+ name: webmock
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '2.3'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '2.3'
70
70
  - !ruby/object:Gem::Dependency
71
- name: vcr
71
+ name: pry
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
- name: rake
85
+ name: vcr
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
@@ -96,7 +96,7 @@ dependencies:
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  - !ruby/object:Gem::Dependency
99
- name: webmock
99
+ name: rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
102
  - - ">="
@@ -192,16 +192,21 @@ files:
192
192
  - lib/pagarme/resources/balance.rb
193
193
  - lib/pagarme/resources/balance_operation.rb
194
194
  - lib/pagarme/resources/bank_account.rb
195
+ - lib/pagarme/resources/billing.rb
195
196
  - lib/pagarme/resources/bulk_anticipation.rb
196
197
  - lib/pagarme/resources/card.rb
197
198
  - lib/pagarme/resources/company.rb
198
199
  - lib/pagarme/resources/customer.rb
200
+ - lib/pagarme/resources/fee_collection.rb
201
+ - lib/pagarme/resources/item.rb
199
202
  - lib/pagarme/resources/payable.rb
203
+ - lib/pagarme/resources/payment_link.rb
200
204
  - lib/pagarme/resources/phone.rb
201
205
  - lib/pagarme/resources/plan.rb
202
206
  - lib/pagarme/resources/postal_code.rb
203
207
  - lib/pagarme/resources/postback.rb
204
208
  - lib/pagarme/resources/recipient.rb
209
+ - lib/pagarme/resources/shipping.rb
205
210
  - lib/pagarme/resources/split_rule.rb
206
211
  - lib/pagarme/resources/subscription.rb
207
212
  - lib/pagarme/resources/transaction.rb
@@ -218,7 +223,9 @@ files:
218
223
  - test/pagarme/resources/bank_account_test.rb
219
224
  - test/pagarme/resources/bulk_anticipation_test.rb
220
225
  - test/pagarme/resources/card_test.rb
226
+ - test/pagarme/resources/customer_test.rb
221
227
  - test/pagarme/resources/payable_test.rb
228
+ - test/pagarme/resources/payment_link.rb
222
229
  - test/pagarme/resources/plan_test.rb
223
230
  - test/pagarme/resources/postback_test.rb
224
231
  - test/pagarme/resources/recipient_test.rb
@@ -246,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
253
  version: '0'
247
254
  requirements: []
248
255
  rubyforge_project:
249
- rubygems_version: 2.5.1
256
+ rubygems_version: 2.5.2.3
250
257
  signing_key:
251
258
  specification_version: 4
252
259
  summary: Allows integration with Pagar.me
@@ -259,7 +266,9 @@ test_files:
259
266
  - test/pagarme/resources/bank_account_test.rb
260
267
  - test/pagarme/resources/bulk_anticipation_test.rb
261
268
  - test/pagarme/resources/card_test.rb
269
+ - test/pagarme/resources/customer_test.rb
262
270
  - test/pagarme/resources/payable_test.rb
271
+ - test/pagarme/resources/payment_link.rb
263
272
  - test/pagarme/resources/plan_test.rb
264
273
  - test/pagarme/resources/postback_test.rb
265
274
  - test/pagarme/resources/recipient_test.rb