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') const mostRecentOrder = orders.sort(sortOrders)[0] return {order: mostRecentOrder} } 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 ( <>
{count}x | {item.name} |
{order.address.name}
{order.address.street1}
{order.address.street2}
{order.address.city}, {order.address.state}, {order.address.zip}
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.
) } > ) } function parsePaymentTime({payment}){ if(typeof payment.time === 'string') payment.time = DateTime.fromISO(payment.time) return payment.time } function sortTransactions(a,b){ const timeA = parsePaymentTime(a) const timeB = parsePaymentTime(b) return timeB.diff(timeA).as('seconds') } function sortOrders(a,b){ const timePaidA = parsePaymentTime(a.transactions.sort(sortTransactions)[0]) const timePaidB = parsePaymentTime(b.transactions.sort(sortTransactions)[0]) return timePaidB.diff(timePaidA).as('seconds') } function formatMoney(money){ if (money === undefined || money === null) return null; return '$' + (money / 100).toFixed(2) }