Initial BTCPay integration
This commit is contained in:
parent
9b3386de30
commit
e1ff5c479e
@ -1,3 +1,4 @@
|
|||||||
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
|
EJABBERD_API_URL='https://xmpp.kosmos.org/api'
|
||||||
|
BTCPAY_API_URL='http://localhost:23001'
|
||||||
LNDHUB_API_URL='http://localhost:3023'
|
LNDHUB_API_URL='http://localhost:3023'
|
||||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
EJABBERD_API_URL='https://xmpp.kosmos.org:5443/api'
|
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_API_URL='http://10.1.1.163:3023'
|
||||||
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
LNDHUB_PUBLIC_URL='https://lndhub.kosmos.org'
|
||||||
|
32
app/services/btc_pay.rb
Normal file
32
app/services/btc_pay.rb
Normal 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
|
Loading…
x
Reference in New Issue
Block a user