Class: MidasClient::Transaction

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

Constant Summary

Constants included from EndPoints

EndPoints::DEVELOPMENT, EndPoints::MANAGEMENTS, EndPoints::OPERATIONS, EndPoints::PRODUCTION, EndPoints::QUERIES, EndPoints::SUBSCRIPTIONS

Instance Attribute Summary

Attributes inherited from Request

#environment, #login, #password, #query, #subscription, #transaction

Attributes included from Util

#logger

Instance Method Summary collapse

Methods inherited from Request

#base_result, external_request, #initialize, #request

Methods included from EndPoints

#get_env, #get_environment, #production?, #set_env

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",


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/midas_client/transaction.rb', line 159

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

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

  # monta a URL de chamada da requisição
  endpoint=  get_env[:url] + EndPoints::OPERATIONS[: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)
  request(method, endpoint, self., self.password, params)
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",


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/midas_client/transaction.rb', line 113

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

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

  # monta a URL de chamada da requisição
  endpoint=  get_env[:url] + EndPoints::OPERATIONS[: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)
  request(method, endpoint, self., self.password, params)

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"
}

}



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/midas_client/transaction.rb', line 206

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

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

  # monta a URL de chamada da requisição
  endpoint=  get_env[:url] + EndPoints::OPERATIONS[: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)
  request(method, endpoint, self., self.password, params)

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"
}


262
263
264
265
266
267
268
269
270
271
272
# File 'lib/midas_client/transaction.rb', line 262

def cancellation(transaction_token)
  # define o método de envio da requisição
  method = :put

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

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

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"
}


237
238
239
240
241
242
243
244
245
246
247
# File 'lib/midas_client/transaction.rb', line 237

def capture(transaction_token)
  # define o método de envio da requisição
  method = :put

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

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

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"
}

}



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/midas_client/transaction.rb', line 36

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

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

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

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

end

#query_external_id(externalId) ⇒ Object

This method performs a query by a specific transaction’s identifier, called external ID.

This is a is synchronous operation, using method GET

Params:

transactionToken: string (Transaction unique identification generated by customer)

{

"result": {
    "success": true,
    "code": "000",
    "message": "Sucesso"
},
    "pagging": {
    "limit": 1,
    "count": 1,
    "current": 1
},
    "transactions": [
    {
        "externalId": "906cb7ec",
        "externalDate": "2017-08-26T03:02:28.7",
        "paymentMethod": "CREDIT_CARD",
        "creditCard": {
            "brand": "VISA",
            "panLastDigits": "0308",
            "expirationMonth": 12,
            "expirationYear": 2020,
            "holderName": "CARLOS A C OLIVEIRA",
            "customer": {
                "documentType": "CPF",
                "documentNumber": "07564954744"
            }
        },
        "amount": 12000,
        "instalments": 5,
        "callbackUrl": "http://coliveira.dynu.com:3001/callback/906cb7ec",
        "nsu": "464672",
        "authorizationCode": "123456",
        "token": "8935aa77e9e4ed962d594910f96bf73f",
        "status": "CAPTURED"
    }
]
}


370
371
372
373
374
375
376
377
378
# File 'lib/midas_client/transaction.rb', line 370

def query_external_id(externalId)
  # define o método de envio da requisição
  method = :get

  # monta a URL de chamada da requisição
  endpoint =  get_env[:url] + EndPoints::QUERIES[:context] + EndPoints::QUERIES[:by_external_id].gsub('{externalId}', externalId)

  request(method, endpoint, , password, {})
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"
}


314
315
316
317
318
319
320
321
322
# File 'lib/midas_client/transaction.rb', line 314

def query_transaction(transaction_token)
  # define o método de envio da requisição
  method = :get

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

  request(method, endpoint, , password, {})
end

#query_user_cards(document_type = 'CPF', document_number) ⇒ Object

This method performs a query to list all creditcards form a user.

This is a is synchronous operation, using method GET

Params:

documentType: string (CPF or CNPJ)
documentNumber: string

Response:

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


394
395
396
397
398
399
400
401
402
# File 'lib/midas_client/transaction.rb', line 394

def query_user_cards(document_type='CPF', document_number)
  # define o método de envio da requisição
  method = :get

  # monta a URL de chamada da requisição
  endpoint =  get_env[:url] + EndPoints::OPERATIONS[:context] + EndPoints::OPERATIONS[:cards_by_user].gsub('{documentType}', document_type).gsub('{documentNumber}', document_number)

  request(method, endpoint, , password, {})
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"
}


288
289
290
291
292
293
294
295
296
297
298
# File 'lib/midas_client/transaction.rb', line 288

def refund(transaction_token)
  # define o método de envio da requisição
  method = :put

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

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

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"


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/midas_client/transaction.rb', line 72

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

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

  # monta a URL de chamada da requisição
  endpoint=  get_env[:url] + EndPoints::OPERATIONS[: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)
  request(method, endpoint, self., self.password, params)

end