Initial BTCPay integration

This commit is contained in:
Basti 2022-05-23 18:49:55 +02:00
parent 9b3386de30
commit e1ff5c479e
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
3 changed files with 34 additions and 0 deletions

View File

@ -1,3 +1,4 @@
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
BTCPAY_API_URL='http://localhost:23001'
LNDHUB_API_URL='http://localhost:3023'
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'

View File

@ -1,3 +1,4 @@
EJABBERD_API_URL='https://xmpp.kosmos.org:5443/api'
BTCPAY_API_URL='http://10.1.1.163:23001'
LNDHUB_API_URL='http://10.1.1.163:3023'
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'

32
app/services/btc_pay.rb Normal file
View File

@ -0,0 +1,32 @@
#
# API Docs: https://docs.btcpayserver.org/API/Greenfield/v1/
#
class BtcPay
def initialize
@base_url = "#{ENV["BTCPAY_API_URL"]}/api/v1"
@store_id = Rails.application.credentials.btcpay[:store_id]
@auth_token = Rails.application.credentials.btcpay[:auth_token]
end
def onchain_wallet_balance
wallet_info = get "stores/#{@store_id}/payment-methods/onchain/BTC/wallet"
{
balance: wallet_info["balance"].to_f,
unconfirmed_balance: wallet_info["unconfirmedBalance"].to_f,
confirmed_balance: wallet_info["confirmedBalance"].to_f
}
end
private
def get(endpoint)
res = Faraday.get("#{@base_url}/#{endpoint}", {}, {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "token #{@auth_token}"
})
JSON.parse(res.body)
end
end