Skip to content

Commit

Permalink
fix: create_charge is broken on latest satspay
Browse files Browse the repository at this point in the history
- improved error handling
  • Loading branch information
dni committed Aug 30, 2024
1 parent da36b42 commit aef24c7
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,27 @@ async def api_create_tip(data: CreateTips):
)

name = data.name or "Anonymous"
charge_id = await create_charge(
data={
"amount": sats,
"webhook": tipjar.webhook or "",
"name": name,
"description": message,
"onchainwallet": tipjar.onchain or "",
"lnbitswallet": tipjar.wallet,
"completelink": "/tipjar/" + str(tipjar_id),
"completelinktext": "Thanks for the tip!",
"time": 1440,
"custom_css": "",
},
api_key=wallet.inkey,
)
try:
charge_id = await create_charge(
data={
"amount": sats,
"webhook": tipjar.webhook or None,
"name": name,
"description": message,
"onchainwallet": tipjar.onchain or None,
"lnbitswallet": tipjar.wallet,
"completelink": f"/tipjar/{tipjar_id}",
"completelinktext": "Thanks for the tip!",
"time": 1440,
"custom_css": "",
},
api_key=wallet.inkey,
)
except Exception as exc:
msg = f"Failed to create charge: {exc!s}"
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR, detail=msg
) from exc

await create_tip(
tip_id=charge_id,
Expand Down Expand Up @@ -184,7 +190,13 @@ async def api_delete_tip(
detail="Not authorized to delete this tip!",
)
await delete_tip(tip_id)
await delete_charge(tip_id, key_type.wallet.inkey)
try:
await delete_charge(tip_id, key_type.wallet.inkey)
except Exception as exc:
raise HTTPException(
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
detail=f"Failed to delete charge: {exc!s}",
) from exc

return "", HTTPStatus.NO_CONTENT

Expand Down

0 comments on commit aef24c7

Please sign in to comment.