midas_client 0.2.4 → 0.2.13b
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +59 -0
- data/lib/midas_client/endpoints.rb +27 -7
- data/lib/midas_client/management.rb +44 -11
- data/lib/midas_client/query.rb +656 -215
- data/lib/midas_client/request.rb +2 -2
- data/lib/midas_client/subscription.rb +174 -8
- data/lib/midas_client/transaction.rb +72 -0
- data/lib/midas_client/util.rb +4 -0
- data/lib/midas_client/version.rb +1 -1
- data/lib/midas_client.rb +2 -2
- metadata +5 -7
- data/lib/midas_client/billet.rb +0 -7
data/lib/midas_client/request.rb
CHANGED
@@ -13,11 +13,11 @@ module MidasClient
|
|
13
13
|
@login = login
|
14
14
|
@password = password
|
15
15
|
@environment = environment
|
16
|
-
login.blank? ? log("POS STATIC INITIALIZED!") : log("POS #{login} INITIALIZED
|
16
|
+
login.blank? ? log("POS STATIC INITIALIZED!") : log("POS #{login} INITIALIZED - @environment: #{@environment}")
|
17
17
|
end
|
18
18
|
|
19
19
|
# Method that's wrap generic response
|
20
|
-
def base_result(success, code, message)
|
20
|
+
def self.base_result(success, code, message)
|
21
21
|
{
|
22
22
|
result: {
|
23
23
|
success: success,
|
@@ -62,8 +62,11 @@ module MidasClient
|
|
62
62
|
method = :post
|
63
63
|
|
64
64
|
# monta a URL de chamada da requisição
|
65
|
-
|
66
|
-
|
65
|
+
if params[:cardToken].blank?
|
66
|
+
endpoint= get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:create_manual]
|
67
|
+
else
|
68
|
+
endpoint= get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:create_recurrent]
|
69
|
+
end
|
67
70
|
|
68
71
|
params[:externalDate] = (params[:externalDate].blank? ? Time.now.iso8601(1) : params[:externalDate])
|
69
72
|
params[:invoicesCount]= (params[:invoicesCount].blank? ? 12 : params[:invoicesCount])
|
@@ -135,11 +138,42 @@ module MidasClient
|
|
135
138
|
# percorre cada uma das invoices abertas e chama o método de atualização
|
136
139
|
opened_invoices.each do |inv|
|
137
140
|
update_invoice(inv[:token], {amount: params[:amount]})
|
138
|
-
end
|
141
|
+
end unless opened_invoices.blank?
|
139
142
|
response
|
140
143
|
end
|
141
144
|
|
142
|
-
#= This method
|
145
|
+
#= This method renew a subscription increasing the number of invoices associated. Works as a most complete update_subscription operation.
|
146
|
+
# This is a is synchronous operation.
|
147
|
+
#
|
148
|
+
# Params:
|
149
|
+
# subscriptionToken: URL querystring
|
150
|
+
# body:
|
151
|
+
# {
|
152
|
+
# "invoicesCount":2,
|
153
|
+
# "amount":200,
|
154
|
+
# "expirationDate":"2019-01-01"
|
155
|
+
# }
|
156
|
+
#
|
157
|
+
# Response:
|
158
|
+
# result: {
|
159
|
+
# success: true/false
|
160
|
+
# code: "XXX"
|
161
|
+
# message: "Some message to you"
|
162
|
+
# }
|
163
|
+
def renew_subscription(subscription_token, params)
|
164
|
+
# define o método de envio da requisição
|
165
|
+
method = :put
|
166
|
+
|
167
|
+
# monta a URL de chamada da requisição
|
168
|
+
endpoint = get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:renew].gsub('{subscriptionToken}', subscription_token)
|
169
|
+
|
170
|
+
# faz a chamada a plataforma de pagamento (MIDAS) para atualizar o valor, numero de invoices e data de expiração inicial das novas invoices de uma assinatura.
|
171
|
+
response = request(method, endpoint, self.login, self.password, params)
|
172
|
+
|
173
|
+
response
|
174
|
+
end
|
175
|
+
|
176
|
+
#= This method performs a query by a specific subscription.
|
143
177
|
# This is a is synchronous operation, using method GET
|
144
178
|
#
|
145
179
|
# Params:
|
@@ -223,6 +257,139 @@ module MidasClient
|
|
223
257
|
request(method, endpoint, self.login, self.password, {})
|
224
258
|
end
|
225
259
|
|
260
|
+
#= This method performs a query by a invoice token and return all transactions associated to it.
|
261
|
+
# This is a is synchronous operation, using method GET
|
262
|
+
#
|
263
|
+
# Params:
|
264
|
+
# invoice_token: string (Transaction unique identification generated by our
|
265
|
+
# gateway and received in the subscription's create response)#
|
266
|
+
#
|
267
|
+
#
|
268
|
+
# Response:
|
269
|
+
#
|
270
|
+
# {
|
271
|
+
# :result=>{
|
272
|
+
# :success=>true,
|
273
|
+
# :code=>"000",
|
274
|
+
# :message=>"Sucesso"
|
275
|
+
# },
|
276
|
+
# "transactions": [
|
277
|
+
# {
|
278
|
+
# "externalDate": "2017-10-13T03:00:00.731",
|
279
|
+
# "transactionType": "RECURRENT",
|
280
|
+
# "paymentMethod": "CREDIT_CARD",
|
281
|
+
# "creditCard": {
|
282
|
+
# "brand": "MASTER",
|
283
|
+
# "panLastDigits": "1137",
|
284
|
+
# "expirationMonth": 1,
|
285
|
+
# "expirationYear": 2022,
|
286
|
+
# "holderName": "Fulano de Tals",
|
287
|
+
# "customer": {
|
288
|
+
# "documentType": "CPF",
|
289
|
+
# "documentNumber": "24503795710"
|
290
|
+
# }
|
291
|
+
# },
|
292
|
+
# "amount": 22950,
|
293
|
+
# "instalments": 1,
|
294
|
+
# "token": "3962f882146ec3f6bf581a883f52004f",
|
295
|
+
# "status": "ERROR"
|
296
|
+
# }
|
297
|
+
# ]
|
298
|
+
# }
|
299
|
+
def invoice_transactions(invoice_token)
|
300
|
+
# define o método de envio da requisição
|
301
|
+
method = :get
|
302
|
+
|
303
|
+
# monta a URL de chamada da requisição
|
304
|
+
endpoint = get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:invoice_transactions].gsub('{invoiceToken}', invoice_token)
|
305
|
+
|
306
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
307
|
+
request(method, endpoint, self.login, self.password, {})
|
308
|
+
end
|
309
|
+
|
310
|
+
#= This method associate a transactionToken to an invoice, which changes the invoice status
|
311
|
+
# This is a is synchronous operation, using method PUT
|
312
|
+
#
|
313
|
+
# Params:
|
314
|
+
# invoice_token: string (Transaction unique identification generated by our
|
315
|
+
# gateway and received in the subscription's create response)#
|
316
|
+
#
|
317
|
+
# transaction_token: string Identification of the token from the transaction that will
|
318
|
+
# be associated to the invoice
|
319
|
+
#
|
320
|
+
# Response:
|
321
|
+
#
|
322
|
+
# {
|
323
|
+
# :result=>{
|
324
|
+
# :success=>true,
|
325
|
+
# :code=>"000",
|
326
|
+
# :message=>"Sucesso"
|
327
|
+
# }
|
328
|
+
def invoice_payment(invoice_token, transaction_token)
|
329
|
+
# define o método de envio da requisição
|
330
|
+
method = :put
|
331
|
+
|
332
|
+
# monta a URL de chamada da requisição
|
333
|
+
endpoint = get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:invoice_payment].gsub('{invoiceToken}', invoice_token)
|
334
|
+
|
335
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
336
|
+
request(method, endpoint, self.login, self.password, {transactionToken: transaction_token})
|
337
|
+
end
|
338
|
+
|
339
|
+
#= This method set an invoice as PAID, which changes the invoice status
|
340
|
+
# This is a is synchronous operation, using method PUT
|
341
|
+
#
|
342
|
+
# Params:
|
343
|
+
# payment_date: string (format YYYY-MM-DD, ex: 2018-05-28)
|
344
|
+
#
|
345
|
+
# payment_voucher: string Identification of the external payment that will
|
346
|
+
# be associated to the invoice
|
347
|
+
#
|
348
|
+
# Response:
|
349
|
+
#
|
350
|
+
# {
|
351
|
+
# :result=>{
|
352
|
+
# :success=>true,
|
353
|
+
# :code=>"000",
|
354
|
+
# :message=>"Sucesso"
|
355
|
+
# }
|
356
|
+
def invoice_external_payment(invoice_token, payment_date, payment_voucher)
|
357
|
+
# define o método de envio da requisição
|
358
|
+
method = :put
|
359
|
+
|
360
|
+
# monta a URL de chamada da requisição
|
361
|
+
endpoint = get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:invoice_external_payment].gsub('{invoiceToken}', invoice_token)
|
362
|
+
|
363
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
364
|
+
request(method, endpoint, self.login, self.password, {paymentDate: payment_date, paymentVoucher: payment_voucher})
|
365
|
+
end
|
366
|
+
|
367
|
+
#= This method cancel an invoice of a subscription
|
368
|
+
# This is a is synchronous operation, using method PUT
|
369
|
+
#
|
370
|
+
# Params:
|
371
|
+
# invoice_token: string (Transaction unique identification generated by our
|
372
|
+
# gateway and received in the subscription's create response)#
|
373
|
+
#
|
374
|
+
# Response:
|
375
|
+
#
|
376
|
+
# {
|
377
|
+
# :result=>{
|
378
|
+
# :success=>true,
|
379
|
+
# :code=>"000",
|
380
|
+
# :message=>"Sucesso"
|
381
|
+
# }
|
382
|
+
def invoice_cancel(invoice_token)
|
383
|
+
# define o método de envio da requisição
|
384
|
+
method = :put
|
385
|
+
|
386
|
+
# monta a URL de chamada da requisição
|
387
|
+
endpoint = get_env[:url] + EndPoints::SUBSCRIPTIONS[:context] + EndPoints::SUBSCRIPTIONS[:invoice_cancel].gsub('{invoiceToken}', invoice_token)
|
388
|
+
|
389
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
390
|
+
request(method, endpoint, self.login, self.password, {})
|
391
|
+
end
|
392
|
+
|
226
393
|
#= This method updates the credit card information associated to the subscription.
|
227
394
|
# This is a is synchronous operation, using method PUT
|
228
395
|
#
|
@@ -257,13 +424,12 @@ module MidasClient
|
|
257
424
|
|
258
425
|
#= This method updates a subscription.
|
259
426
|
# This is a is synchronous operation.
|
260
|
-
#
|
427
|
+
# QueryString:
|
428
|
+
# invoice_token: Invoice unique identification generated by our gateway
|
261
429
|
# Params:
|
262
|
-
# subscriptionToken: querystring (Subscription unique identification generated by our
|
263
|
-
# gateway and received in the subscription's creation response)
|
264
430
|
# amount: number (Only integer numbers, with the last two digits representing the cents.
|
265
431
|
# For example: 100 is equivalent to R$ 1,00)
|
266
|
-
# expirationDate string deadline date for the invoice. FORMAT:
|
432
|
+
# expirationDate string deadline date for the invoice. FORMAT: YYYY-MM-DD
|
267
433
|
#
|
268
434
|
# Response:
|
269
435
|
# result: {
|
@@ -400,5 +400,77 @@ module MidasClient
|
|
400
400
|
|
401
401
|
request(method, endpoint, login, password, {})
|
402
402
|
end
|
403
|
+
|
404
|
+
#= This method creates a billet to be paid
|
405
|
+
#
|
406
|
+
# Params:
|
407
|
+
# externalId: Unique identifier
|
408
|
+
# externalDate: Date of operation
|
409
|
+
# bankNumber: Bank Number associated to the PointOfSale
|
410
|
+
# payer/name: Payer details
|
411
|
+
# payer/documentType
|
412
|
+
# payer/documentNumber
|
413
|
+
# payer/address
|
414
|
+
# payer/neighborhood
|
415
|
+
# payer/zipCode
|
416
|
+
# payer/city
|
417
|
+
# payer/state
|
418
|
+
# expirationDate: Expiration Date
|
419
|
+
# amount: Value of transaction in cents
|
420
|
+
# callbackURL
|
421
|
+
#
|
422
|
+
# # Response:
|
423
|
+
# {
|
424
|
+
# "result": {
|
425
|
+
# "success": true,
|
426
|
+
# "code": "000",
|
427
|
+
# "message": "Sucesso"
|
428
|
+
# },
|
429
|
+
# "transactionToken": "83f90dd4569ab44cb46faa0f62b645a4",
|
430
|
+
# "lineCode": "34191.09008 00001.230721 00989.870001 1 74700000000100",
|
431
|
+
# "url": "http://api.sandbox.ansertecnologia.net/midas-core/v2/transaction/bankbillet/83f90dd4569ab44cb46faa0f62b645a4"
|
432
|
+
# }
|
433
|
+
def create_billet(*params)
|
434
|
+
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
435
|
+
params = params.first
|
436
|
+
|
437
|
+
# define o método de envio da requisição
|
438
|
+
method = :post
|
439
|
+
|
440
|
+
# monta a URL de chamada da requisição
|
441
|
+
endpoint= get_env[:url] + EndPoints::OPERATIONS[:context] + EndPoints::OPERATIONS[:create_billet]
|
442
|
+
|
443
|
+
# regulariza o formato da data
|
444
|
+
params[:externalDate] = (params[:externalDate].blank? ? Time.now.iso8601(1) : params[:externalDate])
|
445
|
+
|
446
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
447
|
+
request(method, endpoint, self.login, self.password, params)
|
448
|
+
|
449
|
+
end
|
450
|
+
|
451
|
+
#= This method return the URL of billet to be paid
|
452
|
+
# This is a is synchronous operation.
|
453
|
+
#
|
454
|
+
# Params:
|
455
|
+
# transactionToken: string (Transaction unique identification generated by our
|
456
|
+
# gateway and received in the create billet response)
|
457
|
+
#
|
458
|
+
# Response:
|
459
|
+
# result: {
|
460
|
+
# success: true/false
|
461
|
+
# code: "XXX"
|
462
|
+
# message: "Some message to you"
|
463
|
+
# }
|
464
|
+
def print_billet(transaction_token)
|
465
|
+
# define o método de envio da requisição
|
466
|
+
method = :get
|
467
|
+
|
468
|
+
# monta a URL de chamada da requisição
|
469
|
+
endpoint = get_env[:url] + EndPoints::OPERATIONS[:context] + EndPoints::OPERATIONS[:print_billet].gsub('{transactionToken}', transaction_token)
|
470
|
+
|
471
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
472
|
+
request(method, endpoint, self.login, self.password, {})
|
473
|
+
|
474
|
+
end
|
403
475
|
end
|
404
476
|
end
|
data/lib/midas_client/util.rb
CHANGED
@@ -19,6 +19,10 @@ module MidasClient
|
|
19
19
|
logger.error "#{text}"
|
20
20
|
end
|
21
21
|
|
22
|
+
def sanitized_document_number(number)
|
23
|
+
number.gsub('.', '').gsub('-','') unless number.nil?
|
24
|
+
end
|
25
|
+
|
22
26
|
def sanitize_pci(text)
|
23
27
|
CreditCardSanitizer.new(replacement_token: '@').sanitize!(text.to_s) || text
|
24
28
|
end
|
data/lib/midas_client/version.rb
CHANGED
data/lib/midas_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: midas_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.13b
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Andre Oliveira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,6 @@ files:
|
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
99
|
- lib/midas_client.rb
|
100
|
-
- lib/midas_client/billet.rb
|
101
100
|
- lib/midas_client/endpoints.rb
|
102
101
|
- lib/midas_client/management.rb
|
103
102
|
- lib/midas_client/query.rb
|
@@ -123,12 +122,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
122
|
version: '0'
|
124
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
124
|
requirements:
|
126
|
-
- - "
|
125
|
+
- - ">"
|
127
126
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
127
|
+
version: 1.3.1
|
129
128
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.5.1
|
129
|
+
rubygems_version: 3.0.8
|
132
130
|
signing_key:
|
133
131
|
specification_version: 4
|
134
132
|
summary: Midas Client REST API - https://ansertecnologia.com
|