Skip to content

Commit

Permalink
feat: improve shipping and costs display
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaDiotallevi committed Aug 23, 2024
1 parent c935a3f commit aafb1ea
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
6 changes: 3 additions & 3 deletions gatsby/src/pages/shop/checkout/success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ const Success = ({
fetchSession()
}, [sessionId])

type Currency = "eur" | "gbp" | "usd"
type Currency = "eur" | "gbp" | "usd" | "chf" | "nok" | "dkk" | "sek"

const currencyToSymbol: Record<string, string> = {
const currencyToSymbol: Record<Currency, string> = {
eur: "€",
gbp: "£",
usd: "$",
Expand Down Expand Up @@ -131,7 +131,7 @@ const Success = ({
2,
)}
<br></br>
Shipping fee: Free<br></br>
Shipping: Free<br></br>
Discounts: {currencySymbol}
{(
(session.total_details?.amount_discount ||
Expand Down
35 changes: 29 additions & 6 deletions serverless/src/handlers/sendOrderConfirmationEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ export const handler = async (event: SQSEvent): Promise<void> => {

const charge = invoice.charge as Stripe.Charge | null

type Currency =
| "eur"
| "gbp"
| "usd"
| "chf"
| "nok"
| "dkk"
| "sek"

const currencyToSymbol: Record<Currency, string> = {
eur: "€",
gbp: "£",
usd: "$",
chf: "₣", // Switzerland
nok: "kr", // Norway
dkk: "kr", // Denmark
sek: "kr", // Sweden
}

const currencySymbol =
currencyToSymbol[(session?.currency as Currency) || "gbp"]

await sendEmail({
Source: emailSource,
Destination: {
Expand All @@ -73,16 +95,17 @@ export const handler = async (event: SQSEvent): Promise<void> => {
productImageSource: product.images[0] || "",
itemQuantity: session.line_items?.data[0].quantity || "",
amountSubtotal:
`£${((session.amount_subtotal || 0) / 100).toFixed(
2
)}` || "",
`${currencySymbol}${(
(session.amount_subtotal || 0) / 100
).toFixed(2)}` || "",
amountDiscount:
`£${(
`${currencySymbol}${(
(session.total_details?.amount_discount || 0) / 100
).toFixed(2)}` || "",
amountTotal:
${((session.amount_total || 0) / 100).toFixed(2)}` ||
"",
`${currencySymbol}${(
(session.amount_total || 0) / 100
).toFixed(2)}` || "",
receiptPdf: charge?.receipt_url?.replace("?", "/pdf?"),
}),
})
Expand Down
2 changes: 1 addition & 1 deletion serverless/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ Resources:
<h3>Payment summary</h3>
<div>
Subtotal: {{amountSubtotal}}<br>
Shipping fee: Free<br>
Shipping: Free<br>
Discounts: {{amountDiscount}}<br>
Total: {{amountTotal}}
</div>
Expand Down

0 comments on commit aafb1ea

Please sign in to comment.