some syntax refactoring
This commit is contained in:
@@ -29,8 +29,8 @@ class CreateData(BaseModel):
|
||||
url: Optional[str] = Query(...)
|
||||
memo: Optional[str] = Query(...)
|
||||
description: str
|
||||
amount: int
|
||||
remembers: bool
|
||||
amount: int
|
||||
remembers: bool
|
||||
|
||||
@paywall_ext.post("/api/v1/paywalls")
|
||||
@api_check_wallet_key("invoice")
|
||||
@@ -39,7 +39,7 @@ async def api_paywall_create(data: CreateData):
|
||||
return paywall, HTTPStatus.CREATED
|
||||
|
||||
|
||||
@paywall_ext.delete("/api/v1/paywalls/<paywall_id>")
|
||||
@paywall_ext.delete("/api/v1/paywalls/{paywall_id}")
|
||||
@api_check_wallet_key("invoice")
|
||||
async def api_paywall_delete(paywall_id):
|
||||
paywall = await get_paywall(paywall_id)
|
||||
@@ -55,7 +55,7 @@ async def api_paywall_delete(paywall_id):
|
||||
return "", HTTPStatus.NO_CONTENT
|
||||
|
||||
|
||||
@paywall_ext.post("/api/v1/paywalls/<paywall_id>/invoice")
|
||||
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/invoice")
|
||||
async def api_paywall_create_invoice(amount: int = Query(..., ge=1), paywall_id = None):
|
||||
paywall = await get_paywall(paywall_id)
|
||||
|
||||
@@ -76,26 +76,26 @@ async def api_paywall_create_invoice(amount: int = Query(..., ge=1), paywall_id
|
||||
extra={"tag": "paywall"},
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonable_encoder({"message": str(e)}), HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
return {"message": str(e)}, HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
|
||||
return (
|
||||
jsonable_encoder({"payment_hash": payment_hash, "payment_request": payment_request}),
|
||||
{"payment_hash": payment_hash, "payment_request": payment_request},
|
||||
HTTPStatus.CREATED,
|
||||
)
|
||||
|
||||
|
||||
@paywall_ext.post("/api/v1/paywalls/<paywall_id>/check_invoice")
|
||||
@paywall_ext.post("/api/v1/paywalls/{paywall_id}/check_invoice")
|
||||
async def api_paywal_check_invoice(payment_hash: str = Query(...), paywall_id = None):
|
||||
paywall = await get_paywall(paywall_id)
|
||||
|
||||
if not paywall:
|
||||
return jsonable_encoder({"message": "Paywall does not exist."}), HTTPStatus.NOT_FOUND
|
||||
return {"message": "Paywall does not exist."}, HTTPStatus.NOT_FOUND
|
||||
|
||||
try:
|
||||
status = await check_invoice_status(paywall.wallet, payment_hash)
|
||||
is_paid = not status.pending
|
||||
except Exception:
|
||||
return jsonable_encoder({"paid": False}), HTTPStatus.OK
|
||||
return {"paid": False}, HTTPStatus.OK
|
||||
|
||||
if is_paid:
|
||||
wallet = await get_wallet(paywall.wallet)
|
||||
@@ -103,8 +103,8 @@ async def api_paywal_check_invoice(payment_hash: str = Query(...), paywall_id =
|
||||
await payment.set_pending(False)
|
||||
|
||||
return (
|
||||
jsonable_encoder({"paid": True, "url": paywall.url, "remembers": paywall.remembers}),
|
||||
{"paid": True, "url": paywall.url, "remembers": paywall.remembers},
|
||||
HTTPStatus.OK,
|
||||
)
|
||||
|
||||
return jsonable_encoder({"paid": False}), HTTPStatus.OK
|
||||
return {"paid": False}, HTTPStatus.OK
|
||||
|
||||
Reference in New Issue
Block a user