Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create_charge is broken on latest satspay #13

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: create_charge is broken on latest satspay
- improved error handling
dni committed Aug 30, 2024
commit aef24c75ff31e3a3cb05d7977d6d894b4cfb4ab8
44 changes: 28 additions & 16 deletions views_api.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -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