fix: use merchant id instead of user id
This commit is contained in:
parent
40a52e9134
commit
856ad53b7e
3 changed files with 18 additions and 17 deletions
29
services.py
29
services.py
|
|
@ -35,7 +35,7 @@ async def create_new_order(
|
|||
merchant_public_key: str, data: PartialOrder
|
||||
) -> Optional[PaymentRequest]:
|
||||
merchant = await get_merchant_by_pubkey(merchant_public_key)
|
||||
assert merchant, "Cannot find merchant!"
|
||||
assert merchant, "Cannot find merchant for order!"
|
||||
|
||||
if await get_order(merchant.id, data.id):
|
||||
return None
|
||||
|
|
@ -116,29 +116,31 @@ async def process_nostr_message(msg: str):
|
|||
type, *rest = json.loads(msg)
|
||||
if type.upper() == "EVENT":
|
||||
subscription_id, event = rest
|
||||
subscription_name, merchant_public_key = subscription_id.split(":")
|
||||
_, merchant_public_key = subscription_id.split(":")
|
||||
event = NostrEvent(**event)
|
||||
if event.kind == 4:
|
||||
await _handle_nip04_message(
|
||||
subscription_name, merchant_public_key, event
|
||||
)
|
||||
await _handle_nip04_message(merchant_public_key, event)
|
||||
return
|
||||
except Exception as ex:
|
||||
print("####### bad message", msg)
|
||||
logger.warning(ex)
|
||||
|
||||
|
||||
async def _handle_nip04_message(
|
||||
subscription_name: str, merchant_public_key: str, event: NostrEvent
|
||||
):
|
||||
async def _handle_nip04_message(merchant_public_key: str, event: NostrEvent):
|
||||
merchant = await get_merchant_by_pubkey(merchant_public_key)
|
||||
assert merchant, f"Merchant not found for public key '{merchant_public_key}'"
|
||||
|
||||
clear_text_msg = merchant.decrypt_message(event.content, event.pubkey)
|
||||
|
||||
# print("### clear_text_msg", subscription_name, clear_text_msg)
|
||||
if subscription_name == "direct-messages-in":
|
||||
if event.pubkey == merchant_public_key:
|
||||
assert len(event.tag_values("p")) != 0, "Outgong message has no 'p' tag"
|
||||
clear_text_msg = merchant.decrypt_message(event.content, event.tag_values("p")[0])
|
||||
await _handle_outgoing_dms(event, merchant, clear_text_msg)
|
||||
elif event.has_tag_value("p", merchant_public_key):
|
||||
clear_text_msg = merchant.decrypt_message(event.content, event.pubkey)
|
||||
await _handle_incoming_dms(event, merchant, clear_text_msg)
|
||||
else:
|
||||
await _handle_outgoing_dms(event, merchant, clear_text_msg)
|
||||
logger.warning(f"Bad NIP04 event: '{event.id}'")
|
||||
|
||||
|
||||
async def _handle_incoming_dms(
|
||||
|
|
@ -166,8 +168,7 @@ async def _handle_outgoing_dms(
|
|||
event_id=event.id,
|
||||
event_created_at=event.created_at,
|
||||
message=clear_text_msg, # exclude if json
|
||||
public_key=sent_to[0],
|
||||
incoming=True,
|
||||
public_key=sent_to[0]
|
||||
)
|
||||
await create_direct_message(merchant.id, dm)
|
||||
|
||||
|
|
@ -216,7 +217,7 @@ async def _handle_new_order(order: PartialOrder) -> Optional[str]:
|
|||
wallet = await get_wallet(wallet_id)
|
||||
assert wallet, f"Cannot find wallet for product id: {first_product_id}"
|
||||
|
||||
new_order = await create_new_order(wallet.user, order)
|
||||
new_order = await create_new_order(order.merchant_public_key, order)
|
||||
if new_order:
|
||||
return json.dumps(new_order.dict(), separators=(",", ":"), ensure_ascii=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ async function directMessages(path) {
|
|||
data: function () {
|
||||
return {
|
||||
activePublicKey:
|
||||
'83d07a79496f4cbdc50ca585741a79a2df1fd938cfa449f0fccb0ab7352115dd',
|
||||
'186895a32209c3a92f0efaa7c65c3f8da690c75b952b815718c0d55d3eed821e',
|
||||
messages: [],
|
||||
newMessage: ''
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ async def api_update_zone(
|
|||
status_code=HTTPStatus.NOT_FOUND,
|
||||
detail="Zone does not exist.",
|
||||
)
|
||||
zone = await update_zone(wallet.wallet.user, data)
|
||||
zone = await update_zone(merchant.id, data)
|
||||
assert zone, "Cannot find updated zone"
|
||||
return zone
|
||||
except HTTPException as ex:
|
||||
|
|
@ -201,7 +201,7 @@ async def api_delete_zone(zone_id, wallet: WalletTypeInfo = Depends(require_admi
|
|||
detail="Zone does not exist.",
|
||||
)
|
||||
|
||||
await delete_zone(wallet.wallet.user, zone_id)
|
||||
await delete_zone(merchant.id, zone_id)
|
||||
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue