Add kredits API with wallet balance endpoint
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-05-23 22:47:08 +02:00
parent e1ff5c479e
commit caea2d0121
7 changed files with 70 additions and 5 deletions

View File

@@ -0,0 +1,5 @@
class Api::BaseController < ApplicationController
layout false
end

View File

@@ -0,0 +1,12 @@
class Api::KreditsController < Api::BaseController
def onchain_btc_balance
btcpay = BtcPay.new
balance = btcpay.onchain_wallet_balance
render json: balance
rescue
render json: { error: 'Failed to fetch wallet balance' },
status: 500
end
end

View File

@@ -9,12 +9,12 @@ class BtcPay
end
def onchain_wallet_balance
wallet_info = get "stores/#{@store_id}/payment-methods/onchain/BTC/wallet"
res = 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
balance: res["balance"].to_f,
unconfirmed_balance: res["unconfirmedBalance"].to_f,
confirmed_balance: res["confirmedBalance"].to_f
}
end