lib/paykassa/pay.rb in paykassa-0.1.10 vs lib/paykassa/pay.rb in paykassa-0.1.11
- old
+ new
@@ -25,11 +25,12 @@
binancecoin: 29,
tron_trc20: 30,
binancesmartchain_bep20: 31, # available currencies USDT, BUSD, USDC, ADA, EOS, BTC, ETH, DOGE
ethereum_erc20: 32
}
- def initialize(domain:, api_id:, api_key:, test: false)
+ def initialize(domain:, api_id:, api_key:, test: false, logger: nil)
+ @logger.info("Initialize class Pay with params: domain: #{domain}, api_id: #{api_id}, api_key: #{api_key}, test: #{test}") if !@logger.nil?
@token = api_key
@_auth = {domain: domain, api_id: api_id, api_key: api_key, test: test}
end
def pay(amount: , shop: , currency: , system_name: , paid_commission: "shop", number:, tag:, priority:)
data = {
@@ -40,18 +41,20 @@
paid_commision: paid_commision,
number: number,
tag: tag,
priority: priority
}
+ @logger.info("Pay.pay with data: #{data.inspect}") if !@logger.nil?
make_request("api_payment",data)
end
def balance(shop: )
data = {
shop: shop,
pi_id: @_auth[:api_id],
api_key: @_auth[:api_key]
}
+ @logger.info("Pay.balance with data: #{data.inspect}") if !@logger.nil?
make_request("api_get_shop_balance", data, false)
end
def currency_rate(inn:,out:)
if !CURRENCIES.include? inn
raise "#{inn} not include in currencies: #{CURRENCIES}"
@@ -61,10 +64,11 @@
end
data = {
currency_in: inn,
currency_out: out
}
+ @logger.info("Pay.currency_rate with data: #{data.inspect}") if !@logger.nil?
make_request(
nil,
data,
false,
RATE_URL
@@ -72,11 +76,13 @@
end
private
def make_request(func,data,merge_auth = true, url= nil)
data = data.merge({func: func}) if !func.nil?
data = data.merge(@_auth) if merge_auth
- url = BASE_SCI_URI if url.nil?
+ url = BASE_URI if url.nil?
+ @logger.info("private Pay.make_request with params: url: #{url.inspect}, data: #{data.inspect}") if !@logger.nil?
res = Net::HTTP.post_form(url, data)
+ @logger.info("private Pay.make_request: result: #{res.inspect}") if !@logger.nil?
JSON.parse(res.body).deep_symbolize_keys
end
end