diff --git a/crud.py b/crud.py index fd6220c..8e565ec 100644 --- a/crud.py +++ b/crud.py @@ -55,11 +55,12 @@ async def create_charge( time, amount, zeroconf, + fasttrack, balance, extra, custom_css ) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( charge_id, @@ -77,6 +78,7 @@ async def create_charge( data.time, data.amount, data.zeroconf, + data.fasttrack, 0, data.extra, data.custom_css, diff --git a/migrations.py b/migrations.py index 2498f48..f72d435 100644 --- a/migrations.py +++ b/migrations.py @@ -197,3 +197,15 @@ async def m013_add_setting_webhook(db): await db.execute("UPDATE satspay.settings SET webhook_method = 'GET'") except OperationalError: pass + + +async def m014_fasttrack_to_charge(db): + """ + Add 'fasttrack' column to charge for allowing fasttrack checkout without 0conf + """ + try: + await db.execute( + "ALTER TABLE satspay.charges ADD COLUMN fasttrack BOOLEAN DEFAULT FALSE" + ) + except OperationalError: + pass diff --git a/models.py b/models.py index 5f44ac1..b66c58e 100644 --- a/models.py +++ b/models.py @@ -25,6 +25,7 @@ class CreateCharge(BaseModel): time: int = Query(..., ge=1) amount: Optional[int] = Query(None, ge=1) zeroconf: bool = Query(False) + fasttrack: bool = Query(False) custom_css: Optional[str] = Query(None) currency: str = Query(None) currency_amount: Optional[float] = Query(None) @@ -47,6 +48,7 @@ class Charge(BaseModel): time: int amount: int zeroconf: bool + fasttrack: bool balance: int pending: Optional[int] = 0 timestamp: datetime @@ -60,6 +62,13 @@ def add_extra(self, extra: dict): old_extra = json.loads(self.extra) if self.extra else {} self.extra = json.dumps({**old_extra, **extra}) + @property + def paid_fasttrack(self): + """ + ignore the pending status if fasttrack is enabled tell the frontend its paid + """ + return (self.pending or 0) >= self.amount and self.fasttrack or self.paid + @property def public(self): public_keys = [ @@ -72,6 +81,7 @@ def public(self): "time", "amount", "zeroconf", + "fasttrack", "balance", "pending", "timestamp", @@ -81,7 +91,8 @@ def public(self): ] c = {k: v for k, v in self.dict().items() if k in public_keys} c["timestamp"] = self.timestamp.isoformat() - if self.paid: + c["paid"] = self.paid_fasttrack + if self.paid_fasttrack: c["completelink"] = self.completelink return c diff --git a/static/js/index.js b/static/js/index.js index 63ece5d..01dbfcc 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -139,6 +139,7 @@ new Vue({ onchain: false, onchainwallet: '', zeroconf: false, + fasttrack: false, lnbits: false, description: '', custom_css: '', diff --git a/tasks.py b/tasks.py index 4037b0c..f3190ed 100644 --- a/tasks.py +++ b/tasks.py @@ -52,10 +52,12 @@ async def send_success_websocket(charge: Charge): for listener in listeners: await listener.send_json( { - "paid": charge.paid, + "paid": charge.paid_fasttrack, "balance": charge.balance, "pending": charge.pending, - "completelink": charge.completelink if charge.paid else None, + "completelink": ( + charge.completelink if charge.paid_fasttrack else None + ), } ) diff --git a/templates/satspay/index.html b/templates/satspay/index.html index 89eb465..2390789 100644 --- a/templates/satspay/index.html +++ b/templates/satspay/index.html @@ -456,7 +456,7 @@