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
b70c5596
Commit
b70c5596
authored
Apr 16, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(payments): implement basic payment service orchestrator
parent
d5a3e348
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
1 deletion
+103
-1
__init__.py
aisbf/payments/__init__.py
+3
-1
service.py
aisbf/payments/service.py
+100
-0
No files found.
aisbf/payments/__init__.py
View file @
b70c5596
...
@@ -7,10 +7,12 @@ from aisbf.payments.models import (
...
@@ -7,10 +7,12 @@ from aisbf.payments.models import (
CryptoWallet
,
CryptoWallet
,
AddCryptoPaymentMethodRequest
AddCryptoPaymentMethodRequest
)
)
from
aisbf.payments.service
import
PaymentService
__all__
=
[
__all__
=
[
'PaymentMigrations'
,
'PaymentMigrations'
,
'CryptoAddress'
,
'CryptoAddress'
,
'CryptoWallet'
,
'CryptoWallet'
,
'AddCryptoPaymentMethodRequest'
'AddCryptoPaymentMethodRequest'
,
'PaymentService'
]
]
aisbf/payments/service.py
0 → 100644
View file @
b70c5596
"""
Main payment service orchestrator
"""
import
logging
from
typing
import
Optional
logger
=
logging
.
getLogger
(
__name__
)
class
PaymentService
:
"""Main payment service orchestrating all payment operations"""
def
__init__
(
self
,
db_manager
,
config
:
dict
):
self
.
db
=
db_manager
self
.
config
=
config
# Initialize sub-services
from
aisbf.payments.crypto.wallet
import
CryptoWalletManager
from
aisbf.payments.crypto.pricing
import
CryptoPriceService
from
aisbf.payments.crypto.monitor
import
BlockchainMonitor
self
.
wallet_manager
=
CryptoWalletManager
(
db_manager
,
config
[
'encryption_key'
])
self
.
price_service
=
CryptoPriceService
(
db_manager
,
config
)
self
.
blockchain_monitor
=
BlockchainMonitor
(
db_manager
,
config
)
async
def
initialize
(
self
):
"""Initialize payment service (run on startup)"""
logger
.
info
(
"Payment service initialized"
)
async
def
get_user_crypto_addresses
(
self
,
user_id
:
int
)
->
dict
:
"""Get or create crypto addresses for user"""
addresses
=
{}
# Get enabled crypto types
with
self
.
db
.
_get_connection
()
as
conn
:
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"""
SELECT crypto_type FROM crypto_consolidation_settings
WHERE enabled = TRUE
"""
)
enabled_cryptos
=
cursor
.
fetchall
()
for
crypto_config
in
enabled_cryptos
:
crypto_type
=
crypto_config
[
0
]
address
=
await
self
.
wallet_manager
.
get_or_create_user_address
(
user_id
,
crypto_type
)
addresses
[
crypto_type
]
=
address
return
addresses
async
def
get_user_wallet_balances
(
self
,
user_id
:
int
)
->
dict
:
"""Get user's crypto wallet balances"""
with
self
.
db
.
_get_connection
()
as
conn
:
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"""
SELECT crypto_type, balance_crypto, balance_fiat, last_updated
FROM user_crypto_wallets
WHERE user_id = ?
"""
,
(
user_id
,))
wallets
=
cursor
.
fetchall
()
return
{
wallet
[
0
]:
{
'balance_crypto'
:
float
(
wallet
[
1
]),
'balance_fiat'
:
float
(
wallet
[
2
]),
'last_sync'
:
wallet
[
3
]
}
for
wallet
in
wallets
}
async
def
add_crypto_payment_method
(
self
,
user_id
:
int
,
crypto_type
:
str
)
->
dict
:
"""Add crypto as payment method"""
try
:
# Get or create crypto address
address
=
await
self
.
wallet_manager
.
get_or_create_user_address
(
user_id
,
crypto_type
)
# Create payment method entry
with
self
.
db
.
_get_connection
()
as
conn
:
cursor
=
conn
.
cursor
()
cursor
.
execute
(
"""
INSERT INTO payment_methods
(user_id, type, gateway, crypto_type, is_default, status)
VALUES (?, 'crypto', ?, ?, TRUE, 'active')
"""
,
(
user_id
,
crypto_type
,
crypto_type
))
conn
.
commit
()
return
{
'success'
:
True
,
'crypto_type'
:
crypto_type
,
'address'
:
address
}
except
Exception
as
e
:
logger
.
error
(
f
"Error adding crypto payment method: {e}"
)
return
{
'success'
:
False
,
'error'
:
str
(
e
)}
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