From 5ef3bcbd18c817aab6229e08e48394c87fcd74e6 Mon Sep 17 00:00:00 2001 From: Ashelyn Dawn Date: Mon, 20 Apr 2020 22:34:59 -0600 Subject: [PATCH] Confirmation page --- api/orders.js | 7 +++- pages/store/checkout/complete.js | 72 ++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/api/orders.js b/api/orders.js index a15e3ee..1523112 100644 --- a/api/orders.js +++ b/api/orders.js @@ -6,8 +6,11 @@ const stripe = require('stripe')(process.env.STRIPE_PRIVATE_KEY); const validate = require('./middleware/validators') router.get('/', async (req, res) => { - const orders = await db.order.findAllForSession(req.session.uuid) - res.json(orders) + if(req.user) + // TODO: Write this function + return res.json(await db.order.findAllforUser(req.user.uuid)) + else + return res.json(await db.order.findAllForSession(req.session.uuid)) }) router.use(require('./middleware/ensureCart')) diff --git a/pages/store/checkout/complete.js b/pages/store/checkout/complete.js index 333b1c0..f0683fd 100644 --- a/pages/store/checkout/complete.js +++ b/pages/store/checkout/complete.js @@ -1,4 +1,7 @@ import {DateTime} from 'luxon' +import Link from 'next/link' + +import styles from './style.module.css' CheckoutComplete.getInitialProps = async function({ctx: {query: {session_id}, axios}}){ const {data: orders} = await axios.get('/api/orders') @@ -9,10 +12,67 @@ CheckoutComplete.getInitialProps = async function({ctx: {query: {session_id}, ax } export default function CheckoutComplete({order}){ + const items = order.transactions.map(transaction => transaction.cart.items).flat() + const latestTransaction = order.transactions.sort(sortTransactions)[0] + + let email = null + + if(latestTransaction.payment.stripe) + email = latestTransaction.payment.stripe.reciept_email + return ( -
-      {JSON.stringify(order, null, 2)}
-    
+ <> +

Order Complete

+
+
+

The following items:

+ + + {items.map(({uuid, count, item}) => ( + + + + + ))} + +
{count}x{item.name}
+
+
+

Will be shipped to:

+

{order.address.name}

+

{order.address.street1}

+

{order.address.street2}

+

{order.address.city}, {order.address.state}, {order.address.zip}

+
+
+ { + email + ? ( + <> +

+ Orders typically are shipped within 3-5 business days of purchase. You + will receive an email with a tracking number when your order ships. +

+

+ Your tracking number will be sent to: + {email} + +

+

+ If you do not receive an email within 1 week, + please contact us. In any + correspondence please be sure to include your order number + (#{order.number}). +

+ + ) + : ( +

+ Orders typically are shipped within 3-5 business days of purchase. +

+ ) + } + ) } @@ -35,3 +95,9 @@ function sortOrders(a,b){ return timePaidB.diff(timePaidA).as('seconds') } + +function formatMoney(money){ + if (money === undefined || money === null) return null; + + return '$' + (money / 100).toFixed(2) +}