midas_client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -5
- data/lib/midas_client.rb +19 -6
- data/lib/midas_client/endpoints.rb +33 -29
- data/lib/midas_client/{queries.rb → query.rb} +5 -13
- data/lib/midas_client/request.rb +4 -4
- data/lib/midas_client/subscription.rb +16 -54
- data/lib/midas_client/transaction.rb +20 -78
- data/lib/midas_client/util.rb +11 -4
- data/lib/midas_client/version.rb +1 -1
- data/midas_client.gemspec +0 -4
- metadata +4 -8
- data/config/settings.yml +0 -24
- data/config/settings/development.yml +0 -31
- data/config/settings/production.yml +0 -31
- data/config/settings/test.yml +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48c2b25290113dfad892d58a05687d1de8b89475
|
4
|
+
data.tar.gz: 663fed3bda6bbba8da20dd7cd8132b3b1f01ece3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 115e6253d94e6ff221d2a434b73b897fae9e9df0d123778d88a814ffba9742629f8a6538608e34c93559425c09c294577dd89ede10840af911504a2d95f5213a
|
7
|
+
data.tar.gz: 83217c8b4e346ae2533877ac95eefc896139ff9f9815b1ebab731dc589065d1ec8317b5b1c7ab2063789c2c99df2258d3f9dea1c2667000be9dec8c5809aa9ce
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ https://ansertecnologia.atlassian.net/wiki/x/EYCyAg
|
|
8
8
|
Add this line to your application's Gemfile:
|
9
9
|
|
10
10
|
```ruby
|
11
|
-
gem 'midas_client'
|
11
|
+
gem 'midas_client', git: 'https://bitbucket.org/ansertecnologia/midas_client.git'
|
12
12
|
```
|
13
13
|
|
14
14
|
And then execute:
|
@@ -42,9 +42,15 @@ Response
|
|
42
42
|
$ [MIDAS_CLIENT][CALLER:request][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
43
|
|
44
44
|
## Change Releases
|
45
|
+
|
46
|
+
VERSION - 0.1.3 - 2017/05/22
|
47
|
+
- Removing Rails log dependency
|
48
|
+
- Removing Rails.env dependency
|
49
|
+
- read.me
|
50
|
+
|
45
51
|
VERSION - 0.1.2 - 2017/05/19
|
46
52
|
|
47
|
-
|
53
|
+
Subscriptions
|
48
54
|
- Update Subscription
|
49
55
|
- Update Invoice
|
50
56
|
- bugfix
|
@@ -52,13 +58,13 @@ Operations available: Subscriptions
|
|
52
58
|
|
53
59
|
VERSION - 0.1.1 - 2017/05/16
|
54
60
|
|
55
|
-
|
61
|
+
Subscriptions
|
56
62
|
- Implementing logging features
|
57
63
|
- bugfix
|
58
64
|
|
59
65
|
VERSION - 0.1.0 - 2017/05/15
|
60
66
|
|
61
|
-
|
67
|
+
Transactions
|
62
68
|
- Creditcard Store (tokenization)
|
63
69
|
- Synchronous Transaction (Authorize + Capture)
|
64
70
|
- Asynchronous Transaction (Authorize + Capture)
|
@@ -69,7 +75,7 @@ Operations available: Transactions
|
|
69
75
|
- Refund
|
70
76
|
- Query Transaction
|
71
77
|
|
72
|
-
|
78
|
+
Subscriptions
|
73
79
|
- Create Subscription
|
74
80
|
- Cancel Subscription
|
75
81
|
- Subscription by Token
|
data/lib/midas_client.rb
CHANGED
@@ -1,12 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'stringio'
|
3
|
+
require 'logger'
|
1
4
|
require 'rest_client'
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
require 'credit_card_sanitizer'
|
6
|
+
|
7
|
+
require_relative "midas_client/version"
|
8
|
+
require_relative "midas_client/util"
|
9
|
+
require_relative "midas_client/endpoints"
|
10
|
+
require_relative "midas_client/request"
|
11
|
+
require_relative "midas_client/transaction"
|
12
|
+
require_relative "midas_client/subscription"
|
13
|
+
|
14
|
+
|
15
|
+
#Dir[File.expand_path('../midas_client/resources/*.rb', __FILE__)].map do |path|
|
16
|
+
# require path
|
17
|
+
#end
|
8
18
|
|
9
19
|
module MidasClient
|
10
20
|
@@spec = Gem::Specification.find_by_name("midas_client")
|
11
21
|
@@gem_root = @@spec.gem_dir
|
22
|
+
|
23
|
+
class << self
|
24
|
+
end
|
12
25
|
end
|
@@ -1,46 +1,50 @@
|
|
1
1
|
module MidasClient
|
2
2
|
module EndPoints
|
3
3
|
|
4
|
+
def self.production?
|
5
|
+
(ENV['RACK_ENV'] == 'production') || (ENV['RAILS_ENV'] == 'production') || ENV['PRODUCTION'] || ENV['production']
|
6
|
+
end
|
7
|
+
|
4
8
|
def self.get_env
|
5
|
-
|
9
|
+
self.production? ? PRODUCTION : DEVELOPMENT
|
6
10
|
end
|
7
11
|
|
8
|
-
|
9
|
-
url:
|
10
|
-
context:
|
12
|
+
DEVELOPMENT ={
|
13
|
+
url: 'https://sandbox.ansertecnologia.net',
|
14
|
+
context: '/midas-core/v2',
|
11
15
|
}
|
12
16
|
|
13
|
-
|
14
|
-
url:
|
15
|
-
context:
|
17
|
+
PRODUCTION ={
|
18
|
+
url: 'https://api.ansertecnologia.net',
|
19
|
+
context: '/midas-core/v2',
|
16
20
|
}
|
17
21
|
|
18
|
-
|
19
|
-
store:
|
20
|
-
synchronous_transaction:
|
21
|
-
asynchronous_transaction:
|
22
|
-
authorize:
|
23
|
-
confirm:
|
24
|
-
cancel:
|
25
|
-
refund:
|
26
|
-
query_by_transaction:
|
27
|
-
callback:
|
22
|
+
OPERATIONS = {
|
23
|
+
store: '/creditcard',
|
24
|
+
synchronous_transaction: '/transaction/creditcard',
|
25
|
+
asynchronous_transaction: '/transaction/creditcard/dispatch',
|
26
|
+
authorize: '/transaction/creditcard/authorize',
|
27
|
+
confirm: '/transaction/creditcard/{transactionToken}/capture',
|
28
|
+
cancel: '/transaction/creditcard/{transactionToken}/cancel',
|
29
|
+
refund: '/transaction/creditcard/{transactionToken}/refund',
|
30
|
+
query_by_transaction: '/transaction/{transactionToken}',
|
31
|
+
callback: 'http://matricula.crossfitlendarios.com.br/callback',
|
28
32
|
}
|
29
33
|
|
30
|
-
|
31
|
-
by_token:
|
32
|
-
invoices:
|
33
|
-
invoice_transactions:
|
34
|
-
create:
|
35
|
-
cancel:
|
36
|
-
update:
|
37
|
-
update_invoice:
|
38
|
-
callback:
|
34
|
+
SUBSCRIPTIONS = {
|
35
|
+
by_token: '/subscription/{subscriptionToken}',
|
36
|
+
invoices: '/subscription/{subscriptionToken}/invoices',
|
37
|
+
invoice_transactions: '/invoice/{invoiceToken}/transactions',
|
38
|
+
create: '/subscription/creditcard',
|
39
|
+
cancel: '/subscription/{subscriptionToken}/cancel',
|
40
|
+
update: '/subscription/{subscriptionToken}',
|
41
|
+
update_invoice: '/invoice/{invoiceToken}',
|
42
|
+
callback: 'https://matricula.crossfitlendarios.com.br/callback'
|
39
43
|
}
|
40
44
|
|
41
|
-
|
42
|
-
by_period:
|
43
|
-
subscriptions:
|
45
|
+
QUERIES = {
|
46
|
+
by_period: '/transactions',
|
47
|
+
subscriptions: '/subscriptions'
|
44
48
|
}
|
45
49
|
end
|
46
50
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module MidasClient
|
2
|
-
class Queries <
|
2
|
+
class Queries < Request
|
3
3
|
|
4
|
-
include
|
4
|
+
include EndPoints
|
5
5
|
|
6
6
|
# This method performs a query by a range date.
|
7
7
|
# This is a is synchronous operation, using method GET
|
@@ -17,23 +17,15 @@ module MidasClient
|
|
17
17
|
# code: "XXX"
|
18
18
|
# message: "Some message to you"
|
19
19
|
# }
|
20
|
-
def
|
21
|
-
# inicializa as variáveis de retorno
|
22
|
-
result ={}
|
23
|
-
|
20
|
+
def transaction_by_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil)
|
24
21
|
# define o método de envio da requisição
|
25
22
|
method = :get
|
26
23
|
|
27
24
|
# monta a URL de chamada da requisição
|
28
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
25
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::QUERIES[:by_period]
|
29
26
|
|
30
27
|
# monta os parâmetros da requisição na url
|
31
|
-
|
32
|
-
params = { startDate: start_date, endDate: end_date}
|
33
|
-
else
|
34
|
-
params = { startDate: start_date, endDate: end_date, status: status}
|
35
|
-
end
|
36
|
-
#endpoint= "#{endpoint}/#{transaction_token}"
|
28
|
+
params = status.blank? ? { startDate: start_date, endDate: end_date} : { startDate: start_date, endDate: end_date, status: status}
|
37
29
|
|
38
30
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
39
31
|
response = request(method, endpoint, self.login, self.password, params)
|
data/lib/midas_client/request.rb
CHANGED
@@ -23,7 +23,7 @@ module MidasClient
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# Method that's wrap rest-client generic request
|
26
|
-
def request(method, endpoint, login, password, parameters, headers={content_type: :json, accept: :json})
|
26
|
+
def request(method, endpoint, login, password, parameters={}, headers={content_type: :json, accept: :json})
|
27
27
|
# inicia a contagem da execução
|
28
28
|
start_time_execution = Time.now
|
29
29
|
log "METHOD: #{method} URL: #{endpoint} login: #{login} password: #{password} payload: #{self.sanitize_pci(parameters)}"
|
@@ -45,7 +45,7 @@ module MidasClient
|
|
45
45
|
response = JSON.parse(response, symbolize_names: true )
|
46
46
|
rescue => e
|
47
47
|
error_log "METHOD: #{method} URL: #{endpoint} login: #{login} Mensagem: #{e.to_s}"
|
48
|
-
response = base_result(false,
|
48
|
+
response = base_result(false, '999', "Operação não concluída. Motivo: #{e.to_s}")
|
49
49
|
ensure
|
50
50
|
total_time_execution = Time.now - start_time_execution
|
51
51
|
log "[RESPONSE] #{self.sanitize_pci(response)}"
|
@@ -56,7 +56,7 @@ module MidasClient
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# Method to call any other
|
59
|
-
def external_request(method, endpoint, parameters={}, headers={content_type: :json, accept: :json})
|
59
|
+
def self.external_request(method, endpoint, parameters={}, headers={content_type: :json, accept: :json})
|
60
60
|
# inicia a contagem da execução
|
61
61
|
start_time_execution = Time.now
|
62
62
|
|
@@ -75,7 +75,7 @@ module MidasClient
|
|
75
75
|
response = JSON.parse(response, symbolize_names: true )
|
76
76
|
rescue => e
|
77
77
|
error_log "[EXTERNAL][REQUEST]METHOD: #{method} URL: #{endpoint} Mensagem: #{e.to_s}"
|
78
|
-
response = base_result(false,
|
78
|
+
response = base_result(false, '999', "Operação não concluída. Motivo: #{e.to_s}")
|
79
79
|
ensure
|
80
80
|
total_time_execution = Time.now - start_time_execution
|
81
81
|
log "[EXTERNAL][RESPONSE][#{method}] URL: #{endpoint} TEMPO: #{total_time_execution}s RESULT: #{self.sanitize_pci(response)}"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module MidasClient
|
2
2
|
|
3
|
-
class Subscription <
|
3
|
+
class Subscription < Request
|
4
4
|
include EndPoints
|
5
5
|
|
6
6
|
# This method creates a subscription.
|
@@ -59,17 +59,11 @@ module MidasClient
|
|
59
59
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
60
60
|
params = params.first
|
61
61
|
|
62
|
-
# inicializa as variáveis de retorno
|
63
|
-
result ={}
|
64
|
-
|
65
|
-
first_invoice_result = ""
|
66
|
-
subscription_token = ""
|
67
|
-
|
68
62
|
# define o método de envio da requisição
|
69
63
|
method = :post
|
70
64
|
|
71
65
|
# monta a URL de chamada da requisição
|
72
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
66
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:create]
|
73
67
|
|
74
68
|
|
75
69
|
params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])
|
@@ -79,12 +73,9 @@ module MidasClient
|
|
79
73
|
response = request(method, endpoint, self.login, self.password, params)
|
80
74
|
|
81
75
|
result = response[:result]
|
82
|
-
subscription_token = response[:subscriptionToken]
|
76
|
+
subscription_token = response[:subscriptionToken]
|
83
77
|
first_invoice_result = response[:firstInvoiceResult]
|
84
78
|
|
85
|
-
# grava o tempo de execução da operação
|
86
|
-
total_time_execution = Time.now - start_time_execution
|
87
|
-
|
88
79
|
return result, subscription_token, first_invoice_result
|
89
80
|
end
|
90
81
|
|
@@ -102,21 +93,16 @@ module MidasClient
|
|
102
93
|
# message: "Some message to you"
|
103
94
|
# }
|
104
95
|
def cancel_subscription(subscription_token)
|
105
|
-
# inicializa as variáveis de retorno
|
106
|
-
result ={}
|
107
|
-
|
108
96
|
# define o método de envio da requisição
|
109
97
|
method = :put
|
110
98
|
|
111
99
|
# monta a URL de chamada da requisição
|
112
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
100
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:cancel].gsub('{subscriptionToken}', subscription_token)
|
113
101
|
|
114
102
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
115
103
|
response = request(method, endpoint, self.login, self.password, {})
|
116
104
|
|
117
|
-
|
118
|
-
|
119
|
-
return result
|
105
|
+
response[:result]
|
120
106
|
end
|
121
107
|
|
122
108
|
# This method updates a subscription callback, amount and updates opened invoices' amount.
|
@@ -140,7 +126,7 @@ module MidasClient
|
|
140
126
|
method = :put
|
141
127
|
|
142
128
|
# monta a URL de chamada da requisição
|
143
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
129
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:update].gsub('{subscriptionToken}', subscription_token)
|
144
130
|
|
145
131
|
# faz a chamada a plataforma de pagamento (MIDAS) para atualizar o valor de face e callback da assinatura
|
146
132
|
response = request(method, endpoint, self.login, self.password, params)
|
@@ -149,16 +135,14 @@ module MidasClient
|
|
149
135
|
invoices = subscription_invoices(subscription_token)
|
150
136
|
|
151
137
|
# filtra apenas as invoices em aberto
|
152
|
-
opened_invoices = invoices[:invoices].select{|s| s[:status] ==
|
138
|
+
opened_invoices = invoices[:invoices].select{|s| s[:status] == 'OPEN'}
|
153
139
|
|
154
140
|
# percorre cada uma das invoices abertas e chama o método de atualização
|
155
141
|
opened_invoices.each do |inv|
|
156
142
|
update_invoice(inv[:token], {amount: params[:amount]})
|
157
143
|
end
|
158
144
|
|
159
|
-
|
160
|
-
|
161
|
-
return result
|
145
|
+
response[:result]
|
162
146
|
end
|
163
147
|
|
164
148
|
# This method performs a query by a specific transaction.
|
@@ -200,21 +184,16 @@ module MidasClient
|
|
200
184
|
# }
|
201
185
|
# }
|
202
186
|
def subscription_by_token(subscription_token)
|
203
|
-
# inicializa as variáveis de retorno
|
204
|
-
result ={}
|
205
|
-
|
206
187
|
# define o método de envio da requisição
|
207
188
|
method = :get
|
208
189
|
|
209
190
|
# monta a URL de chamada da requisição
|
210
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
191
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:by_token].gsub('{subscriptionToken}', subscription_token)
|
211
192
|
|
212
193
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
213
194
|
response = request(method, endpoint, self.login, self.password, {})
|
214
195
|
|
215
|
-
|
216
|
-
|
217
|
-
return result, response[:subscription]
|
196
|
+
return response[:result], response[:subscription]
|
218
197
|
end
|
219
198
|
|
220
199
|
# This method performs a query by a specific transaction.
|
@@ -242,23 +221,16 @@ module MidasClient
|
|
242
221
|
# }. {:number=>2,...}, {:number=>3,}]
|
243
222
|
# }
|
244
223
|
def subscription_invoices(subscription_token)
|
245
|
-
# inicializa as variáveis de retorno
|
246
|
-
result ={}
|
247
|
-
|
248
224
|
# define o método de envio da requisição
|
249
225
|
method = :get
|
250
226
|
|
251
227
|
# monta a URL de chamada da requisição
|
252
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
228
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:invoices].gsub('{subscriptionToken}', subscription_token)
|
253
229
|
|
254
230
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
255
231
|
response = request(method, endpoint, self.login, self.password, {})
|
256
232
|
|
257
|
-
|
258
|
-
|
259
|
-
invoices = response[:invoices]
|
260
|
-
|
261
|
-
return result, invoices
|
233
|
+
return response[:result], response[:invoices]
|
262
234
|
end
|
263
235
|
|
264
236
|
# This method updates the credit card information associated to the subscription.
|
@@ -279,14 +251,11 @@ module MidasClient
|
|
279
251
|
# }
|
280
252
|
#
|
281
253
|
def update_subscription_card(subscription_token, new_card_token)
|
282
|
-
# inicializa as variáveis de retorno
|
283
|
-
result ={}
|
284
|
-
|
285
254
|
# define o método de envio da requisição
|
286
255
|
method = :put
|
287
256
|
|
288
257
|
# monta a URL de chamada da requisição
|
289
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
258
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:update_card].gsub('{subscriptionToken}', subscription_token)
|
290
259
|
|
291
260
|
params = {
|
292
261
|
cardToken: new_card_token
|
@@ -295,9 +264,7 @@ module MidasClient
|
|
295
264
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
296
265
|
response = request(method, endpoint, self.login, self.password, params)
|
297
266
|
|
298
|
-
|
299
|
-
|
300
|
-
return result
|
267
|
+
response[:result]
|
301
268
|
end
|
302
269
|
|
303
270
|
# This method updates a subscription.
|
@@ -317,21 +284,16 @@ module MidasClient
|
|
317
284
|
# message: "Some message to you"
|
318
285
|
# }
|
319
286
|
def update_invoice(invoice_token, params)
|
320
|
-
# inicializa as variáveis de retorno
|
321
|
-
result ={}
|
322
|
-
|
323
287
|
# define o método de envio da requisição
|
324
288
|
method = :put
|
325
289
|
|
326
290
|
# monta a URL de chamada da requisição
|
327
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
291
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::SUBSCRIPTIONS[:update_invoice].gsub('{invoiceToken}', invoice_token)
|
328
292
|
|
329
293
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
330
294
|
response = request(method, endpoint, self.login, self.password, params)
|
331
295
|
|
332
|
-
|
333
|
-
|
334
|
-
return result
|
296
|
+
response[:result]
|
335
297
|
end
|
336
298
|
|
337
299
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module MidasClient
|
2
|
-
class Transaction <
|
2
|
+
class Transaction < Request
|
3
3
|
|
4
|
-
include
|
4
|
+
include EndPoints
|
5
5
|
|
6
6
|
# This method securely stores credit card's data (pan, expiration...)
|
7
7
|
# and returns a token to be used to perform payment transactions.
|
@@ -39,23 +39,16 @@ module MidasClient
|
|
39
39
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
40
40
|
params = params.first
|
41
41
|
|
42
|
-
# inicializa as variáveis de retorno
|
43
|
-
result ={}
|
44
|
-
card_token = nil
|
45
|
-
|
46
42
|
# define o método de envio da requisição
|
47
43
|
method = :post
|
48
44
|
|
49
45
|
# monta a URL de chamada da requisição
|
50
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
46
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:store]
|
51
47
|
|
52
48
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
53
49
|
response = request(method, endpoint, login, password, params)
|
54
50
|
|
55
|
-
|
56
|
-
card_token = response[:cardToken] if !response[:cardToken].nil?
|
57
|
-
|
58
|
-
return result, card_token
|
51
|
+
return response[:result], response[:cardToken]
|
59
52
|
end
|
60
53
|
|
61
54
|
# This method creates a payment transaction, already performing
|
@@ -83,16 +76,11 @@ module MidasClient
|
|
83
76
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
84
77
|
params = params.first
|
85
78
|
|
86
|
-
# inicializa as variáveis de retorno
|
87
|
-
result ={}
|
88
|
-
nsu = ""
|
89
|
-
transaction_token = ""
|
90
|
-
|
91
79
|
# define o método de envio da requisição
|
92
80
|
method = :post
|
93
81
|
|
94
82
|
# monta a URL de chamada da requisição
|
95
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
83
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:synchronous_transaction]
|
96
84
|
|
97
85
|
# regulariza o formato da data
|
98
86
|
params[:externaldate] = params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate]
|
@@ -100,11 +88,7 @@ module MidasClient
|
|
100
88
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
101
89
|
response = request(method, endpoint, self.login, self.password, params)
|
102
90
|
|
103
|
-
result
|
104
|
-
nsu = response[:nsu] if !response[:nsu].nil?
|
105
|
-
transaction_token = response[:transactionToken] if !response[:transactionToken].nil?
|
106
|
-
|
107
|
-
return result, transaction_token, nsu
|
91
|
+
return response[:result], response[:transactionToken], response[:nsu]
|
108
92
|
end
|
109
93
|
|
110
94
|
# This method dispatches a payment transaction creation request, already performing
|
@@ -134,15 +118,11 @@ module MidasClient
|
|
134
118
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
135
119
|
params = params.first
|
136
120
|
|
137
|
-
# inicializa as variáveis de retorno
|
138
|
-
result ={}
|
139
|
-
transaction_token = ""
|
140
|
-
|
141
121
|
# define o método de envio da requisição
|
142
122
|
method = :post
|
143
123
|
|
144
124
|
# monta a URL de chamada da requisição
|
145
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
125
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:asynchronous_transaction]
|
146
126
|
|
147
127
|
# regulariza o formato da data
|
148
128
|
params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])
|
@@ -150,10 +130,7 @@ module MidasClient
|
|
150
130
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
151
131
|
response = request(method, endpoint, self.login, self.password, params)
|
152
132
|
|
153
|
-
|
154
|
-
transaction_token = response[:transactionToken] if !response[:transactionToken].nil?
|
155
|
-
|
156
|
-
return result, transaction_token
|
133
|
+
return response[:result], response[:transactionToken]
|
157
134
|
end
|
158
135
|
|
159
136
|
# This method dispatches a debit payment transaction request, that's receive an authorization URL,
|
@@ -188,15 +165,11 @@ module MidasClient
|
|
188
165
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
189
166
|
params = params.first
|
190
167
|
|
191
|
-
# inicializa as variáveis de retorno
|
192
|
-
result ={}
|
193
|
-
transaction_token = ""
|
194
|
-
|
195
168
|
# define o método de envio da requisição
|
196
169
|
method = :post
|
197
170
|
|
198
171
|
# monta a URL de chamada da requisição
|
199
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
172
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:asynchronous_debit_transaction]
|
200
173
|
|
201
174
|
# regulariza formato da data
|
202
175
|
params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])
|
@@ -204,11 +177,7 @@ module MidasClient
|
|
204
177
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
205
178
|
response = request(method, endpoint, self.login, self.password, params)
|
206
179
|
|
207
|
-
result
|
208
|
-
authentication_url = response[:authenticationUrl] unless response[:authenticationUrl].nil?
|
209
|
-
transaction_token = response[:transactionToken] unless response[:transactionToken].nil?
|
210
|
-
|
211
|
-
return result, authentication_url, transaction_token
|
180
|
+
return response[:result], response[:authenticationUrl], response[:transactionToken]
|
212
181
|
end
|
213
182
|
|
214
183
|
# This method performs a payment authorization. This is a is synchronous operation.
|
@@ -245,15 +214,11 @@ module MidasClient
|
|
245
214
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
246
215
|
params = params.first
|
247
216
|
|
248
|
-
# inicializa as variáveis de retorno
|
249
|
-
result ={}
|
250
|
-
transaction_token = ""
|
251
|
-
|
252
217
|
# define o método de envio da requisição
|
253
218
|
method = :post
|
254
219
|
|
255
220
|
# monta a URL de chamada da requisição
|
256
|
-
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
221
|
+
endpoint= EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:authorize]
|
257
222
|
|
258
223
|
# regulariza o formato da data
|
259
224
|
params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])
|
@@ -261,11 +226,7 @@ module MidasClient
|
|
261
226
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
262
227
|
response = request(method, endpoint, self.login, self.password, params)
|
263
228
|
|
264
|
-
|
265
|
-
nsu = response[:nsu] if !response[:nsu].nil?
|
266
|
-
transaction_token = response[:transactionToken] if !response[:transactionToken].nil?
|
267
|
-
|
268
|
-
return result, transaction_token
|
229
|
+
return response[:result], response[:transactionToken]
|
269
230
|
end
|
270
231
|
|
271
232
|
# This method performs a capture (confirmation) in a already authorized transaction.
|
@@ -282,21 +243,16 @@ module MidasClient
|
|
282
243
|
# message: "Some message to you"
|
283
244
|
# }
|
284
245
|
def capture(transaction_token)
|
285
|
-
# inicializa as variáveis de retorno
|
286
|
-
result ={}
|
287
|
-
|
288
246
|
# define o método de envio da requisição
|
289
247
|
method = :put
|
290
248
|
|
291
249
|
# monta a URL de chamada da requisição
|
292
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
250
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:confirm].gsub('{transactionToken}', transaction_token)
|
293
251
|
|
294
252
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
295
253
|
response = self.request(method, endpoint, self.login, self.password, {})
|
296
254
|
|
297
|
-
|
298
|
-
|
299
|
-
return result
|
255
|
+
response[:result]
|
300
256
|
end
|
301
257
|
|
302
258
|
# This method performs a cancellation in a already authorized transaction.
|
@@ -313,20 +269,16 @@ module MidasClient
|
|
313
269
|
# message: "Some message to you"
|
314
270
|
# }
|
315
271
|
def cancellation(transaction_token)
|
316
|
-
# inicializa as variáveis de retorno
|
317
|
-
result ={}
|
318
|
-
|
319
272
|
# define o método de envio da requisição
|
320
273
|
method = :put
|
321
274
|
|
322
275
|
# monta a URL de chamada da requisição
|
323
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
276
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:cancel].gsub('{transactionToken}', transaction_token)
|
324
277
|
|
325
278
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
326
279
|
response = self.request(method, endpoint, self.login, self.password, {})
|
327
|
-
result = response[:result]
|
328
280
|
|
329
|
-
|
281
|
+
response[:result]
|
330
282
|
end
|
331
283
|
|
332
284
|
# This method performs a refund in a captured authorized transaction.
|
@@ -344,21 +296,16 @@ module MidasClient
|
|
344
296
|
# message: "Some message to you"
|
345
297
|
# }
|
346
298
|
def refund(transaction_token)
|
347
|
-
# inicializa as variáveis de retorno
|
348
|
-
result ={}
|
349
|
-
|
350
299
|
# define o método de envio da requisição
|
351
300
|
method = :put
|
352
301
|
|
353
302
|
# monta a URL de chamada da requisição
|
354
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
303
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:refund].gsub('{transactionToken}', transaction_token)
|
355
304
|
|
356
305
|
# faz a chamada a plataforma de pagamento (MIDAS)
|
357
306
|
response = request(method, endpoint, self.login, self.password, {})
|
358
307
|
|
359
|
-
|
360
|
-
|
361
|
-
return result
|
308
|
+
response[:result]
|
362
309
|
end
|
363
310
|
|
364
311
|
# This method performs a query by a specific transaction.
|
@@ -376,20 +323,15 @@ module MidasClient
|
|
376
323
|
# message: "Some message to you"
|
377
324
|
# }
|
378
325
|
def query_transaction(transaction_token)
|
379
|
-
# inicializa as variáveis de retorno
|
380
|
-
result ={}
|
381
|
-
|
382
326
|
# define o método de envio da requisição
|
383
327
|
method = :get
|
384
328
|
|
385
329
|
# monta a URL de chamada da requisição
|
386
|
-
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::
|
330
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::OPERATIONS[:query_by_transaction].gsub('{transactionToken}', transaction_token)
|
387
331
|
|
388
332
|
response = request(method, endpoint, login, password, params)
|
389
333
|
|
390
|
-
|
391
|
-
|
392
|
-
return result
|
334
|
+
response[:result]
|
393
335
|
end
|
394
336
|
|
395
337
|
end
|
data/lib/midas_client/util.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
-
require 'credit_card_sanitizer'
|
2
|
-
|
3
1
|
module MidasClient
|
4
2
|
module Util
|
3
|
+
|
4
|
+
def logger(progname = '[MIDAS_CLIENT]')
|
5
|
+
@logger ||= Logger.new($stdout).tap do |log|
|
6
|
+
log.progname = progname
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
5
10
|
def log(text)
|
6
|
-
|
11
|
+
logger.level = Logger::INFO
|
12
|
+
logger.info "#{text}"
|
7
13
|
end
|
8
14
|
|
9
15
|
def error_log(text)
|
10
|
-
|
16
|
+
logger.level = Logger::ERROR
|
17
|
+
logger.error "#{text}"
|
11
18
|
end
|
12
19
|
|
13
20
|
def sanitize_pci(text)
|
data/lib/midas_client/version.rb
CHANGED
data/midas_client.gemspec
CHANGED
@@ -29,10 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.bindir = "exe"
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
|
-
spec.require_paths = ["config"]
|
33
|
-
spec.require_paths = ["config/initializers"]
|
34
|
-
spec.require_paths = ["config/settings"]
|
35
|
-
|
36
32
|
|
37
33
|
spec.add_development_dependency "bundler", "~> 1.14"
|
38
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
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.1.
|
4
|
+
version: 0.1.3
|
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-05-
|
11
|
+
date: 2017-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,13 +96,9 @@ files:
|
|
96
96
|
- LICENSE.txt
|
97
97
|
- README.md
|
98
98
|
- Rakefile
|
99
|
-
- config/settings.yml
|
100
|
-
- config/settings/development.yml
|
101
|
-
- config/settings/production.yml
|
102
|
-
- config/settings/test.yml
|
103
99
|
- lib/midas_client.rb
|
104
100
|
- lib/midas_client/endpoints.rb
|
105
|
-
- lib/midas_client/
|
101
|
+
- lib/midas_client/query.rb
|
106
102
|
- lib/midas_client/request.rb
|
107
103
|
- lib/midas_client/subscription.rb
|
108
104
|
- lib/midas_client/transaction.rb
|
@@ -117,7 +113,7 @@ metadata:
|
|
117
113
|
post_install_message:
|
118
114
|
rdoc_options: []
|
119
115
|
require_paths:
|
120
|
-
-
|
116
|
+
- lib
|
121
117
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
118
|
requirements:
|
123
119
|
- - ">="
|
data/config/settings.yml
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
default: &default
|
2
|
-
operations:
|
3
|
-
context: "/midas-core/v2"
|
4
|
-
store: "/creditcard"
|
5
|
-
synchronous_transaction: "/transaction/creditcard"
|
6
|
-
asynchronous_transaction: "/transaction/creditcard/dispatch"
|
7
|
-
authorize: "/transaction/creditcard/authorize"
|
8
|
-
confirm: "/transaction/creditcard/{transactionToken}/capture"
|
9
|
-
cancel: "/transaction/creditcard/{transactionToken}/cancel"
|
10
|
-
refund: "/transaction/creditcard/{transactionToken}/refund"
|
11
|
-
query_by_transaction: "/transaction/{transactionToken}"
|
12
|
-
callback: "http://matricula.crossfitlendarios.com.br/callback"
|
13
|
-
subscriptions:
|
14
|
-
context: "/midas-core/v2"
|
15
|
-
by_token: "/subscription/{subscriptionToken}"
|
16
|
-
invoices: "/subscription/{subscriptionToken}/invoices"
|
17
|
-
invoice_transactions: "/invoice/{invoiceToken}/transactions"
|
18
|
-
create: "/subscription/creditcard"
|
19
|
-
cancel: "/subscription/{subscriptionToken}/cancel"
|
20
|
-
callback: "https://matricula.crossfitlendarios.com.br/callback"
|
21
|
-
queries:
|
22
|
-
context: "/midas-query/v2"
|
23
|
-
by_period: "/transactions"
|
24
|
-
subscriptions: "/subscriptions"
|
@@ -1,31 +0,0 @@
|
|
1
|
-
config:
|
2
|
-
multiple_cards: false
|
3
|
-
delete_cards: false
|
4
|
-
cache_key: '%Y-%m-%d-%H:%M'
|
5
|
-
midas:
|
6
|
-
pos: "pdv01"
|
7
|
-
password: "/eFRsg8RLne+I0GlECQofYvnsDfb0w=="
|
8
|
-
url: "https://sandbox.ansertecnologia.net"
|
9
|
-
operations:
|
10
|
-
context: "/midas-core/v2"
|
11
|
-
store: "/creditcard"
|
12
|
-
synchronous_transaction: "/transaction/creditcard"
|
13
|
-
asynchronous_transaction: "/transaction/creditcard/dispatch"
|
14
|
-
authorize: "/transaction/creditcard/authorize"
|
15
|
-
confirm: "/transaction/creditcard/{transactionToken}/capture"
|
16
|
-
cancel: "/transaction/creditcard/{transactionToken}/cancel"
|
17
|
-
refund: "/transaction/creditcard/{transactionToken}/refund"
|
18
|
-
query_by_transaction: "/transaction/{transactionToken}"
|
19
|
-
callback: "http://matricula.crossfitlendarios.com.br/callback"
|
20
|
-
subscriptions:
|
21
|
-
context: "/midas-core/v2"
|
22
|
-
by_token: "/subscription/{subscriptionToken}"
|
23
|
-
invoices: "/subscription/{subscriptionToken}/invoices"
|
24
|
-
invoice_transactions: "/invoice/{invoiceToken}/transactions"
|
25
|
-
create: "/subscription/creditcard"
|
26
|
-
cancel: "/subscription/{subscriptionToken}/cancel"
|
27
|
-
callback: "https://matricula.crossfitlendarios.com.br/callback"
|
28
|
-
queries:
|
29
|
-
context: "/midas-query/v2"
|
30
|
-
by_period: "/transactions"
|
31
|
-
subscriptions: "/subscriptions"
|
@@ -1,31 +0,0 @@
|
|
1
|
-
config:
|
2
|
-
multiple_cards: false
|
3
|
-
delete_cards: false
|
4
|
-
cache_key: '%Y-%m-%d'
|
5
|
-
midas:
|
6
|
-
pos: "lendarios-01"
|
7
|
-
password: "b0FIYhr/xCvGFMuR1Wg059X/0cqwLg=="
|
8
|
-
url: "https://api.ansertecnologia.net"
|
9
|
-
operations:
|
10
|
-
context: "/midas-core/v2"
|
11
|
-
store: "/creditcard"
|
12
|
-
synchronous_transaction: "/transaction/creditcard"
|
13
|
-
asynchronous_transaction: "/transaction/creditcard/dispatch"
|
14
|
-
authorize: "/transaction/creditcard/authorize"
|
15
|
-
confirm: "/transaction/creditcard/{transactionToken}/capture"
|
16
|
-
cancel: "/transaction/creditcard/{transactionToken}/cancel"
|
17
|
-
refund: "/transaction/creditcard/{transactionToken}/refund"
|
18
|
-
query_by_transaction: "/transaction/{transactionToken}"
|
19
|
-
callback: "http://matricula.crossfitlendarios.com.br/callback"
|
20
|
-
subscriptions:
|
21
|
-
context: "/midas-core/v2"
|
22
|
-
by_token: "/subscription/{subscriptionToken}"
|
23
|
-
invoices: "/subscription/{subscriptionToken}/invoices"
|
24
|
-
invoice_transactions: "/invoice/{invoiceToken}/transactions"
|
25
|
-
create: "/subscription/creditcard"
|
26
|
-
cancel: "/subscription/{subscriptionToken}/cancel"
|
27
|
-
callback: "https://matricula.crossfitlendarios.com.br/callback"
|
28
|
-
queries:
|
29
|
-
context: "/midas-query/v2"
|
30
|
-
by_period: "/transactions"
|
31
|
-
subscriptions: "/subscriptions"
|
data/config/settings/test.yml
DELETED
File without changes
|