Class: MidasClient::Transaction

Inherits:
Request
  • Object
show all
Includes:
EndPoints
Defined in:
lib/midas_client/transaction.rb

Constant Summary

Constants included from EndPoints

EndPoints::Development, EndPoints::Operations, EndPoints::Production, EndPoints::Queries, EndPoints::Subscriptions

Instance Attribute Summary

Attributes inherited from Request

#login, #password

Instance Method Summary collapse

Methods included from EndPoints

get_env

Methods inherited from Request

#base_result, #external_request, #initialize, #request

Methods included from Util

#error_log, #log, #sanitize_pci

Constructor Details

This class inherits a constructor from MidasClient::Request

Instance Method Details

#asynchronous_debit_transaction(*params) ⇒ Object

This method dispatches a debit payment transaction request, that’s receive an authorization URL, where the payer must authorize the transaction.

Params:

externalId: string (Transaction identification on the client application)
externalDate: Date and time form client application - YYYY-MM-DDThh:mm:SS.sssTDZ - ISO8601
pan: DebitCard Number
expirationMonth:
expirationYear:
holderName:
customer/documentType: CPF/CNPJ
customer/documentNumber: if CPF 11 digits else CNPJ 13 digits
cvv: number (Security Code)
amount: number (Only integer numbers, with the last two digits representing the cents.
                For example: 100 is equivalent to R$ 1,00)
callbackUrl: string (URL used to notify the client application about the transaction authorization result. async notification )
redirectUrl: string (URL used to notify the client application that the transaction authorization result successful. )
errorUrl: string (URL used to notify the client application that the transaction authorization result failed)

# Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
},
"authenticationUrl": "https://qasecommerce.cielo.com.br/web/index.cbmp?id=ac470d041f660e21d253a5741e59c5b4",
"transactionToken":"6accbedb2da4f7bfbca5b5fed3669be6",


187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/midas_client/transaction.rb', line 187

def asynchronous_debit_transaction(*params)
  # Parametros são recebidos como um array de hash, pego o 1o item do array
  params = params.first

  # inicializa as variáveis de retorno
  result ={}
  transaction_token = ""

  # define o método de envio da requisição
  method = :post

  # monta a URL de chamada da requisição
  endpoint=  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:asynchronous_debit_transaction]

  # regulariza formato da data
  params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, self., self.password, params)

  result = response[:result]
  authentication_url = response[:authenticationUrl] unless response[:authenticationUrl].nil?
  transaction_token = response[:transactionToken] unless response[:transactionToken].nil?

  return result, authentication_url, transaction_token
end

#asynchronous_transaction(*params) ⇒ Object

This method dispatches a payment transaction creation request, already performing the authorization and capture in only one step, but sending the response using the informed callback URL, in an asynchronous away.

Params:

externalId: string (Transaction identification on the client application)
externalDate: Date and time form client application - YYYY-MM-DDThh:mm:SS.sssTDZ - ISO8601
cardToken: string (created by method card_store)
cvv: number (Security Code)
softDescriptor: string (Text to be shown on the credit card invoice entry)
amount: number (Only integer numbers, with the last two digits representing the cents.
                For example: 100 is equivalent to R$ 1,00)
instalments: number (1 to 12)
callbackUrl: string (URL used to notify the client application about the transaction creation result. )

# Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
},
transactionToken: "65ffe2897b832cb89cb2063b74fbb143",


133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/midas_client/transaction.rb', line 133

def asynchronous_transaction(*params)
  # Parametros são recebidos como um array de hash, pego o 1o item do array
  params = params.first

  # inicializa as variáveis de retorno
  result ={}
  transaction_token = ""

  # define o método de envio da requisição
  method = :post

  # monta a URL de chamada da requisição
  endpoint=  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:asynchronous_transaction]

  # regulariza o formato da data
  params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, self., self.password, params)

  result = response[:result]
  transaction_token = response[:transactionToken] if !response[:transactionToken].nil?

  return result, transaction_token
end

#authorize(*params) ⇒ Object

This method performs a payment authorization. This is a is synchronous operation. To confirm the payment and finish the transaction you must send a capture request

Params:

externalId: string (Transaction identification on the client application)
externalDate: Date and time form client application - YYYY-MM-DDThh:mm:SS.sssTDZ - ISO8601
cardToken: string (created by method card_store)
cvv: number (Security Code)
amount: number (Only integer numbers, with the last two digits representing the cents.
                For example: 100 is equivalent to R$ 1,00)
instalments: number (1 to 12)

Response: {

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}

}

Response Failure {

:result=>{
  :success=>false,
  :code=>"150",
  :message=>"A data externa é obrigatória"
}

}



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/midas_client/transaction.rb', line 244

def authorize(*params)
  # Parametros são recebidos como um array de hash, pego o 1o item do array
  params = params.first

  # inicializa as variáveis de retorno
  result ={}
  transaction_token = ""

  # define o método de envio da requisição
  method = :post

  # monta a URL de chamada da requisição
  endpoint=  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:authorize]

  # regulariza o formato da data
  params[:externalDate] = (params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate])

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, self., self.password, params)

  result = response[:result]
  nsu = response[:nsu] if !response[:nsu].nil?
  transaction_token = response[:transactionToken] if !response[:transactionToken].nil?

  return result, transaction_token
end

#cancellation(transaction_token) ⇒ Object

This method performs a cancellation in a already authorized transaction. This is a is synchronous operation.

Params:

transactionToken: string (Transaction unique identification generated by our
                          gateway and received in the transaction authorization response)

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}


315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/midas_client/transaction.rb', line 315

def cancellation(transaction_token)
  # inicializa as variáveis de retorno
  result ={}

  # define o método de envio da requisição
  method = :put

  # monta a URL de chamada da requisição
  endpoint =  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:cancel].gsub("{transactionToken}", transaction_token)

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = self.request(method, endpoint, self., self.password, {})
  result = response[:result]

  return result
end

#capture(transaction_token) ⇒ Object

This method performs a capture (confirmation) in a already authorized transaction. This is a is synchronous operation.

Params:

transactionToken: string (Transaction unique identification generated by our
                          gateway and received in the transaction authorization response)

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}


284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/midas_client/transaction.rb', line 284

def capture(transaction_token)
  # inicializa as variáveis de retorno
  result ={}

  # define o método de envio da requisição
  method = :put

  # monta a URL de chamada da requisição
  endpoint =  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:confirm].gsub("{transactionToken}", transaction_token)

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = self.request(method, endpoint, self., self.password, {})

  result = response[:result]

  return result
end

#card_store(*params) ⇒ Object

This method securely stores credit card’s data (pan, expiration…) and returns a token to be used to perform payment transactions.

Params:

externalId: number (Transaction identification on the client application)
pan: number
expirationMonth: number (format: MM)
expirationYear: number (format: YYYY)
holderName: string
customer/documentType: string (values: {'CPF', 'CNPJ'})
customer/documentNumber: string

Response success:

{
  "result": {
    "success":"true",
    "code":"000",
    "message":"Success"
  },
  "brand":"VISA",
  "cardToken":"2b5141a2209384e4266c8f7cbaf67a2d"
}

Response Failure {

:result=>{
  :success=>false,
  :code=>"120",
  :message=>"O numero do documento eh obrigatorio"
}

}



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/midas_client/transaction.rb', line 38

def card_store(*params)
  # Parametros são recebidos como um array de hash, pego o 1o item do array
  params = params.first

  # inicializa as variáveis de retorno
  result ={}
  card_token = nil

  # define o método de envio da requisição
  method = :post

  # monta a URL de chamada da requisição
  endpoint=  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:store]

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, , password, params)

  result = response[:result]
  card_token = response[:cardToken] if !response[:cardToken].nil?

  return result, card_token
end

#query_transaction(transaction_token) ⇒ Object

This method performs a query by a specific transaction. This is a is synchronous operation, using method GET

Params:

transactionToken: string (Transaction unique identification generated by our
                          gateway and received in the transaction authorization response)#

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}


378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/midas_client/transaction.rb', line 378

def query_transaction(transaction_token)
  # inicializa as variáveis de retorno
  result ={}

  # define o método de envio da requisição
  method = :get

  # monta a URL de chamada da requisição
  endpoint =  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:query_by_transaction].gsub("{transactionToken}", transaction_token)

  response = request(method, endpoint, , password, params)

  result = response[:result]

  return result
end

#refund(transaction_token) ⇒ Object

This method performs a refund in a captured authorized transaction. This is a is synchronous operation.

Params:

transactionToken: string (Transaction unique identification generated by our
                          gateway and received in the transaction authorization response)#

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}


346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/midas_client/transaction.rb', line 346

def refund(transaction_token)
  # inicializa as variáveis de retorno
  result ={}

  # define o método de envio da requisição
  method = :put

  # monta a URL de chamada da requisição
  endpoint =  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:refund].gsub("{transactionToken}", transaction_token)

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, self., self.password, {})

  result = response[:result]

  return result
end

#synchronous_transaction(*params) ⇒ Object

This method creates a payment transaction, already performing the authorization and capture in only one step.

Params:

externalId: string (Transaction identification on the client application)
externalDate: Date and time form client application - YYYY-MM-DDThh:mm:SS.sssTDZ - ISO8601
cardToken: string (created by method card_store)
cvv: number (Security Code)
amount: number (Only integer numbers, with the last two digits representing the cents.
                For example: 100 is equivalent to R$ 1,00)
instalments: number (1 to 12)

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
},
transactionToken: "65ffe2897b832cb89cb2063b74fbb143",
nsu: "99999"


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/midas_client/transaction.rb', line 82

def synchronous_transaction(*params)
  # Parametros são recebidos como um array de hash, pego o 1o item do array
  params = params.first

  # inicializa as variáveis de retorno
  result ={}
  nsu = ""
  transaction_token = ""

  # define o método de envio da requisição
  method = :post

  # monta a URL de chamada da requisição
  endpoint=  EndPoints.get_env[:url] + EndPoints.get_env[:context] + EndPoints::Operations[:synchronous_transaction]

  # regulariza o formato da data
  params[:externaldate] = params[:externaldate].blank? ? Time.now.iso8601(1) : params[:externaldate]

  # faz a chamada a plataforma de pagamento (MIDAS)
  response = request(method, endpoint, self., self.password, params)

  result = response[:result]
  nsu = response[:nsu] if !response[:nsu].nil?
  transaction_token = response[:transactionToken] if !response[:transactionToken].nil?

  return result, transaction_token, nsu
end