Class: MidasClient::Query

Inherits:
Request
  • Object
show all
Defined in:
lib/midas_client/query.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

#by_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)

Response:

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


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/midas_client/query.rb', line 62

def by_external_id(externalId)
  log "Entrei em by_external_id"

  # 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

#by_external_ids(externalIds = []) ⇒ Object

This method performs a query by an array of transaction’s identifier.

This is a is synchronous operation, using method GET

Params:

none

Response:

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


87
88
89
90
91
92
93
94
95
96
97
# File 'lib/midas_client/query.rb', line 87

def by_external_ids(externalIds = [])
  log "Entrei em by_external_ids"

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

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

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

#by_transaction_tokens(transactionTokens = []) ⇒ Object

This method performs a query by an array of transaction’s token.

This is a is synchronous operation, using method GET

Params:

none

Response:

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


112
113
114
115
116
117
118
119
120
121
122
# File 'lib/midas_client/query.rb', line 112

def by_transaction_tokens(transactionTokens = [])
  log "Entrei em by_external_ids"

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

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

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

#list_creditcardsObject

This method performs a query to return all creditcards stored for a Point Of Sale

This is a is synchronous operation, using method GET

Params:

none

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}
creditCards: [
{
   brand: "MASTER",
   panLastDigits": "4832",
   expirationMonth": 10,
   expirationYear": 2019,
   holderName": "Nome Portador",
   customer: {
      documentType: "CPF",
      documentNumber: "12345678900"
   },
   token: "b7553c62bc93ed0708b4behfcf28f3592"
 }


192
193
194
195
196
197
198
199
200
201
202
# File 'lib/midas_client/query.rb', line 192

def list_creditcards()
  log "Entrei em list_creditcards"
  # 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[:creditcards]

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

#list_customersObject

This method performs a query to return all creditcards stored for a Point Of Sale

This is a is synchronous operation, using method GET

Params:

none

Response:

result: {
  success: true/false
  code: "XXX"
  message: "Some message to you"
}
creditCards: [
{
   brand: "MASTER",
   panLastDigits": "4832",
   expirationMonth": 10,
   expirationYear": 2019,
   holderName": "Nome Portador",
   customer: {
      documentType: "CPF",
      documentNumber: "12345678900"
   },
   token: "b7553c62bc93ed0708b4behfcf28f3592"
 }


229
230
231
232
233
234
235
236
237
238
239
# File 'lib/midas_client/query.rb', line 229

def list_customers()
  log "Entrei em list_customers"
  # 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[:customers]

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

#subscriptions(status = nil) ⇒ Object

This method performs a query to return all subscriptions for a Point Of Sale by status

This is a is synchronous operation, using method GET

Params:

status: ACTIVE/CANCELLED

Response:

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


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/midas_client/query.rb', line 136

def subscriptions(status = nil)
  log "Entrei em subscriptions"
  # 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[:subscriptions]

  # monta os parâmetros da requisição na url
  endpoint = status.blank? ? endpoint.gsub("status={status}", '') : endpoint.gsub("{status}", status)

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

  result = response[:result]
  pagging = response[:pagging]
  if response[:subscriptions].kind_of?(Array) || response[:subscriptions].blank?
    subscriptions = response[:subscriptions]
  else
    subscription_array = []
    subscription_array << response[:subscriptions]
    subscriptions = subscription_array
  end

  response[:result] = result
  response[:pagging] = pagging
  response[:subscriptions] = subscriptions

  response
end

#transaction_by_date(start_date = (Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil) ⇒ Object

This method performs a query by a range date.

This is a is synchronous operation, using method GET

Params:

start_date: date format YYYY-MM-DD
send_date: date format YYYY-MM-DD

Response:

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


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/midas_client/query.rb', line 18

def transaction_by_date(start_date=(Date.today - 7).strftime('%Y-%m-%d'), end_date = Date.today.strftime('%Y-%m-%d'), status = nil)
    log "Entrei em transaction_by_date"
    # 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_period].gsub("{startDate}", start_date).gsub("{endDate}", end_date)

    # monta os parâmetros da requisição na url
    endpoint = status.blank? ? endpoint.gsub("{status}", '') : endpoint.gsub("{status}", status)

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

    result = response[:result]
    pagging = response[:pagging]
    if response[:transactions].kind_of?(Array) || response[:transactions].blank?
      transactions = response[:transactions]
    else
      transaction_array = []
      transaction_array << response[:transactions]
      transactions = transaction_array
    end

    response[:result] = result
    response[:pagging] = pagging
    response[:transactions] = transactions

    response
end