feat: basic order handling

This commit is contained in:
Vlad Stan 2023-07-10 14:54:05 +03:00
parent e97a327aec
commit 6a093c8890
4 changed files with 222 additions and 11 deletions

View file

@ -117,12 +117,8 @@
</q-card-section>
<q-separator />
<q-card-actions align="right">
<q-btn @click="requestInvoice(cart)" flat color="primary">
<q-btn @click="placeOrder()" flat color="primary">
Place Order
</q-btn>
</q-card-actions>

View file

@ -5,7 +5,7 @@ async function shoppingCartCheckout(path) {
name: 'shopping-cart-checkout',
template,
props: ['cart', 'stall'],
props: ['cart', 'stall', 'customer-pubkey'],
data: function () {
return {
paymentMethod: 'ln',
@ -58,9 +58,53 @@ async function shoppingCartCheckout(path) {
selectShippingZone: function (zone) {
this.shippingZone = zone
},
requestInvoice: function () {
}
async placeOrder() {
console.log('### placeOrder cart', this.cart)
console.log('### placeOrder stal', this.stall)
if (!this.shippingZone) {
this.$q.notify({
timeout: 5000,
type: 'warning',
message: 'Please select a shipping zone!',
})
return
}
if (!this.customerPubkey) {
this.$emit('login-required')
return
}
const order = {
address: this.contactData.address,
message: this.contactData.message,
contact: {
nostr: this.customerPubkey,
email: this.contactData.email
},
items: Array.from(this.cart.products, p => {
return { product_id: p.id, quantity: p.orderedQuantity }
}),
shipping_id: this.shippingZone.id,
type: 0
}
const created_at = Math.floor(Date.now() / 1000)
order.id = await hash(
[this.customerPubkey, created_at, JSON.stringify(order)].join(':')
)
const event = {
...(await NostrTools.getBlankEvent()),
kind: 4,
created_at,
tags: [['p', this.stall.pubkey]],
pubkey: this.customerPubkey
}
this.$emit('place-order', { event, order })
},
},
created() {
console.log('### shoppingCartCheckout', this.stall)