Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
aisbf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
aisbf
Commits
294063ed
Commit
294063ed
authored
Apr 16, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(payments): add crypto API endpoints
parent
1ed05114
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
81 additions
and
0 deletions
+81
-0
main.py
main.py
+81
-0
No files found.
main.py
View file @
294063ed
...
...
@@ -59,6 +59,7 @@ from pathlib import Path
import
json
import
markdown
from
urllib.parse
import
urljoin
,
urlencode
from
cryptography.fernet
import
Fernet
# Global variable to store custom config directory
_custom_config_dir
=
None
...
...
@@ -66,6 +67,9 @@ _custom_config_dir = None
# Global variable to store original command line arguments for restart
_original_argv
=
None
# Payment service global
payment_service
=
None
def
set_config_dir
(
config_dir
:
str
):
"""Set custom config directory before importing config"""
global
_custom_config_dir
...
...
@@ -1153,6 +1157,33 @@ async def startup_event():
logger
.
info
(
"="
*
80
)
logger
.
info
(
""
)
# Initialize payment service
global
payment_service
try
:
# Generate or load encryption key
encryption_key
=
os
.
getenv
(
'ENCRYPTION_KEY'
)
if
not
encryption_key
:
encryption_key
=
Fernet
.
generate_key
()
.
decode
()
logger
.
warning
(
"No ENCRYPTION_KEY set, generated temporary key"
)
payment_config
=
{
'encryption_key'
:
encryption_key
,
'base_url'
:
os
.
getenv
(
'BASE_URL'
,
'http://localhost:17765'
),
'currency_code'
:
'USD'
,
'btc_confirmations'
:
3
,
'eth_confirmations'
:
12
}
from
aisbf.payments.service
import
PaymentService
db_manager
=
DatabaseRegistry
.
get_config_database
()
payment_service
=
PaymentService
(
db_manager
,
payment_config
)
await
payment_service
.
initialize
()
logger
.
info
(
"Payment service started"
)
except
Exception
as
e
:
logger
.
error
(
f
"Failed to initialize payment service: {e}"
)
# Continue startup even if payment service fails
logger
.
info
(
f
"=== AISBF Server Started ==="
)
logger
.
info
(
f
"Available providers: {list(config.providers.keys()) if config else []}"
)
logger
.
info
(
f
"Available rotations: {list(config.rotations.keys()) if config else []}"
)
...
...
@@ -1620,6 +1651,56 @@ app.add_middleware(SessionMiddleware, secret_key=_session_secret, max_age=30 * 2
# This ensures proxy headers are processed before any other middleware (including auth_middleware)
app
.
add_middleware
(
ProxyHeadersMiddleware
)
# Helper function for API authentication
async
def
get_current_user
(
request
:
Request
)
->
dict
:
"""Get current authenticated user from request state"""
user_id
=
getattr
(
request
.
state
,
'user_id'
,
None
)
if
user_id
is
None
:
raise
HTTPException
(
status_code
=
401
,
detail
=
"Authentication required"
)
# Get user from database
from
aisbf.database
import
get_database
db
=
DatabaseRegistry
.
get_config_database
()
user
=
db
.
get_user_by_id
(
user_id
)
if
not
user
:
raise
HTTPException
(
status_code
=
401
,
detail
=
"User not found"
)
return
user
# Crypto payment API endpoints
@
app
.
get
(
"/api/crypto/addresses"
)
async
def
get_crypto_addresses
(
request
:
Request
):
"""Get user's crypto addresses"""
current_user
=
await
get_current_user
(
request
)
addresses
=
await
payment_service
.
get_user_crypto_addresses
(
current_user
[
'id'
])
return
{
'addresses'
:
addresses
}
@
app
.
get
(
"/api/crypto/wallets"
)
async
def
get_crypto_wallets
(
request
:
Request
):
"""Get user's crypto wallet balances"""
current_user
=
await
get_current_user
(
request
)
balances
=
await
payment_service
.
get_user_wallet_balances
(
current_user
[
'id'
])
return
{
'wallets'
:
balances
}
@
app
.
post
(
"/api/payment-methods/crypto"
)
async
def
add_crypto_payment_method
(
request
:
Request
):
"""Add crypto payment method"""
current_user
=
await
get_current_user
(
request
)
body
=
await
request
.
json
()
result
=
await
payment_service
.
add_crypto_payment_method
(
current_user
[
'id'
],
body
[
'crypto_type'
]
)
if
not
result
[
'success'
]:
raise
HTTPException
(
status_code
=
400
,
detail
=
result
[
'error'
])
return
result
# Dashboard routes
@
app
.
get
(
"/dashboard/analytics"
,
response_class
=
HTMLResponse
)
async
def
dashboard_analytics
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment