lib/mundipagg/MundipaggApi.rb in mundipagg_api-1.0.1 vs lib/mundipagg/MundipaggApi.rb in mundipagg_api-1.1.0
- old
+ new
@@ -10,15 +10,17 @@
@serviceEnvironment = environment
@merchantKey = merchantKey
@@SERVICE_HEADERS = {:MerchantKey => "#{@merchantKey}", :Accept => 'application/json', :"Content-Type" => 'application/json'}
end
- # URL de production
+ # URL de producao
@@SERVICE_URL_PRODUCTION = 'https://transactionv2.mundipaggone.com/Sale/'
+ @@SERVICE_URL_PRODUCTION_CREDIT_CARD = 'https://transactionv2.mundipaggone.com/CreditCard/'
- # URL de homologation
+ # URL de homologacao
@@SERVICE_URL_STAGING = 'https://stagingv2.mundipaggone.com/Sale/'
+ @@SERVICE_URL_STAGING_CREDIT_CARD = 'https://stagingv2.mundipaggone.com/CreditCard/'
# permite que o integrador adicione uma busca por transacoes utilizando alguns criterios
def Query(querySaleRequestEnum, key)
# try, tenta fazer o request
begin
@@ -35,11 +37,11 @@
# se der algum erro, trata aqui
rescue RestClient::ExceptionWithResponse => err
return err.response
end
- # se n�o houver erros, trata o json e retorna o objeto
+ # se nao houver erros, trata o json e retorna o objeto
querySaleResponse = JSON.load response
querySaleResponse
end
# criar uma transacao na plataforma One utilizando um ou mais meios de pagamento
@@ -300,10 +302,11 @@
return err.response
end
return response
end
+ # ffaz o download do transaction report file e salva no computador em .txt
def TransactionReportFileDownloader(date, file_name, path)
begin
path = path + file_name + '.txt'
response = RestClient.get('https://api.mundipaggone.com/TransactionReportFile/GetStream?fileDate=' + date.strftime("%Y%m%d"), headers={:MerchantKey => "#{@merchantKey}"})
File.write(path, response)
@@ -321,9 +324,56 @@
return err
end
return response
end
+ def InstantBuyKey(instant_buy_key)
+ # try, tenta fazer o request
+ begin
+
+ # se for homologacao faz a chamada por aqui
+ if @serviceEnvironment == :staging
+ response = RestClient.get @@SERVICE_URL_STAGING_CREDIT_CARD + instant_buy_key, headers=@@SERVICE_HEADERS
+
+ # se for producao, faz a chamada por aqui
+ elsif @serviceEnvironment == :production
+ response = RestClient.get @@SERVICE_URL_PRODUCTION_CREDIT_CARD + instant_buy_key, headers=@@SERVICE_HEADERS
+ end
+
+ # se der algum erro, trata aqui
+ rescue RestClient::ExceptionWithResponse => err
+ return err.response
+ end
+
+ # se nao houver erros, trata o json e retorna o objeto
+ instant_buy_response = JSON.load response
+ instant_buy_response
+ end
+
+ def BuyerKey(buyer_key)
+ # try, tenta fazer o request
+ begin
+
+ # se for homologacao faz a chamada por aqui
+ if @serviceEnvironment == :staging
+ response = RestClient.get @@SERVICE_URL_STAGING_CREDIT_CARD + buyer_key + '/BuyerKey', headers=@@SERVICE_HEADERS
+
+ # se for producao, faz a chamada por aqui
+ elsif @serviceEnvironment == :production
+ response = RestClient.get @@SERVICE_URL_PRODUCTION_CREDIT_CARD + buyer_key + '/BuyerKey', headers=@@SERVICE_HEADERS
+ end
+
+ # se der algum erro, trata aqui
+ rescue RestClient::ExceptionWithResponse => err
+ return err.response
+ end
+
+ # se nao houver erros, trata o json e retorna o objeto
+ buyer_response = JSON.load response
+ buyer_response
+ end
+
+ # funcao de post generica
def postRequest(payload, url)
response = nil
begin
response = RestClient.post(url, payload, headers=@@SERVICE_HEADERS)
rescue RestClient::ExceptionWithResponse => err