Class: PaykassaPay

Inherits:
Object
  • Object
show all
Defined in:
lib/paykassa/pay.rb

Constant Summary collapse

BASE_URL =
URI("https://paykassa.app/api/0.5/index.php")
RATE_URL =
URI("https://currency.paykassa.pro/index.php")
BASE_SCI_URI =
URI('https://paykassa.pro/sci/0.3/index.php')
CURRENCIES =
[
    "USD", "RUB", "BTC", "ETH", "LTC", "DOGE", "DASH", "BCH", "ZEC",
    "XRP", "TRX", "XLM", "BNB", "USDT", "ADA", "EOS", "GBP", "EUR", 
    "USDC", "BUSD"
]
SYSTEM_IDS =
{
    perfectmoney: 2,
    berty: 7,
    bitcoin: 11,
    ethereum: 12,
    litecoin: 14,
    dogecoin: 15,
    dash: 16,
    bitcoincash: 18,
    zcash: 19,
    ripple: 22,
    tron: 27,
    stellar: 28,
    binancecoin: 29,
    tron_trc20: 30,
    binancesmartchain_bep20: 31, # available currencies USDT, BUSD, USDC, ADA, EOS, BTC, ETH, DOGE    
    ethereum_erc20: 32
}

Instance Method Summary collapse

Constructor Details

#initialize(domain:, api_id:, api_key:, test: false, logger: nil) ⇒ PaykassaPay

Returns a new instance of PaykassaPay.



30
31
32
33
34
35
# File 'lib/paykassa/pay.rb', line 30

def initialize(domain:, api_id:, api_key:, test: false, logger: nil)
    @logger = logger
    @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

Instance Method Details

#balance(shop:) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/paykassa/pay.rb', line 50

def balance(shop: ) 
    data = {
        shop: shop,
        api_id: @_auth[:api_id], 
        api_key: @_auth[:api_key]
    }
    @logger.info("Pay.balance with data: #{data.inspect}") unless @logger.nil?
    make_request(
        func: "api_get_shop_balance", 
        data: data, 
        merge_auth: false
    )
end

#currency_rate(inn:, out:) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/paykassa/pay.rb', line 63

def currency_rate(inn:,out:)
    if !CURRENCIES.include? inn 
        raise "#{inn} not include in currencies: #{CURRENCIES}"
    end
    if !CURRENCIES.include? out 
        raise "#{out} not include in currencies: #{CURRENCIES}"
    end
    data = {
        currency_in: inn, 
        currency_out: out
    }
    @logger.info("Pay.currency_rate with data: #{data.inspect}") if !@logger.nil?
    make_request(
        func: nil,
        data: data,
        merge_auth: false, 
        url: RATE_URL
    )
end

#pay(amount:, shop:, currency:, system_name:, paid_commission: "shop", number:, tag:, priority:) ⇒ Object



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

def pay(amount: , shop: , currency: , system_name: , paid_commission: "shop", number:, tag:, priority:)
    data = {
        amount: amount.to_f, 
        shop: shop, 
        currency: currency,
        system: SYSTEM_IDS[system_name],
        paid_commission: paid_commission,
        number: number, 
        tag: tag, 
        priority: priority
    }
    @logger.info("Pay.pay with data: #{data.inspect}") unless @logger.nil?
    make_request(func: "api_payment",data: data, merge_auth: true)
end