midas_client 0.2.1 → 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 +86 -3
- data/lib/midas_client/endpoints.rb +32 -6
- data/lib/midas_client/management.rb +44 -11
- data/lib/midas_client/query.rb +644 -33
- data/lib/midas_client/request.rb +17 -2
- data/lib/midas_client/subscription.rb +183 -13
- data/lib/midas_client/transaction.rb +95 -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
@@ -5,16 +5,19 @@ module MidasClient
|
|
5
5
|
include EndPoints
|
6
6
|
|
7
7
|
attr_accessor :login, :password, :environment
|
8
|
+
attr_accessor :transaction
|
9
|
+
attr_accessor :subscription
|
10
|
+
attr_accessor :query
|
8
11
|
|
9
12
|
def initialize(login=nil, password=nil, environment='DEVELOPMENT', option={})
|
10
13
|
@login = login
|
11
14
|
@password = password
|
12
15
|
@environment = environment
|
13
|
-
login.blank? ? log("POS STATIC INITIALIZED!") : log("POS #{login} INITIALIZED
|
16
|
+
login.blank? ? log("POS STATIC INITIALIZED!") : log("POS #{login} INITIALIZED - @environment: #{@environment}")
|
14
17
|
end
|
15
18
|
|
16
19
|
# Method that's wrap generic response
|
17
|
-
def base_result(success, code, message)
|
20
|
+
def self.base_result(success, code, message)
|
18
21
|
{
|
19
22
|
result: {
|
20
23
|
success: success,
|
@@ -87,5 +90,17 @@ module MidasClient
|
|
87
90
|
response
|
88
91
|
end
|
89
92
|
|
93
|
+
def transaction
|
94
|
+
@transaction ||= Transaction.new(login, password, environment)
|
95
|
+
end
|
96
|
+
|
97
|
+
def subscription
|
98
|
+
@subscription ||= Subscription.new(login, password, environment)
|
99
|
+
end
|
100
|
+
|
101
|
+
def query
|
102
|
+
@query ||= Query.new(login, password, environment)
|
103
|
+
end
|
104
|
+
|
90
105
|
end
|
91
106
|
end
|
@@ -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])
|
@@ -81,7 +84,7 @@ module MidasClient
|
|
81
84
|
#
|
82
85
|
# Response:
|
83
86
|
# result: {
|
84
|
-
# success: true/
|
87
|
+
# success: true/falseb0FIYhr/xCvGFMuR1Wg059X/0cqwLg==
|
85
88
|
# code: "XXX"
|
86
89
|
# message: "Some message to you"
|
87
90
|
# }
|
@@ -102,9 +105,11 @@ module MidasClient
|
|
102
105
|
# Params:
|
103
106
|
# subscriptionToken: querystring (Subscription unique identification generated by our
|
104
107
|
# gateway and received in the subscription's creation response)
|
105
|
-
#
|
108
|
+
# params: {
|
109
|
+
# amount: number (Only integer numbers, with the last two digits representing the cents.
|
106
110
|
# For example: 100 is equivalent to R$ 1,00)
|
107
|
-
#
|
111
|
+
# callbackUrl: string - URL to receive the result for each invoice charge
|
112
|
+
# }
|
108
113
|
#
|
109
114
|
# Response:
|
110
115
|
# result: {
|
@@ -123,19 +128,52 @@ module MidasClient
|
|
123
128
|
response = request(method, endpoint, self.login, self.password, params)
|
124
129
|
|
125
130
|
# recupera a lista de invoices da assinatura para chamar o método de atualização de cada invoice.
|
126
|
-
|
131
|
+
response_invoices = subscription_invoices(subscription_token)
|
132
|
+
result = response_invoices[:result]
|
133
|
+
invoices = response_invoices[:invoices]
|
127
134
|
|
128
135
|
# filtra apenas as invoices em aberto
|
129
|
-
opened_invoices = invoices.select{|s| s[:status] == 'OPEN'}
|
136
|
+
opened_invoices = invoices.select{|s| s[:status] == 'OPEN'} unless invoices.blank?
|
130
137
|
|
131
138
|
# percorre cada uma das invoices abertas e chama o método de atualização
|
132
139
|
opened_invoices.each do |inv|
|
133
140
|
update_invoice(inv[:token], {amount: params[:amount]})
|
134
|
-
end
|
141
|
+
end unless opened_invoices.blank?
|
135
142
|
response
|
136
143
|
end
|
137
144
|
|
138
|
-
#= 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.
|
139
177
|
# This is a is synchronous operation, using method GET
|
140
178
|
#
|
141
179
|
# Params:
|
@@ -219,6 +257,139 @@ module MidasClient
|
|
219
257
|
request(method, endpoint, self.login, self.password, {})
|
220
258
|
end
|
221
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
|
+
|
222
393
|
#= This method updates the credit card information associated to the subscription.
|
223
394
|
# This is a is synchronous operation, using method PUT
|
224
395
|
#
|
@@ -253,13 +424,12 @@ module MidasClient
|
|
253
424
|
|
254
425
|
#= This method updates a subscription.
|
255
426
|
# This is a is synchronous operation.
|
256
|
-
#
|
427
|
+
# QueryString:
|
428
|
+
# invoice_token: Invoice unique identification generated by our gateway
|
257
429
|
# Params:
|
258
|
-
# subscriptionToken: querystring (Subscription unique identification generated by our
|
259
|
-
# gateway and received in the subscription's creation response)
|
260
430
|
# amount: number (Only integer numbers, with the last two digits representing the cents.
|
261
431
|
# For example: 100 is equivalent to R$ 1,00)
|
262
|
-
# expirationDate string deadline date for the invoice. FORMAT:
|
432
|
+
# expirationDate string deadline date for the invoice. FORMAT: YYYY-MM-DD
|
263
433
|
#
|
264
434
|
# Response:
|
265
435
|
# result: {
|
@@ -377,5 +377,100 @@ module MidasClient
|
|
377
377
|
request(method, endpoint, login, password, {})
|
378
378
|
end
|
379
379
|
|
380
|
+
#= This method performs a query to list all creditcards form a user.
|
381
|
+
# This is a is synchronous operation, using method GET
|
382
|
+
#
|
383
|
+
# Params:
|
384
|
+
# documentType: string (CPF or CNPJ)
|
385
|
+
# documentNumber: string
|
386
|
+
#
|
387
|
+
#
|
388
|
+
# Response:
|
389
|
+
# result: {
|
390
|
+
# success: true/false
|
391
|
+
# code: "XXX"
|
392
|
+
# message: "Some message to you"
|
393
|
+
# }
|
394
|
+
def query_user_cards(document_type='CPF', document_number)
|
395
|
+
# define o método de envio da requisição
|
396
|
+
method = :get
|
397
|
+
|
398
|
+
# monta a URL de chamada da requisição
|
399
|
+
endpoint = get_env[:url] + EndPoints::OPERATIONS[:context] + EndPoints::OPERATIONS[:cards_by_user].gsub('{documentType}', document_type).gsub('{documentNumber}', document_number)
|
400
|
+
|
401
|
+
request(method, endpoint, login, password, {})
|
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
|
380
475
|
end
|
381
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
|