Commit 1ed05114 authored by Your Name's avatar Your Name

fix(payments): use database-agnostic placeholders in PaymentService

parent b70c5596
...@@ -34,10 +34,11 @@ class PaymentService: ...@@ -34,10 +34,11 @@ class PaymentService:
# Get enabled crypto types # Get enabled crypto types
with self.db._get_connection() as conn: with self.db._get_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(""" placeholder = '?' if self.db.db_type == 'sqlite' else '%s'
cursor.execute(f"""
SELECT crypto_type FROM crypto_consolidation_settings SELECT crypto_type FROM crypto_consolidation_settings
WHERE enabled = TRUE WHERE enabled = {placeholder}
""") """, (True,))
enabled_cryptos = cursor.fetchall() enabled_cryptos = cursor.fetchall()
for crypto_config in enabled_cryptos: for crypto_config in enabled_cryptos:
...@@ -54,10 +55,11 @@ class PaymentService: ...@@ -54,10 +55,11 @@ class PaymentService:
"""Get user's crypto wallet balances""" """Get user's crypto wallet balances"""
with self.db._get_connection() as conn: with self.db._get_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(""" placeholder = '?' if self.db.db_type == 'sqlite' else '%s'
cursor.execute(f"""
SELECT crypto_type, balance_crypto, balance_fiat, last_updated SELECT crypto_type, balance_crypto, balance_fiat, last_updated
FROM user_crypto_wallets FROM user_crypto_wallets
WHERE user_id = ? WHERE user_id = {placeholder}
""", (user_id,)) """, (user_id,))
wallets = cursor.fetchall() wallets = cursor.fetchall()
...@@ -82,11 +84,12 @@ class PaymentService: ...@@ -82,11 +84,12 @@ class PaymentService:
# Create payment method entry # Create payment method entry
with self.db._get_connection() as conn: with self.db._get_connection() as conn:
cursor = conn.cursor() cursor = conn.cursor()
cursor.execute(""" placeholder = '?' if self.db.db_type == 'sqlite' else '%s'
cursor.execute(f"""
INSERT INTO payment_methods INSERT INTO payment_methods
(user_id, type, gateway, crypto_type, is_default, status) (user_id, type, gateway, crypto_type, is_default, status)
VALUES (?, 'crypto', ?, ?, TRUE, 'active') VALUES ({placeholder}, 'crypto', {placeholder}, {placeholder}, {placeholder}, 'active')
""", (user_id, crypto_type, crypto_type)) """, (user_id, crypto_type, crypto_type, True))
conn.commit() conn.commit()
return { return {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment