diff --git a/src/app/api/webhooks/saleor/route.ts b/src/app/api/webhooks/saleor/route.ts index e509911..52ccb4b 100644 --- a/src/app/api/webhooks/saleor/route.ts +++ b/src/app/api/webhooks/saleor/route.ts @@ -6,6 +6,8 @@ import { OrderShipped } from "@/emails/OrderShipped"; import { OrderCancelled } from "@/emails/OrderCancelled"; import { OrderPaid } from "@/emails/OrderPaid"; +const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://dev.manoonoils.com"; + interface SaleorWebhookHeaders { "saleor-event": string; "saleor-domain": string; @@ -159,6 +161,7 @@ async function handleOrderConfirmed(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), shippingAddress: formatAddress(order.shippingAddress), + siteUrl: SITE_URL, }), language, idempotencyKey: `order-confirmed/${order.id}`, @@ -175,6 +178,7 @@ async function handleOrderConfirmed(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), shippingAddress: formatAddress(order.shippingAddress), + siteUrl: SITE_URL, }), eventType: "ORDER_CONFIRMED", orderId: order.id, @@ -219,6 +223,7 @@ async function handleOrderFulfilled(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), trackingNumber, trackingUrl, + siteUrl: SITE_URL, }), language, idempotencyKey: `order-fulfilled/${order.id}`, @@ -234,6 +239,7 @@ async function handleOrderFulfilled(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), trackingNumber, trackingUrl, + siteUrl: SITE_URL, }), eventType: "ORDER_FULFILLED", orderId: order.id, @@ -272,6 +278,7 @@ async function handleOrderCancelled(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), reason, + siteUrl: SITE_URL, }), language, idempotencyKey: `order-cancelled/${order.id}`, @@ -287,6 +294,7 @@ async function handleOrderCancelled(order: SaleorOrder) { items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), reason, + siteUrl: SITE_URL, }), eventType: "ORDER_CANCELLED", orderId: order.id, @@ -316,6 +324,7 @@ async function handleOrderFullyPaid(order: SaleorOrder) { customerName, items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), + siteUrl: SITE_URL, }), language, idempotencyKey: `order-paid/${order.id}`, @@ -330,6 +339,7 @@ async function handleOrderFullyPaid(order: SaleorOrder) { customerName, items: parseOrderItems(order.lines, currency), total: formatPrice(order.total.gross.amount, currency), + siteUrl: SITE_URL, }), eventType: "ORDER_FULLY_PAID", orderId: order.id, diff --git a/src/emails/BaseLayout.tsx b/src/emails/BaseLayout.tsx index 6e65f6a..e878b79 100644 --- a/src/emails/BaseLayout.tsx +++ b/src/emails/BaseLayout.tsx @@ -16,6 +16,7 @@ interface BaseLayoutProps { children: React.ReactNode; previewText: string; language: string; + siteUrl: string; } const translations: Record = { @@ -37,7 +38,7 @@ const translations: Record = { }, }; -export function BaseLayout({ children, previewText, language }: BaseLayoutProps) { +export function BaseLayout({ children, previewText, language, siteUrl }: BaseLayoutProps) { const t = translations[language] || translations.en; return ( @@ -48,7 +49,7 @@ export function BaseLayout({ children, previewText, language }: BaseLayoutProps)
ManoonOils + {t.title} {t.greeting.replace("{name}", customerName)} {t.orderCancelled} @@ -124,7 +126,7 @@ export function OrderCancelled({
-
diff --git a/src/emails/OrderConfirmation.tsx b/src/emails/OrderConfirmation.tsx index d0fe0cd..ea117f9 100644 --- a/src/emails/OrderConfirmation.tsx +++ b/src/emails/OrderConfirmation.tsx @@ -17,6 +17,7 @@ interface OrderConfirmationProps { items: OrderItem[]; total: string; shippingAddress?: string; + siteUrl: string; } const translations: Record< @@ -101,11 +102,12 @@ export function OrderConfirmation({ items, total, shippingAddress, + siteUrl, }: OrderConfirmationProps) { const t = translations[language] || translations.en; return ( - + {t.title} {t.greeting.replace("{name}", customerName)} {t.orderReceived} @@ -142,7 +144,7 @@ export function OrderConfirmation({ )}
-
-
diff --git a/src/emails/OrderShipped.tsx b/src/emails/OrderShipped.tsx index 473cd75..51f3f02 100644 --- a/src/emails/OrderShipped.tsx +++ b/src/emails/OrderShipped.tsx @@ -16,6 +16,7 @@ interface OrderShippedProps { items: OrderItem[]; trackingNumber?: string; trackingUrl?: string; + siteUrl: string; } const translations: Record< @@ -80,11 +81,12 @@ export function OrderShipped({ items, trackingNumber, trackingUrl, + siteUrl, }: OrderShippedProps) { const t = translations[language] || translations.en; return ( - + {t.title} {t.greeting.replace("{name}", customerName)} {t.orderShipped} diff --git a/src/lib/saleor/create-webhooks.graphql b/src/lib/saleor/create-webhooks.graphql index 1994060..c69ab62 100644 --- a/src/lib/saleor/create-webhooks.graphql +++ b/src/lib/saleor/create-webhooks.graphql @@ -1,7 +1,11 @@ +# Replace YOUR_STOREFRONT_URL with your actual storefront URL +# Dev: https://dev.manoonoils.com +# Prod: https://manoonoils.com + mutation CreateSaleorWebhooks { orderConfirmedWebhook: webhookCreate(input: { name: "Resend - Order Confirmed" - targetUrl: "https://manoonoils.com/api/webhooks/saleor" + targetUrl: "YOUR_STOREFRONT_URL/api/webhooks/saleor" events: [ORDER_CONFIRMED] isActive: true }) { @@ -20,7 +24,7 @@ mutation CreateSaleorWebhooks { orderPaidWebhook: webhookCreate(input: { name: "Resend - Order Paid" - targetUrl: "https://manoonoils.com/api/webhooks/saleor" + targetUrl: "YOUR_STOREFRONT_URL/api/webhooks/saleor" events: [ORDER_FULLY_PAID] isActive: true }) { @@ -39,7 +43,7 @@ mutation CreateSaleorWebhooks { orderCancelledWebhook: webhookCreate(input: { name: "Resend - Order Cancelled" - targetUrl: "https://manoonoils.com/api/webhooks/saleor" + targetUrl: "YOUR_STOREFRONT_URL/api/webhooks/saleor" events: [ORDER_CANCELLED] isActive: true }) { @@ -58,7 +62,7 @@ mutation CreateSaleorWebhooks { orderFulfilledWebhook: webhookCreate(input: { name: "Resend - Order Fulfilled" - targetUrl: "https://manoonoils.com/api/webhooks/saleor" + targetUrl: "YOUR_STOREFRONT_URL/api/webhooks/saleor" events: [ORDER_FULFILLED] isActive: true }) {