midas_client 0.2.1 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 949740b14437d4db4de04a152052379dc0c4a779
4
- data.tar.gz: 27271aba5cbcef7c04ba2ae89252f2361a91c89b
3
+ metadata.gz: 81c854614d06fb0820ef6fde44ea13ee781266c7
4
+ data.tar.gz: 1d40a8f4350905e685f539f619380fdfac92b7e3
5
5
  SHA512:
6
- metadata.gz: 90935d84f635edefd4e8e65e6df770c7be8ee73d1fe4d457fb5881ad32afd11a6247132d49f920f53c455a53911f33fe6dc880da863b3e169dcb64ac58c41080
7
- data.tar.gz: edfe960092329e9cb0ee4dc761ac57c31000c7a718560b9eddbebcfc2964a397b9d0d4a9a78a327350afc7729d98b02bc097a6491ab3c57ecca539f8abc42dfe
6
+ metadata.gz: e9ee9daec5887385a65edccca415957bcef666226a1f6531adc80a42798f8da574b9da52b3d78da2147faad71287bb5a9dd5e1f2dfa8ae7a0fa035250a9a951e
7
+ data.tar.gz: 61ffb8f7cda498954e0e169098ba0de225034c3d7446292da61bebb2e8e20d0e1209e961eea2795339447108956fd7fac4a45ca33eefd325573381a54033dad5
data/README.md CHANGED
@@ -33,8 +33,10 @@ Use client as follow:
33
33
 
34
34
  Request
35
35
 
36
- $ transaction = MidasClient::Transaction.new('pdv01','/eFRsg8RLne+I0GlECQofYvnsDfb0w==')
37
- $ transaction.card_store({"externalId":"teste_midas_client_00002", "pan":"5529525900844124", "expirationMonth":"01", "expirationYear":"2021", "holderName":"TESTE MIDAS CLIENT", "customer":{ "documentType":"CPF", "documentNumber":"36549450152"}})
36
+ $ request = MidasClient::Request.new('testes-01','/eFRsg8RLne+I0GlECQofYvnsDfb0w==', 'DEVELOPMENT')
37
+ $ request.transaction.card_store({"externalId":"teste_midas_client_00002", "pan":"5529525900844124", "expirationMonth":"01", "expirationYear":"2021", "holderName":"TESTE MIDAS CLIENT", "customer":{ "documentType":"CPF", "documentNumber":"36549450152"}})
38
+ $ request.subscription.cancel_subscription("subscription_token_00002")
39
+ $ request.query.list_customers
38
40
 
39
41
  Response
40
42
 
@@ -42,7 +44,29 @@ Response
42
44
  $ [17/05/2017 20:48:06.103][RESPONSE] {:result=>{:success=>true, :code=>"010", :message=>"O cartao jah foi armazenado anteriormente"}, :brand=>"MASTER", :cardToken=>"f887d732863eb3ef2e45c0bd8b57ed33"}
43
45
 
44
46
  ## Change Releases
45
- VERSION - 0.2.0 - 2017/10/11
47
+ VERSION - 0.2.4 - 2017/11/01
48
+
49
+ - Refactoring QUERIES CONSTANT to QUERY
50
+ - Query to list creditcards from a Point of Sale (MidasClient::Query.list_creditcards)
51
+ - Query to list creditcards from user's document number (MidasClient::Transation.query_user_cards)
52
+ - Query to list transactions by an array of external ids (MidasClient::Query.by_external_ids)
53
+ - Query to list transactions by an array of transaction tokens (MidasClient::Query.by_transaction_tokens)
54
+ - Query to list customers from de POint of Sale (MidasClient::Query.list_customers)
55
+ - Access attributes at Request to acess all subclasses from Request as singleton methods
56
+ - Refactoring class Queries name to Query
57
+ - read.me
58
+
59
+ VERSION - 0.2.3 - 2017/10/25
60
+
61
+ - Bug fix at MidasClient::Subscription.subscription_update
62
+ - read.me
63
+
64
+ VERSION - 0.2.2 - 2017/10/16
65
+
66
+ - Query to return all subscritions for a Point Of Sale at module Query.
67
+ - read.me
68
+
69
+ VERSION - 0.2.1 - 2017/10/11
46
70
 
47
71
  - Changing Development API endpoint
48
72
  - read.me
@@ -43,7 +43,8 @@ module MidasClient
43
43
  cancel: '/transaction/creditcard/{transactionToken}/cancel',
44
44
  refund: '/transaction/creditcard/{transactionToken}/refund',
45
45
  query_by_transaction: '/transaction/{transactionToken}',
46
- callback: 'http://matricula.crossfitlendarios.com.br/callback'
46
+ callback: 'http://matricula.crossfitlendarios.com.br/callback',
47
+ cards_by_user: '/customer/{documentType}/{documentNumber}/creditcard',
47
48
  }
48
49
 
49
50
  SUBSCRIPTIONS = {
@@ -62,7 +63,12 @@ module MidasClient
62
63
  QUERIES = {
63
64
  context: '/midas-query/v2',
64
65
  by_external_id: '/transactions/external-id/{externalId}',
66
+ by_external_ids: '/transactions/external-ids',
67
+ by_transaction_tokens: '/transactions/transaction-tokens',
65
68
  by_period: '/transactions?startDate={startDate}&endDate={endDate}&status={status}',
69
+ subscriptions: "/subscriptions?status={status}",
70
+ creditcards: '/creditcards',
71
+ customers: '/customers'
66
72
  }
67
73
 
68
74
  MANAGEMENTS = {
@@ -1,21 +1,21 @@
1
1
  module MidasClient
2
- class Queries < Request
3
-
4
- #= This method performs a query by a range date.
5
- # This is a is synchronous operation, using method GET
6
- #
7
- # Params:
8
- # start_date: date format YYYY-MM-DD
9
- # send_date: date format YYYY-MM-DD
10
- #
11
- #
12
- # Response:
13
- # result: {
14
- # success: true/false
15
- # code: "XXX"
16
- # message: "Some message to you"
17
- # }
18
- def transaction_by_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil)
2
+ class Query < Request
3
+
4
+ #= This method performs a query by a range date.
5
+ # This is a is synchronous operation, using method GET
6
+ #
7
+ # Params:
8
+ # start_date: date format YYYY-MM-DD
9
+ # send_date: date format YYYY-MM-DD
10
+ #
11
+ #
12
+ # Response:
13
+ # result: {
14
+ # success: true/false
15
+ # code: "XXX"
16
+ # message: "Some message to you"
17
+ # }
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
19
  log "Entrei em transaction_by_date"
20
20
  # define o método de envio da requisição
21
21
  method = :get
@@ -44,8 +44,6 @@ module MidasClient
44
44
  response[:transactions] = transactions
45
45
 
46
46
  response
47
- end
48
-
49
47
  end
50
48
 
51
49
  #= This method performs a query by a specific transaction's identifier, called external ID.
@@ -61,7 +59,9 @@ module MidasClient
61
59
  # code: "XXX"
62
60
  # message: "Some message to you"
63
61
  # }
64
- def query_external_id(externalId)
62
+ def by_external_id(externalId)
63
+ log "Entrei em by_external_id"
64
+
65
65
  # define o método de envio da requisição
66
66
  method = :get
67
67
 
@@ -70,4 +70,174 @@ module MidasClient
70
70
 
71
71
  request(method, endpoint, login, password, {})
72
72
  end
73
+
74
+ #= This method performs a query by an array of transaction's identifier.
75
+ # This is a is synchronous operation, using method GET
76
+ #
77
+ # Params:
78
+ # none
79
+ #
80
+ #
81
+ # Response:
82
+ # result: {
83
+ # success: true/false
84
+ # code: "XXX"
85
+ # message: "Some message to you"
86
+ # }
87
+ def by_external_ids(externalIds = [])
88
+ log "Entrei em by_external_ids"
89
+
90
+ # define o método de envio da requisição
91
+ method = :post
92
+
93
+ # monta a URL de chamada da requisição
94
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_external_ids]
95
+
96
+ request(method, endpoint, login, password, {externalIds: externalIds})
97
+ end
98
+
99
+ #= This method performs a query by an array of transaction's token.
100
+ # This is a is synchronous operation, using method GET
101
+ #
102
+ # Params:
103
+ # none
104
+ #
105
+ #
106
+ # Response:
107
+ # result: {
108
+ # success: true/false
109
+ # code: "XXX"
110
+ # message: "Some message to you"
111
+ # }
112
+ def by_transaction_tokens(transactionTokens = [])
113
+ log "Entrei em by_external_ids"
114
+
115
+ # define o método de envio da requisição
116
+ method = :post
117
+
118
+ # monta a URL de chamada da requisição
119
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_transaction_tokens]
120
+
121
+ request(method, endpoint, login, password, {transactionTokens: transactionTokens})
122
+ end
123
+
124
+ #= This method performs a query to return all subscriptions for a Point Of Sale by status
125
+ # This is a is synchronous operation, using method GET
126
+ #
127
+ # Params:
128
+ # status: ACTIVE/CANCELLED
129
+ #
130
+ # Response:
131
+ # result: {
132
+ # success: true/false
133
+ # code: "XXX"
134
+ # message: "Some message to you"
135
+ # }
136
+ def subscriptions(status = nil)
137
+ log "Entrei em subscriptions"
138
+ # define o método de envio da requisição
139
+ method = :get
140
+
141
+ # monta a URL de chamada da requisição
142
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:subscriptions]
143
+
144
+ # monta os parâmetros da requisição na url
145
+ endpoint = status.blank? ? endpoint.gsub("status={status}", '') : endpoint.gsub("{status}", status)
146
+
147
+ # faz a chamada a plataforma de pagamento (MIDAS)
148
+ response = request(method, endpoint, self.login, self.password, {})
149
+
150
+ result = response[:result]
151
+ pagging = response[:pagging]
152
+ if response[:subscriptions].kind_of?(Array) || response[:subscriptions].blank?
153
+ subscriptions = response[:subscriptions]
154
+ else
155
+ subscription_array = []
156
+ subscription_array << response[:subscriptions]
157
+ subscriptions = subscription_array
158
+ end
159
+
160
+ response[:result] = result
161
+ response[:pagging] = pagging
162
+ response[:subscriptions] = subscriptions
163
+
164
+ response
165
+ end
166
+
167
+ #= This method performs a query to return all creditcards stored for a Point Of Sale
168
+ # This is a is synchronous operation, using method GET
169
+ #
170
+ # Params:
171
+ # none
172
+ #
173
+ # Response:
174
+ # result: {
175
+ # success: true/false
176
+ # code: "XXX"
177
+ # message: "Some message to you"
178
+ # }
179
+ # creditCards: [
180
+ # {
181
+ # brand: "MASTER",
182
+ # panLastDigits": "4832",
183
+ # expirationMonth": 10,
184
+ # expirationYear": 2019,
185
+ # holderName": "Nome Portador",
186
+ # customer: {
187
+ # documentType: "CPF",
188
+ # documentNumber: "12345678900"
189
+ # },
190
+ # token: "b7553c62bc93ed0708b4behfcf28f3592"
191
+ # }
192
+ def list_creditcards()
193
+ log "Entrei em list_creditcards"
194
+ # define o método de envio da requisição
195
+ method = :get
196
+
197
+ # monta a URL de chamada da requisição
198
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:creditcards]
199
+
200
+ # faz a chamada a plataforma de pagamento (MIDAS)
201
+ request(method, endpoint, self.login, self.password, {})
202
+ end
203
+
204
+ #= This method performs a query to return all creditcards stored for a Point Of Sale
205
+ # This is a is synchronous operation, using method GET
206
+ #
207
+ # Params:
208
+ # none
209
+ #
210
+ # Response:
211
+ # result: {
212
+ # success: true/false
213
+ # code: "XXX"
214
+ # message: "Some message to you"
215
+ # }
216
+ # creditCards: [
217
+ # {
218
+ # brand: "MASTER",
219
+ # panLastDigits": "4832",
220
+ # expirationMonth": 10,
221
+ # expirationYear": 2019,
222
+ # holderName": "Nome Portador",
223
+ # customer: {
224
+ # documentType: "CPF",
225
+ # documentNumber: "12345678900"
226
+ # },
227
+ # token: "b7553c62bc93ed0708b4behfcf28f3592"
228
+ # }
229
+ def list_customers()
230
+ log "Entrei em list_customers"
231
+ # define o método de envio da requisição
232
+ method = :get
233
+
234
+ # monta a URL de chamada da requisição
235
+ endpoint = get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:customers]
236
+
237
+ # faz a chamada a plataforma de pagamento (MIDAS)
238
+ request(method, endpoint, self.login, self.password, {})
239
+ end
240
+
241
+
242
+ end
73
243
  end
@@ -5,6 +5,9 @@ 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
@@ -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
@@ -81,7 +81,7 @@ module MidasClient
81
81
  #
82
82
  # Response:
83
83
  # result: {
84
- # success: true/false
84
+ # success: true/falseb0FIYhr/xCvGFMuR1Wg059X/0cqwLg==
85
85
  # code: "XXX"
86
86
  # message: "Some message to you"
87
87
  # }
@@ -102,9 +102,11 @@ module MidasClient
102
102
  # Params:
103
103
  # subscriptionToken: querystring (Subscription unique identification generated by our
104
104
  # gateway and received in the subscription's creation response)
105
- # amount: number (Only integer numbers, with the last two digits representing the cents.
105
+ # params: {
106
+ # amount: number (Only integer numbers, with the last two digits representing the cents.
106
107
  # For example: 100 is equivalent to R$ 1,00)
107
- # callbackUrl string - URL to receive the result for each invoice charge
108
+ # callbackUrl: string - URL to receive the result for each invoice charge
109
+ # }
108
110
  #
109
111
  # Response:
110
112
  # result: {
@@ -123,10 +125,12 @@ module MidasClient
123
125
  response = request(method, endpoint, self.login, self.password, params)
124
126
 
125
127
  # recupera a lista de invoices da assinatura para chamar o método de atualização de cada invoice.
126
- result, invoices = subscription_invoices(subscription_token)
128
+ response_invoices = subscription_invoices(subscription_token)
129
+ result = response_invoices[:result]
130
+ invoices = response_invoices[:invoices]
127
131
 
128
132
  # filtra apenas as invoices em aberto
129
- opened_invoices = invoices.select{|s| s[:status] == 'OPEN'}
133
+ opened_invoices = invoices.select{|s| s[:status] == 'OPEN'} unless invoices.blank?
130
134
 
131
135
  # percorre cada uma das invoices abertas e chama o método de atualização
132
136
  opened_invoices.each do |inv|
@@ -377,5 +377,28 @@ 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
380
403
  end
381
404
  end
@@ -1,3 +1,3 @@
1
1
  module MidasClient
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.4"
3
3
  end
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.1
4
+ version: 0.2.4
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: 2017-10-11 00:00:00.000000000 Z
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler