midas_client 0.2.1 → 0.2.13b

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.
@@ -1,5 +1,5 @@
1
1
  module MidasClient
2
- class Queries < Request
2
+ class Query < Request
3
3
 
4
4
  #= This method performs a query by a range date.
5
5
  # This is a is synchronous operation, using method GET
@@ -7,6 +7,55 @@ module MidasClient
7
7
  # Params:
8
8
  # start_date: date format YYYY-MM-DD
9
9
  # send_date: date format YYYY-MM-DD
10
+ # status: string
11
+ # type: string DIRECT/RECURRENT
12
+ #
13
+ # Response:
14
+ # result: {
15
+ # success: true/false
16
+ # code: "XXX"
17
+ # message: "Some message to you"
18
+ # }
19
+ def transaction_by_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil, type=nil)
20
+ log "Entrei em transaction_by_date"
21
+ # define o método de envio da requisição
22
+ method = :get
23
+
24
+ # monta a URL de chamada da requisição
25
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_period]
26
+ endpoint = endpoint.gsub("{startDate}", start_date).gsub("{endDate}", end_date)
27
+
28
+ # monta o parâmetro status na requisição da url
29
+ endpoint = status.blank? ? endpoint.gsub("&status={status}", '') : endpoint.gsub("{status}", status)
30
+
31
+ # monta o parâmetro type na requisição da url
32
+ endpoint = type.blank? ? endpoint.gsub("&type={type}", '') : endpoint.gsub("{type}", type)
33
+
34
+ # faz a chamada a plataforma de pagamento (MIDAS)
35
+ response = request(method, endpoint, self.login, self.password, {})
36
+
37
+ result = response[:result]
38
+ pagging = response[:pagging]
39
+ if response[:transactions].kind_of?(Array) || response[:transactions].blank?
40
+ transactions = response[:transactions]
41
+ else
42
+ transaction_array = []
43
+ transaction_array << response[:transactions]
44
+ transactions = transaction_array
45
+ end
46
+
47
+ response[:result] = result
48
+ response[:pagging] = pagging
49
+ response[:transactions] = transactions
50
+
51
+ response
52
+ end
53
+
54
+ #= This method performs a query by a specific transaction's identifier, called external ID.
55
+ # This is a is synchronous operation, using method GET
56
+ #
57
+ # Params:
58
+ # transactionToken: string (Transaction unique identification generated by customer)
10
59
  #
11
60
  #
12
61
  # Response:
@@ -15,59 +64,621 @@ module MidasClient
15
64
  # code: "XXX"
16
65
  # message: "Some message to you"
17
66
  # }
18
- def transaction_by_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil)
19
- log "Entrei em transaction_by_date"
67
+ def by_external_id(externalId)
68
+ log "Entrei em by_external_id"
69
+
20
70
  # define o método de envio da requisição
21
71
  method = :get
22
72
 
23
73
  # monta a URL de chamada da requisição
24
- endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_period].gsub("{startDate}", start_date).gsub("{endDate}", end_date)
74
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_external_id].gsub('{externalId}', externalId)
75
+
76
+ request(method, endpoint, login, password, {})
77
+ end
78
+
79
+ #= This method performs a query by an array of transaction's identifier.
80
+ # This is a is synchronous operation, using method GET
81
+ #
82
+ # Params:
83
+ # none
84
+ #
85
+ #
86
+ # Response:
87
+ # result: {
88
+ # success: true/false
89
+ # code: "XXX"
90
+ # message: "Some message to you"
91
+ # }
92
+ def by_external_ids(externalIds = [])
93
+ log "Entrei em by_external_ids"
94
+
95
+ # define o método de envio da requisição
96
+ method = :post
97
+
98
+ # monta a URL de chamada da requisição
99
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_external_ids]
100
+
101
+ request(method, endpoint, login, password, {externalIds: externalIds})
102
+ end
103
+
104
+ #= This method performs a query by an array of transaction's token.
105
+ # This is a is synchronous operation, using method GET
106
+ #
107
+ # Params:
108
+ # none
109
+ #
110
+ #
111
+ # Response:
112
+ # result: {
113
+ # success: true/false
114
+ # code: "XXX"
115
+ # message: "Some message to you"
116
+ # }
117
+ def by_transaction_tokens(transactionTokens = [])
118
+ log "Entrei em by_external_ids"
119
+
120
+ # define o método de envio da requisição
121
+ method = :post
122
+
123
+ # monta a URL de chamada da requisição
124
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_transaction_tokens]
125
+
126
+ request(method, endpoint, login, password, {transactionTokens: transactionTokens})
127
+ end
128
+
129
+ #= This method performs a query to return all subscriptions for a Point Of Sale by status
130
+ # This is a is synchronous operation, using method GET
131
+ #
132
+ # Params:
133
+ # status: ACTIVE/CANCELLED
134
+ #
135
+ # Response:
136
+ # result: {
137
+ # success: true/false
138
+ # code: "XXX"
139
+ # message: "Some message to you"
140
+ # }
141
+ def subscriptions(status = nil)
142
+ log "Entrei em subscriptions"
143
+ # define o método de envio da requisição
144
+ method = :get
145
+
146
+ # monta a URL de chamada da requisição
147
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:subscriptions]
25
148
 
26
149
  # monta os parâmetros da requisição na url
27
- endpoint = status.blank? ? endpoint.gsub("{status}", '') : endpoint.gsub("{status}", status)
150
+ endpoint = status.blank? ? endpoint.gsub("?status={status}", '') : endpoint.gsub("{status}", status)
28
151
 
29
152
  # faz a chamada a plataforma de pagamento (MIDAS)
30
153
  response = request(method, endpoint, self.login, self.password, {})
31
154
 
32
155
  result = response[:result]
33
156
  pagging = response[:pagging]
34
- if response[:transactions].kind_of?(Array) || response[:transactions].blank?
35
- transactions = response[:transactions]
157
+ if response[:subscriptions].kind_of?(Array) || response[:subscriptions].blank?
158
+ subscriptions = response[:subscriptions]
159
+ else
160
+ subscription_array = []
161
+ subscription_array << response[:subscriptions]
162
+ subscriptions = subscription_array
163
+ end
164
+
165
+ response[:result] = result
166
+ response[:pagging] = pagging
167
+ response[:subscriptions] = subscriptions
168
+
169
+ response
170
+ end
171
+
172
+ #= This method performs a query to return all invoices for a Point Of Sale by a period (by expirationDate) and status
173
+ # This is a is synchronous operation, using method GET
174
+ #
175
+ # Params:
176
+ # start_date: YYYY-MM-DD
177
+ # end_date: YYYY-MM-DD
178
+ # status: PAID/DENIED/RESERVED/CANCELLED
179
+ #
180
+ # Response:
181
+ # result: {
182
+ # success: true/false
183
+ # code: "XXX"
184
+ # message: "Some message to you"
185
+ # }
186
+ def invoices_by_expiration_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = 'PAID')
187
+ log "Entrei em invoices"
188
+ # define o método de envio da requisição
189
+ method = :get
190
+
191
+ # monta a URL de chamada da requisição
192
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:invoices_by_expiration_date]
193
+
194
+ # monta a URL de chamada da requisição
195
+ endpoint = endpoint .gsub("{startDate}", start_date).gsub("{endDate}", end_date)
196
+
197
+ # monta o parâmetro status na requisição da url
198
+ endpoint = status.blank? ? endpoint.gsub("&status={status}", '') : endpoint.gsub("{status}", status)
199
+
200
+ # faz a chamada a plataforma de pagamento (MIDAS)
201
+ response = request(method, endpoint, self.login, self.password, {})
202
+
203
+ result = response[:result]
204
+ pagging = response[:pagging]
205
+ if response[:invoices].kind_of?(Array) || response[:invoices].blank?
206
+ invoices = response[:invoices]
207
+ else
208
+ invoice_array = []
209
+ invoice_array << response[:invoices]
210
+ invoices = invoice_array
211
+ end
212
+
213
+ response[:result] = result
214
+ response[:pagging] = pagging
215
+ response[:invoices] = invoices
216
+
217
+ response
218
+ end
219
+
220
+ #= This method performs a query to return all invoices for a Point Of Sale by a period (by paymentDate) and status
221
+ # This is a is synchronous operation, using method GET
222
+ #
223
+ # Params:
224
+ # start_date: YYYY-MM-DD
225
+ # end_date: YYYY-MM-DD
226
+ # status: PAID/DENIED/RESERVED/CANCELLED
227
+ #
228
+ # Response:
229
+ # result: {
230
+ # success: true/false
231
+ # code: "XXX"
232
+ # message: "Some message to you"
233
+ # }
234
+ def invoices_by_payment_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = 'PAID')
235
+ log "Entrei em invoices"
236
+ # define o método de envio da requisição
237
+ method = :get
238
+
239
+ # monta a URL de chamada da requisição
240
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:invoices_by_payment_date]
241
+
242
+ # monta a URL de chamada da requisição
243
+ endpoint = endpoint .gsub("{startDate}", start_date).gsub("{endDate}", end_date)
244
+
245
+ # monta o parâmetro status na requisição da url
246
+ endpoint = status.blank? ? endpoint.gsub("&status={status}", '') : endpoint.gsub("{status}", status)
247
+
248
+ # faz a chamada a plataforma de pagamento (MIDAS)
249
+ response = request(method, endpoint, self.login, self.password, {})
250
+
251
+ result = response[:result]
252
+ pagging = response[:pagging]
253
+ if response[:invoices].kind_of?(Array) || response[:invoices].blank?
254
+ invoices = response[:invoices]
255
+ else
256
+ invoice_array = []
257
+ invoice_array << response[:invoices]
258
+ invoices = invoice_array
259
+ end
260
+
261
+ response[:result] = result
262
+ response[:pagging] = pagging
263
+ response[:invoices] = invoices
264
+
265
+ response
266
+ end
267
+
268
+ #= This method performs a query to return all creditcards stored for a Point Of Sale
269
+ # This is a is synchronous operation, using method GET
270
+ #
271
+ # Params:
272
+ # none
273
+ #
274
+ # Response:
275
+ # result: {
276
+ # success: true/false
277
+ # code: "XXX"
278
+ # message: "Some message to you"
279
+ # }
280
+ # creditCards: [
281
+ # {
282
+ # brand: "MASTER",
283
+ # panLastDigits": "4832",
284
+ # expirationMonth": 10,
285
+ # expirationYear": 2019,
286
+ # holderName": "Nome Portador",
287
+ # customer: {
288
+ # documentType: "CPF",
289
+ # documentNumber: "12345678900"
290
+ # },
291
+ # token: "b7553c62bc93ed0708b4behfcf28f3592"
292
+ # }
293
+ def list_creditcards()
294
+ log "Entrei em list_creditcards"
295
+ # define o método de envio da requisição
296
+ method = :get
297
+
298
+ # monta a URL de chamada da requisição
299
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:creditcards]
300
+
301
+ # faz a chamada a plataforma de pagamento (MIDAS)
302
+ request(method, endpoint, self.login, self.password, {})
303
+ end
304
+
305
+ #= This method performs a query to return all creditcards stored for a Point Of Sale
306
+ # This is a is synchronous operation, using method GET
307
+ #
308
+ # Params:
309
+ # none
310
+ #
311
+ # Response:
312
+ # result: {
313
+ # success: true/false
314
+ # code: "XXX"
315
+ # message: "Some message to you"
316
+ # }
317
+ # creditCards: [
318
+ # {
319
+ # brand: "MASTER",
320
+ # panLastDigits": "4832",
321
+ # expirationMonth": 10,
322
+ # expirationYear": 2019,
323
+ # holderName": "Nome Portador",
324
+ # customer: {
325
+ # documentType: "CPF",
326
+ # documentNumber: "12345678900"
327
+ # },
328
+ # token: "b7553c62bc93ed0708b4behfcf28f3592"
329
+ # }
330
+ def list_customers()
331
+ log "Entrei em list_customers"
332
+ # define o método de envio da requisição
333
+ method = :get
334
+
335
+ # monta a URL de chamada da requisição
336
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:customers]
337
+
338
+ # faz a chamada a plataforma de pagamento (MIDAS)
339
+ request(method, endpoint, self.login, self.password, {})
340
+ end
341
+
342
+ #= This method performs a query by a specific customer's document type and number.
343
+ # This is a is synchronous operation, using method GET
344
+ #
345
+ # Params:
346
+ # documentType: string (CPF/CNPJ)
347
+ # documentNumeber: number
348
+ #
349
+ # Response:
350
+ # result: {
351
+ # success: true/false
352
+ # code: "XXX"
353
+ # message: "Some message to you"
354
+ # }
355
+ def transactions_by_customer(documentType='CPF', documentNumber='', status = nil)
356
+ log "transactions_by_customer"
357
+
358
+ # define o método de envio da requisição
359
+ method = :get
360
+
361
+ # monta a URL de chamada da requisição
362
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:transactions_by_customer].gsub('{documentType}', documentType).gsub('{documentNumber}', sanitized_document_number(documentNumber))
363
+
364
+ # monta o parâmetro status na requisição da url
365
+ endpoint = status.blank? ? endpoint.gsub("&status={status}", '') : endpoint.gsub("{status}", status)
366
+
367
+ request(method, endpoint, login, password, {})
368
+ end
369
+
370
+ #= This method performs a query by a specific customer's document type and number and return all subscriptions from
371
+ #= the user in the plataform.
372
+ #
373
+ # This is a is synchronous operation, using method GET
374
+ #
375
+ # Params:
376
+ # documentType: string (CPF/CNPJ)
377
+ # documentNumeber: number
378
+ #
379
+ # Response:
380
+ # result: {
381
+ # success: true/false
382
+ # code: "XXX"
383
+ # message: "Some message to you"
384
+ # }
385
+ def subscriptions_by_customer(documentType='CPF', documentNumber='', status = nil)
386
+ log "subscriptions_by_customer"
387
+
388
+ # define o método de envio da requisição
389
+ method = :get
390
+
391
+ # monta a URL de chamada da requisição
392
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:subscriptions_by_customer].gsub('{documentType}', documentType).gsub('{documentNumber}', sanitized_document_number(documentNumber))
393
+
394
+ # monta o parâmetro status na requisição da url
395
+ endpoint = status.blank? ? endpoint.gsub("&status={status}", '') : endpoint.gsub("{status}", status)
396
+
397
+ request(method, endpoint, login, password, {})
398
+ end
399
+
400
+ #= This method performs a query that summarizes all card's(CREDIT/DEBIT) operation between a date period by DAY, BRAND, PAYMENT_METHOD and STATUS.
401
+ #
402
+ # This is a is synchronous operation, using method GET
403
+ #
404
+ # Params:
405
+ # start_date: string (YYYY-MM-DD)
406
+ # end_date: string (YYYY-MM-DD)
407
+ #
408
+ # Response:
409
+ # {
410
+ # "result": {
411
+ # "success": true,
412
+ # "code": "000",
413
+ # "message": "Sucesso"
414
+ # },
415
+ # "pagging": {
416
+ # "limit": 6,
417
+ # "count": 1,
418
+ # "current": 1
419
+ # },
420
+ # "transactionsSummary": [
421
+ # {
422
+ # "date": "2018-01-19",
423
+ # "brand": "Mastercard",
424
+ # "paymentMethod": "CREDIT_CARD",
425
+ # "status": "AUTHORIZED",
426
+ # "count": 3,
427
+ # "sum": 600,
428
+ # "average": 200
429
+ # },
430
+ # {
431
+ # "date": "2018-01-19",
432
+ # "brand": "Mastercard",
433
+ # "paymentMethod": "CREDIT_CARD",
434
+ # "status": "CAPTURED",
435
+ # "count": 3,
436
+ # "sum": 300,
437
+ # "average": 100
438
+ # }]
439
+ # }
440
+ def cards_summary_by_day(start_date=(Date.today.at_beginning_of_month).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'))
441
+ log "Entrei em cards_summary_by_day"
442
+ # define o método de envio da requisição
443
+ method = :get
444
+
445
+ # monta a URL de chamada da requisição
446
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:cards_summary_by_day]
447
+ endpoint = endpoint.gsub("{startDate}", start_date).gsub("{endDate}", end_date)
448
+
449
+ # faz a chamada a plataforma de pagamento (MIDAS)
450
+ response = request(method, endpoint, self.login, self.password, {})
451
+
452
+ result = response[:result]
453
+ pagging = response[:pagging]
454
+ if response[:transactionsSummary].kind_of?(Array) || response[:transactionsSummary].blank?
455
+ transactions = response[:transactionsSummary]
456
+ else
457
+ transaction_array = []
458
+ transaction_array << response[:transactionsSummary]
459
+ transactions = transaction_array
460
+ end
461
+
462
+ response[:result] = result
463
+ response[:pagging] = pagging
464
+ response[:transactionsSummary] = transactions
465
+
466
+ response
467
+ end
468
+
469
+ #= This method performs a query that summarizes all card's(CREDIT/DEBIT) operation between a date period by by MONTH, BRAND, PAYMENT_METHOD and STATUS.
470
+ #
471
+ # This is a is synchronous operation, using method GET
472
+ #
473
+ # Params:
474
+ # start_month: string (MM)
475
+ # end_month: string (MM)
476
+ # start_year: string (YYYY)
477
+ # end_year: string (YYYY)
478
+ #
479
+ # Response:
480
+ # {
481
+ # "result": {
482
+ # "success": true,
483
+ # "code": "000",
484
+ # "message": "Sucesso"
485
+ # },
486
+ # "pagging": {
487
+ # "limit": 6,
488
+ # "count": 1,
489
+ # "current": 1
490
+ # },
491
+ # "transactionsSummary": [
492
+ # {
493
+ # "year": 2018,
494
+ # "month": 1,
495
+ # "brand": "Mastercard",
496
+ # "paymentMethod": "CREDIT_CARD",
497
+ # "status": "AUTHORIZED",
498
+ # "count": 3,
499
+ # "sum": 600,
500
+ # "average": 200
501
+ # },
502
+ # {
503
+ # "year": 2018,
504
+ # "month": 1,
505
+ # "brand": "Mastercard",
506
+ # "paymentMethod": "CREDIT_CARD",
507
+ # "status": "CAPTURED",
508
+ # "count": 3,
509
+ # "sum": 300,
510
+ # "average": 200
511
+ # }]
512
+ # }
513
+ def cards_summary_by_month(start_month=(Date.today - 1.year).strftime('%m'), start_year=((Date.today - 1.year).strftime('%Y')), end_month=(Date.today).strftime('%m'), end_year=((Date.today).strftime('%Y')))
514
+ log "Entrei em cards_summary_by_month"
515
+ # define o método de envio da requisição
516
+ method = :get
517
+
518
+ # monta a URL de chamada da requisição
519
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:cards_summary_by_month]
520
+ endpoint = endpoint.gsub("{startMonth}", start_month).gsub("{startYear}", start_year).gsub("{endMonth}", end_month).gsub("{endYear}", end_year)
521
+
522
+ # faz a chamada a plataforma de pagamento (MIDAS)
523
+ response = request(method, endpoint, self.login, self.password, {})
524
+
525
+ result = response[:result]
526
+ pagging = response[:pagging]
527
+ if response[:transactionsSummary].kind_of?(Array) || response[:transactionsSummary].blank?
528
+ transactions = response[:transactionsSummary]
529
+ else
530
+ transaction_array = []
531
+ transaction_array << response[:transactionsSummary]
532
+ transactions = transaction_array
533
+ end
534
+
535
+ response[:result] = result
536
+ response[:pagging] = pagging
537
+ response[:transactionsSummary] = transactions
538
+
539
+ response
540
+ end
541
+
542
+ #= This method performs a query that summarizes all billet's operations between a date period by DATE, BANK, PAYMENT_METHOD and STATUS.
543
+ #
544
+ # This is a is synchronous operation, using method GET
545
+ #
546
+ # Params:
547
+ # start_date: string (YYYY-MM-DD)
548
+ # end_date: string (YYYY-MM-DD)
549
+ #
550
+ # Response:
551
+ # {
552
+ # "result": {
553
+ # "success": true,
554
+ # "code": "000",
555
+ # "message": "Sucesso"
556
+ # },
557
+ # "pagging": {
558
+ # "limit": 6,
559
+ # "count": 1,
560
+ # "current": 1
561
+ # },
562
+ # "transactionsSummary": [
563
+ # {
564
+ # "date": "2018-01-19",
565
+ # "brand": "Mastercard",
566
+ # "paymentMethod": "CREDIT_CARD",
567
+ # "status": "AUTHORIZED",
568
+ # "count": 3,
569
+ # "sum": 600,
570
+ # "average": 200
571
+ # },
572
+ # {
573
+ # "date": "2018-01-19",
574
+ # "brand": "Mastercard",
575
+ # "paymentMethod": "CREDIT_CARD",
576
+ # "status": "CAPTURED",
577
+ # "count": 3,
578
+ # "sum": 300,
579
+ # "average": 100
580
+ # }]
581
+ # }
582
+ def billets_summary_by_day(start_date=(Date.today.at_beginning_of_month).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'))
583
+ log "Entrei em billets_summary_by_day"
584
+ # define o método de envio da requisição
585
+ method = :get
586
+
587
+ # monta a URL de chamada da requisição
588
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:billets_summary_by_day]
589
+ endpoint = endpoint.gsub("{startDate}", start_date).gsub("{endDate}", end_date)
590
+
591
+ # faz a chamada a plataforma de pagamento (MIDAS)
592
+ response = request(method, endpoint, self.login, self.password, {})
593
+
594
+ result = response[:result]
595
+ pagging = response[:pagging]
596
+ if response[:transactionsSummary].kind_of?(Array) || response[:transactionsSummary].blank?
597
+ transactions = response[:transactionsSummary]
36
598
  else
37
599
  transaction_array = []
38
- transaction_array << response[:transactions]
600
+ transaction_array << response[:transactionsSummary]
39
601
  transactions = transaction_array
40
602
  end
41
603
 
42
604
  response[:result] = result
43
605
  response[:pagging] = pagging
44
- response[:transactions] = transactions
606
+ response[:transactionsSummary] = transactions
45
607
 
46
608
  response
47
609
  end
48
610
 
49
- end
50
-
51
- #= This method performs a query by a specific transaction's identifier, called external ID.
52
- # This is a is synchronous operation, using method GET
53
- #
54
- # Params:
55
- # transactionToken: string (Transaction unique identification generated by customer)
56
- #
57
- #
58
- # Response:
59
- # result: {
60
- # success: true/false
61
- # code: "XXX"
62
- # message: "Some message to you"
63
- # }
64
- def query_external_id(externalId)
65
- # define o método de envio da requisição
66
- method = :get
67
-
68
- # monta a URL de chamada da requisição
69
- endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_external_id].gsub('{externalId}', externalId)
70
-
71
- request(method, endpoint, login, password, {})
72
- end
611
+ #= This method performs a query that summarizes all billet's operations between a date period by MONTH, BANK, PAYMENT_METHOD and STATUS.
612
+ #
613
+ # This is a is synchronous operation, using method GET
614
+ #
615
+ # Params:
616
+ # start_month: string (MM)
617
+ # end_month: string (MM)
618
+ # start_year: string (YYYY)
619
+ # end_year: string (YYYY)
620
+ #
621
+ # Response:
622
+ # {
623
+ # "result": {
624
+ # "success": true,
625
+ # "code": "000",
626
+ # "message": "Sucesso"
627
+ # },
628
+ # "pagging": {
629
+ # "limit": 6,
630
+ # "count": 1,
631
+ # "current": 1
632
+ # },
633
+ # "transactionsSummary": [
634
+ # {
635
+ # "year": 2018,
636
+ # "month": 1,
637
+ # "brand": "Mastercard",
638
+ # "paymentMethod": "CREDIT_CARD",
639
+ # "status": "AUTHORIZED",
640
+ # "count": 3,
641
+ # "sum": 600,
642
+ # "average": 200
643
+ # },
644
+ # {
645
+ # "year": 2018,
646
+ # "month": 1,
647
+ # "brand": "Mastercard",
648
+ # "paymentMethod": "CREDIT_CARD",
649
+ # "status": "CAPTURED",
650
+ # "count": 3,
651
+ # "sum": 300,
652
+ # "average": 200
653
+ # }]
654
+ # }
655
+ def billets_summary_by_month(start_month=(Date.today - 1.year).strftime('%m'), start_year=((Date.today - 1.year).strftime('%Y')), end_month=(Date.today).strftime('%m'), end_year=((Date.today).strftime('%Y')))
656
+ log "Entrei em billets_summary_by_month"
657
+ # define o método de envio da requisição
658
+ method = :get
659
+
660
+ # monta a URL de chamada da requisição
661
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:billets_summary_by_month]
662
+ endpoint = endpoint.gsub("{startMonth}", start_month).gsub("{startYear}", start_year).gsub("{endMonth}", end_month).gsub("{endYear}", end_year)
663
+
664
+ # faz a chamada a plataforma de pagamento (MIDAS)
665
+ response = request(method, endpoint, self.login, self.password, {})
666
+
667
+ result = response[:result]
668
+ pagging = response[:pagging]
669
+ if response[:transactionsSummary].kind_of?(Array) || response[:transactionsSummary].blank?
670
+ transactions = response[:transactionsSummary]
671
+ else
672
+ transaction_array = []
673
+ transaction_array << response[:transactionsSummary]
674
+ transactions = transaction_array
675
+ end
676
+
677
+ response[:result] = result
678
+ response[:pagging] = pagging
679
+ response[:transactionsSummary] = transactions
680
+
681
+ response
682
+ end
683
+ end
73
684
  end