prettier and black stuff.

This commit is contained in:
fiatjaf
2021-03-07 19:18:02 -03:00
parent c7717a611a
commit 1630a28da0
4 changed files with 69 additions and 19 deletions

View File

@@ -286,7 +286,11 @@ async def create_payment(
async def update_payment_status(checking_id: str, pending: bool) -> None:
await db.execute(
"UPDATE apipayments SET pending = ? WHERE checking_id = ?", (int(pending), checking_id,),
"UPDATE apipayments SET pending = ? WHERE checking_id = ?",
(
int(pending),
checking_id,
),
)

View File

@@ -34,12 +34,20 @@ async def get_or_create_shop_by_wallet(wallet: str) -> Optional[Shop]:
async def set_wordlist(shop: int, wordlist: str) -> Optional[Shop]:
await db.execute(
"UPDATE shops SET wordlist = ? WHERE id = ?", (wordlist, shop),
"UPDATE shops SET wordlist = ? WHERE id = ?",
(wordlist, shop),
)
return await get_shop(shop)
async def add_item(shop: int, name: str, description: str, image: Optional[str], price: int, unit: str,) -> int:
async def add_item(
shop: int,
name: str,
description: str,
image: Optional[str],
price: int,
unit: str,
) -> int:
result = await db.execute(
"""
INSERT INTO items (shop, name, description, image, price, unit)
@@ -51,7 +59,13 @@ async def add_item(shop: int, name: str, description: str, image: Optional[str],
async def update_item(
shop: int, item_id: int, name: str, description: str, image: Optional[str], price: int, unit: str,
shop: int,
item_id: int,
name: str,
description: str,
image: Optional[str],
price: int,
unit: str,
) -> int:
await db.execute(
"""

View File

@@ -8,20 +8,35 @@
<q-card-section>
<ol>
<li>Register items.</li>
<li>Print QR codes and paste them on your store, your menu, somewhere, somehow.</li>
<li>Clients scan the QR codes and get information about the items plus the price on their phones directly (they must have internet)</li>
<li>Once they decide to pay, they'll get an invoice on their phones automatically</li>
<li>When the payment is confirmed, a confirmation code will be issued for them.</li>
<li>
Print QR codes and paste them on your store, your menu, somewhere,
somehow.
</li>
<li>
Clients scan the QR codes and get information about the items plus the
price on their phones directly (they must have internet)
</li>
<li>
Once they decide to pay, they'll get an invoice on their phones
automatically
</li>
<li>
When the payment is confirmed, a confirmation code will be issued for
them.
</li>
</ol>
<p>
The confirmation codes are words from a predefined sequential word list. Each new payment bumps the words sequence by 1. So you can check the confirmation codes manually by just looking at them.
The confirmation codes are words from a predefined sequential word list.
Each new payment bumps the words sequence by 1. So you can check the
confirmation codes manually by just looking at them.
</p>
<p>
For example, if your wordlist is <code>[apple, banana, coconut]</code> the first purchase will be <code>apple</code>, the second <code>banana</code> and so on. When it gets to the end it starts from the beginning again.
</p>
<p>
Powered by LNURL-pay.
For example, if your wordlist is
<code>[apple, banana, coconut]</code> the first purchase will be
<code>apple</code>, the second <code>banana</code> and so on. When it
gets to the end it starts from the beginning again.
</p>
<p>Powered by LNURL-pay.</p>
</q-card-section>
</q-card>
</q-expansion-item>
@@ -51,8 +66,8 @@
}}/offlineshop/api/v1/offlineshop/items -H "Content-Type:
application/json" -H "X-Api-Key: {{ g.user.wallets[0].inkey }}" -d
'{"name": &lt;string&gt;, "description": &lt;string&gt;, "image":
&lt;data-uri string&gt;, "price": &lt;integer&gt;, "unit": &lt;"sat" or
"USD"&gt;}'
&lt;data-uri string&gt;, "price": &lt;integer&gt;, "unit": &lt;"sat"
or "USD"&gt;}'
</code>
</q-card-section>
</q-card>
@@ -74,7 +89,10 @@
</h5>
<code
>{"id": &lt;integer&gt;, "wallet": &lt;string&gt;, "wordlist":
&lt;string&gt;, "items": [{"id": &lt;integer&gt;, "name": &lt;string&gt;, "description": &lt;string&gt;, "image": &lt;string&gt;, "enabled": &lt;boolean&gt;, "price": &lt;integer&gt;, "unit": &lt;string&gt;, "lnurl": &lt;string&gt;}, ...]}&lt;/code
&lt;string&gt;, "items": [{"id": &lt;integer&gt;, "name":
&lt;string&gt;, "description": &lt;string&gt;, "image":
&lt;string&gt;, "enabled": &lt;boolean&gt;, "price": &lt;integer&gt;,
"unit": &lt;string&gt;, "lnurl": &lt;string&gt;}, ...]}&lt;</code
>
<h5 class="text-caption q-mt-sm q-mb-none">Curl example</h5>
<code

View File

@@ -24,7 +24,14 @@ async def api_shop_from_wallet():
try:
return (
jsonify({**shop._asdict(), **{"items": [item.values() for item in items],},}),
jsonify(
{
**shop._asdict(),
**{
"items": [item.values() for item in items],
},
}
),
HTTPStatus.OK,
)
except LnurlInvalidUrl:
@@ -50,7 +57,12 @@ async def api_add_or_update_item(item_id=None):
shop = await get_or_create_shop_by_wallet(g.wallet.id)
if item_id == None:
await add_item(
shop.id, g.data["name"], g.data["description"], g.data.get("image"), g.data["price"], g.data["unit"],
shop.id,
g.data["name"],
g.data["description"],
g.data.get("image"),
g.data["price"],
g.data["unit"],
)
return "", HTTPStatus.CREATED
else:
@@ -77,7 +89,9 @@ async def api_delete_item(item_id):
@offlineshop_ext.route("/api/v1/offlineshop/wordlist", methods=["PUT"])
@api_check_wallet_key("invoice")
@api_validate_post_request(
schema={"wordlist": {"type": "string", "empty": True, "nullable": True, "required": True},}
schema={
"wordlist": {"type": "string", "empty": True, "nullable": True, "required": True},
}
)
async def api_set_wordlist():
wordlist = g.data["wordlist"].split("\n") if g.data["wordlist"] else None