midas_client 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.md +46 -7
- data/lib/midas_client/endpoints.rb +2 -0
- data/lib/midas_client/request.rb +29 -2
- data/lib/midas_client/subscription.rb +81 -7
- data/lib/midas_client/transaction.rb +7 -7
- data/lib/midas_client/version.rb +1 -1
- data/midas_client.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a4f57492b987fffb937d687bcdc0ade724851da
|
4
|
+
data.tar.gz: 8f1a729b4e0334d809d364338105b2a6851945f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8915525bb5125947e623b556d90df1edc951da4a49e403e9e03013bbf61f8ede29dc69fbeaddcf1299d2ce96ea84f22f5dd05225d3182522d4f82be4150665d
|
7
|
+
data.tar.gz: 049b8450361d6d715ea04403a00087505b22d4eab17fc6aa510e50850490029980b5138759704262cc6d2de41998187634d48a2a60a7e4255a9fcfc2e0b10d95
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# MidasClient
|
2
|
-
Midas Client its a Ruby GEM that's allow user to send requests
|
2
|
+
Midas Client its a Ruby GEM that's allow user to send requests to Anser Payment API
|
3
3
|
|
4
|
-
|
4
|
+
https://ansertecnologia.atlassian.net/wiki/x/EYCyAg
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
|
@@ -20,6 +20,16 @@ Or install it yourself as:
|
|
20
20
|
$ gem install midas_client
|
21
21
|
|
22
22
|
## Usage
|
23
|
+
Credentials for Sandbox:
|
24
|
+
|
25
|
+
- user: pdv01
|
26
|
+
- password: /eFRsg8RLne+I0GlECQofYvnsDfb0w==
|
27
|
+
|
28
|
+
For details go to API Documentation
|
29
|
+
[https://ansertecnologia.atlassian.net/wiki/x/EYCyAg]
|
30
|
+
or visit Anser Gateway site at [https://ansertenologia.com]
|
31
|
+
|
32
|
+
Use client as follow:
|
23
33
|
|
24
34
|
Request
|
25
35
|
|
@@ -31,11 +41,40 @@ Response
|
|
31
41
|
$ [MIDAS_CLIENT][CALLER:request][17/05/2017 20:48:05.087]METHOD: post URL: https://sandbox.ansertecnologia.net/midas-core/v2/creditcard login: pdv01 password: /eFRsg8RLne+I0GlECQofYvnsDfb0w== payload: {:externalId=>"teste_midas_client_00002", :pan=>"552952@@@@@@4124", :expirationMonth=>"01", :expirationYear=>"2021", :holderName=>"TESTE MIDAS CLIENT", :customer=>{:documentType=>"CPF", :documentNumber=>"36549450152"}}
|
32
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"}
|
33
43
|
|
34
|
-
##
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
44
|
+
## Change Releases
|
45
|
+
VERSION - 0.1.2 - 2017/05/19
|
46
|
+
|
47
|
+
Operations available: Subscriptions
|
48
|
+
- Update Subscription
|
49
|
+
- Update Invoice
|
50
|
+
- bugfix
|
51
|
+
- read.me
|
52
|
+
|
53
|
+
VERSION - 0.1.1 - 2017/05/16
|
54
|
+
|
55
|
+
Operations available: Subscriptions
|
56
|
+
- Implementing logging features
|
57
|
+
- bugfix
|
58
|
+
|
59
|
+
VERSION - 0.1.0 - 2017/05/15
|
60
|
+
|
61
|
+
Operations available: Transactions
|
62
|
+
- Creditcard Store (tokenization)
|
63
|
+
- Synchronous Transaction (Authorize + Capture)
|
64
|
+
- Asynchronous Transaction (Authorize + Capture)
|
65
|
+
- Asynchronous Debit Transaction
|
66
|
+
- Authorize (synchronous)
|
67
|
+
- Capture
|
68
|
+
- Cancellation
|
69
|
+
- Refund
|
70
|
+
- Query Transaction
|
71
|
+
|
72
|
+
Operations available: Subscriptions
|
73
|
+
- Create Subscription
|
74
|
+
- Cancel Subscription
|
75
|
+
- Subscription by Token
|
76
|
+
- List Subscription's Invoices
|
77
|
+
- Update Subscription Card
|
39
78
|
|
40
79
|
## Contributing
|
41
80
|
|
@@ -33,6 +33,8 @@ module MidasClient
|
|
33
33
|
invoice_transactions: "/invoice/{invoiceToken}/transactions",
|
34
34
|
create: "/subscription/creditcard",
|
35
35
|
cancel: "/subscription/{subscriptionToken}/cancel",
|
36
|
+
update: "/subscription/{subscriptionToken}",
|
37
|
+
update_invoice: "/invoice/{invoiceToken}",
|
36
38
|
callback: "https://matricula.crossfitlendarios.com.br/callback"
|
37
39
|
}
|
38
40
|
|
data/lib/midas_client/request.rb
CHANGED
@@ -11,7 +11,6 @@ module MidasClient
|
|
11
11
|
log("POS #{login} INITIALIZED!")
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
14
|
# Method that's wrap generic response
|
16
15
|
def base_result(success, code, message)
|
17
16
|
{
|
@@ -21,7 +20,6 @@ module MidasClient
|
|
21
20
|
message: "#{message}"
|
22
21
|
}
|
23
22
|
}.to_hash
|
24
|
-
|
25
23
|
end
|
26
24
|
|
27
25
|
# Method that's wrap rest-client generic request
|
@@ -56,5 +54,34 @@ module MidasClient
|
|
56
54
|
end
|
57
55
|
response
|
58
56
|
end
|
57
|
+
|
58
|
+
# Method to call any other
|
59
|
+
def external_request(method, endpoint, parameters={}, headers={content_type: :json, accept: :json})
|
60
|
+
# inicia a contagem da execução
|
61
|
+
start_time_execution = Time.now
|
62
|
+
|
63
|
+
log "[EXTERNAL][REQUEST][#{method}] URL: #{endpoint} payload: #{sanitize_pci(parameters)}"
|
64
|
+
begin
|
65
|
+
response = RestClient::Request.execute(method: method,
|
66
|
+
url: endpoint,
|
67
|
+
payload: (parameters.to_json unless parameters.nil?),
|
68
|
+
headers: headers)
|
69
|
+
rescue => e
|
70
|
+
response = e.response || e
|
71
|
+
end
|
72
|
+
|
73
|
+
# parsing da resposta
|
74
|
+
begin
|
75
|
+
response = JSON.parse(response, symbolize_names: true )
|
76
|
+
rescue => e
|
77
|
+
error_log "[EXTERNAL][REQUEST]METHOD: #{method} URL: #{endpoint} Mensagem: #{e.to_s}"
|
78
|
+
response = base_result(false, "999", "Operação não concluída. Motivo: #{e.to_s}")
|
79
|
+
ensure
|
80
|
+
total_time_execution = Time.now - start_time_execution
|
81
|
+
log "[EXTERNAL][RESPONSE][#{method}] URL: #{endpoint} TEMPO: #{total_time_execution}s RESULT: #{self.sanitize_pci(response)}"
|
82
|
+
end
|
83
|
+
response
|
84
|
+
end
|
85
|
+
|
59
86
|
end
|
60
87
|
end
|
@@ -55,7 +55,7 @@ module MidasClient
|
|
55
55
|
# }
|
56
56
|
#}
|
57
57
|
#
|
58
|
-
def
|
58
|
+
def create_subscription(*params)
|
59
59
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
60
60
|
params = params.first
|
61
61
|
|
@@ -101,7 +101,7 @@ module MidasClient
|
|
101
101
|
# code: "XXX"
|
102
102
|
# message: "Some message to you"
|
103
103
|
# }
|
104
|
-
def
|
104
|
+
def cancel_subscription(subscription_token)
|
105
105
|
# inicializa as variáveis de retorno
|
106
106
|
result ={}
|
107
107
|
|
@@ -119,6 +119,48 @@ module MidasClient
|
|
119
119
|
return result
|
120
120
|
end
|
121
121
|
|
122
|
+
# This method updates a subscription callback, amount and updates opened invoices' amount.
|
123
|
+
# This is a is synchronous operation.
|
124
|
+
#
|
125
|
+
# Params:
|
126
|
+
# subscriptionToken: querystring (Subscription unique identification generated by our
|
127
|
+
# gateway and received in the subscription's creation response)
|
128
|
+
# amount: number (Only integer numbers, with the last two digits representing the cents.
|
129
|
+
# For example: 100 is equivalent to R$ 1,00)
|
130
|
+
# callbackUrl string - URL to receive the result for each invoice charge
|
131
|
+
#
|
132
|
+
# Response:
|
133
|
+
# result: {
|
134
|
+
# success: true/false
|
135
|
+
# code: "XXX"
|
136
|
+
# message: "Some message to you"
|
137
|
+
# }
|
138
|
+
def update_subscription(subscription_token, params)
|
139
|
+
# define o método de envio da requisição
|
140
|
+
method = :put
|
141
|
+
|
142
|
+
# monta a URL de chamada da requisição
|
143
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Subscriptions[:update].gsub("{subscriptionToken}", subscription_token)
|
144
|
+
|
145
|
+
# faz a chamada a plataforma de pagamento (MIDAS) para atualizar o valor de face e callback da assinatura
|
146
|
+
response = request(method, endpoint, self.login, self.password, params)
|
147
|
+
|
148
|
+
# recupera a lista de invoices da assinatura para chamar o método de atualização de cada invoice.
|
149
|
+
invoices = subscription_invoices(subscription_token)
|
150
|
+
|
151
|
+
# filtra apenas as invoices em aberto
|
152
|
+
opened_invoices = invoices[:invoices].select{|s| s[:status] == "OPEN"}
|
153
|
+
|
154
|
+
# percorre cada uma das invoices abertas e chama o método de atualização
|
155
|
+
opened_invoices.each do |inv|
|
156
|
+
update_invoice(inv[:token], {amount: params[:amount]})
|
157
|
+
end
|
158
|
+
|
159
|
+
result = response[:result]
|
160
|
+
|
161
|
+
return result
|
162
|
+
end
|
163
|
+
|
122
164
|
# This method performs a query by a specific transaction.
|
123
165
|
# This is a is synchronous operation, using method GET
|
124
166
|
#
|
@@ -157,7 +199,7 @@ module MidasClient
|
|
157
199
|
# :status=>"CANCELLED"
|
158
200
|
# }
|
159
201
|
# }
|
160
|
-
def
|
202
|
+
def subscription_by_token(subscription_token)
|
161
203
|
# inicializa as variáveis de retorno
|
162
204
|
result ={}
|
163
205
|
|
@@ -175,7 +217,6 @@ module MidasClient
|
|
175
217
|
return result, response[:subscription]
|
176
218
|
end
|
177
219
|
|
178
|
-
|
179
220
|
# This method performs a query by a specific transaction.
|
180
221
|
# This is a is synchronous operation, using method GET
|
181
222
|
#
|
@@ -200,7 +241,7 @@ module MidasClient
|
|
200
241
|
# :status=>"PAID"
|
201
242
|
# }. {:number=>2,...}, {:number=>3,}]
|
202
243
|
# }
|
203
|
-
def
|
244
|
+
def subscription_invoices(subscription_token)
|
204
245
|
# inicializa as variáveis de retorno
|
205
246
|
result ={}
|
206
247
|
|
@@ -220,7 +261,6 @@ module MidasClient
|
|
220
261
|
return result, invoices
|
221
262
|
end
|
222
263
|
|
223
|
-
|
224
264
|
# This method updates the credit card information associated to the subscription.
|
225
265
|
# This is a is synchronous operation, using method PUT
|
226
266
|
#
|
@@ -238,7 +278,7 @@ module MidasClient
|
|
238
278
|
# }
|
239
279
|
# }
|
240
280
|
#
|
241
|
-
def
|
281
|
+
def update_subscription_card(subscription_token, new_card_token)
|
242
282
|
# inicializa as variáveis de retorno
|
243
283
|
result ={}
|
244
284
|
|
@@ -260,6 +300,40 @@ module MidasClient
|
|
260
300
|
return result
|
261
301
|
end
|
262
302
|
|
303
|
+
# This method updates a subscription.
|
304
|
+
# This is a is synchronous operation.
|
305
|
+
#
|
306
|
+
# Params:
|
307
|
+
# subscriptionToken: querystring (Subscription unique identification generated by our
|
308
|
+
# gateway and received in the subscription's creation response)
|
309
|
+
# amount: number (Only integer numbers, with the last two digits representing the cents.
|
310
|
+
# For example: 100 is equivalent to R$ 1,00)
|
311
|
+
# expirationDate string deadline date for the invoice. FORMAT: YYY-MM-DD
|
312
|
+
#
|
313
|
+
# Response:
|
314
|
+
# result: {
|
315
|
+
# success: true/false
|
316
|
+
# code: "XXX"
|
317
|
+
# message: "Some message to you"
|
318
|
+
# }
|
319
|
+
def update_invoice(invoice_token, params)
|
320
|
+
# inicializa as variáveis de retorno
|
321
|
+
result ={}
|
322
|
+
|
323
|
+
# define o método de envio da requisição
|
324
|
+
method = :put
|
325
|
+
|
326
|
+
# monta a URL de chamada da requisição
|
327
|
+
endpoint = EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Subscriptions[:update_invoice].gsub("{invoiceToken}", invoice_token)
|
328
|
+
|
329
|
+
# faz a chamada a plataforma de pagamento (MIDAS)
|
330
|
+
response = request(method, endpoint, self.login, self.password, params)
|
331
|
+
|
332
|
+
result = response[:result]
|
333
|
+
|
334
|
+
return result
|
335
|
+
end
|
336
|
+
|
263
337
|
end
|
264
338
|
|
265
339
|
end
|
@@ -130,7 +130,7 @@ module MidasClient
|
|
130
130
|
# },
|
131
131
|
# transactionToken: "65ffe2897b832cb89cb2063b74fbb143",
|
132
132
|
#
|
133
|
-
def
|
133
|
+
def asynchronous_transaction(*params)
|
134
134
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
135
135
|
params = params.first
|
136
136
|
|
@@ -184,7 +184,7 @@ module MidasClient
|
|
184
184
|
# "authenticationUrl": "https://qasecommerce.cielo.com.br/web/index.cbmp?id=ac470d041f660e21d253a5741e59c5b4",
|
185
185
|
# "transactionToken":"6accbedb2da4f7bfbca5b5fed3669be6",
|
186
186
|
#
|
187
|
-
def
|
187
|
+
def asynchronous_debit_transaction(*params)
|
188
188
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
189
189
|
params = params.first
|
190
190
|
|
@@ -241,7 +241,7 @@ module MidasClient
|
|
241
241
|
# }
|
242
242
|
# }
|
243
243
|
#
|
244
|
-
def
|
244
|
+
def authorize(*params)
|
245
245
|
# Parametros são recebidos como um array de hash, pego o 1o item do array
|
246
246
|
params = params.first
|
247
247
|
|
@@ -281,7 +281,7 @@ module MidasClient
|
|
281
281
|
# code: "XXX"
|
282
282
|
# message: "Some message to you"
|
283
283
|
# }
|
284
|
-
def
|
284
|
+
def capture(transaction_token)
|
285
285
|
# inicializa as variáveis de retorno
|
286
286
|
result ={}
|
287
287
|
|
@@ -312,7 +312,7 @@ module MidasClient
|
|
312
312
|
# code: "XXX"
|
313
313
|
# message: "Some message to you"
|
314
314
|
# }
|
315
|
-
def
|
315
|
+
def cancellation(transaction_token)
|
316
316
|
# inicializa as variáveis de retorno
|
317
317
|
result ={}
|
318
318
|
|
@@ -343,7 +343,7 @@ module MidasClient
|
|
343
343
|
# code: "XXX"
|
344
344
|
# message: "Some message to you"
|
345
345
|
# }
|
346
|
-
def
|
346
|
+
def refund(transaction_token)
|
347
347
|
# inicializa as variáveis de retorno
|
348
348
|
result ={}
|
349
349
|
|
@@ -375,7 +375,7 @@ module MidasClient
|
|
375
375
|
# code: "XXX"
|
376
376
|
# message: "Some message to you"
|
377
377
|
# }
|
378
|
-
def
|
378
|
+
def query_transaction(transaction_token)
|
379
379
|
# inicializa as variáveis de retorno
|
380
380
|
result ={}
|
381
381
|
|
data/lib/midas_client/version.rb
CHANGED
data/midas_client.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Carlos Andre Oliveira"]
|
10
10
|
spec.email = ["coliveira@ansertecnologia.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Midas Client REST API}
|
12
|
+
spec.summary = %q{Midas Client REST API - https://ansertecnologia.com}
|
13
13
|
spec.description = %q{Client to Midas REST API https://ansertecnologia.atlassian.net/wiki/display/DOC/Desenvolvedor}
|
14
14
|
spec.homepage = "https://bitbucket.org/ansertecnologia/midas_client.git"
|
15
15
|
spec.license = "MIT"
|
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.2
|
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-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,5 +133,5 @@ rubyforge_project:
|
|
133
133
|
rubygems_version: 2.5.1
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
|
-
summary: Midas Client REST API
|
136
|
+
summary: Midas Client REST API - https://ansertecnologia.com
|
137
137
|
test_files: []
|