Custom shipping cost (#86)

* feat: simple UI for shipping zone per product

* feat: add empty cost

* fix: backwards compatible zones

* feat: finish UI for product shipping cost

* fix: some ui issues

* feat: add per product shipping cost

* feat: show receipt for product

* fix: publish per product shipping cost
This commit is contained in:
Vlad Stan 2023-09-21 17:29:13 +03:00 committed by GitHub
parent 2dc5c5479f
commit 5c83bf8972
6 changed files with 154 additions and 82 deletions

View file

@ -69,13 +69,13 @@ async def create_new_order(
if data.event_id and await get_order_by_event_id(merchant.id, data.event_id):
return None
order, invoice = await build_order_with_payment(
order, invoice, receipt = await build_order_with_payment(
merchant.id, merchant.public_key, data
)
await create_order(merchant.id, order)
return PaymentRequest(
id=data.id, payment_options=[PaymentOption(type="ln", link=invoice)]
id=data.id, payment_options=[PaymentOption(type="ln", link=invoice)], message=receipt
)
@ -90,7 +90,10 @@ async def build_order_with_payment(
assert shipping_zone, f"Shipping zone not found for order '{data.id}'"
product_cost_sat, shipping_cost_sat = await data.costs_in_sats(
products, shipping_zone.cost
products, shipping_zone.id, shipping_zone.cost
)
receipt = data.receipt(
products, shipping_zone.id, shipping_zone.cost
)
wallet_id = await get_wallet_for_product(data.items[0].product_id)
@ -126,7 +129,7 @@ async def build_order_with_payment(
extra=extra,
)
return order, invoice
return order, invoice, receipt
async def update_merchant_to_nostr(
@ -567,7 +570,7 @@ async def _handle_new_order(
except Exception as e:
logger.debug(e)
payment_req = await create_new_failed_order(
merchant_id, merchant_public_key, dm, json_data, str(e)
merchant_id, merchant_public_key, dm, json_data, "Order received, but cannot be processed. Please contact merchant."
)
response = {