package mailer import ( "bytes" "context" "encoding/json" "fmt" htmltemplate "html/template" "io" "net/http" "net/url" "strings" texttemplate "text/template" "time" "royal-pop-backend/internal/config" "royal-pop-backend/internal/orders" ) const resendEndpoint = "https://api.resend.com/emails" type ResendMailer struct { apiKey string from string replyTo string storefrontURL string httpClient *http.Client } type resendEmailRequest struct { From string `json:"from"` To []string `json:"to"` Subject string `json:"subject"` HTML string `json:"html,omitempty"` Text string `json:"text,omitempty"` ReplyTo string `json:"reply_to,omitempty"` } type shippedEmailTemplateData struct { FirstName string OrderID string ShippedDate string ShippingCarrier string TrackingNumber string TrackingURL string OrderImageURL string OrderImageAlt string Items []string StorefrontURL string } type cancelledEmailTemplateData struct { FirstName string OrderID string CancelledDate string RefundAmount string OrderImageURL string OrderImageAlt string Items []string StorefrontURL string } type paidEmailTemplateData struct { FirstName string OrderID string PaidDate string PaidAmount string OrderImageURL string OrderImageAlt string Items []string StorefrontURL string } type createdEmailTemplateData struct { OrderID string CreatedDate string OrderAmount string CustomerName string CustomerEmail string OrderImageURL string OrderImageAlt string Items []string StorefrontURL string ClientDashboardURL string } type deliveredEmailTemplateData struct { FirstName string OrderID string DeliveredDate string OrderImageURL string OrderImageAlt string Items []string StorefrontURL string } var shippedEmailHTMLTemplate = htmltemplate.Must(htmltemplate.New("shipped-email-html").Parse(`
Hi {{.FirstName}},
Your Royal Pop order is now on the way.
Order reference: {{.OrderID}}
Shipped: {{.ShippedDate}}
Carrier: {{.ShippingCarrier}}
Tracking number: {{.TrackingNumber}}
In this shipment
If you need anything, just reply to this email and we’ll help.
Royal Pop
Hi {{.FirstName}},
Your Royal Pop order has now been cancelled.
Order reference: {{.OrderID}}
Cancelled: {{.CancelledDate}}
We were not able to complete this order because some of the information provided was missing or invalid.
A refund of {{.RefundAmount}} has now been issued to the original payment method. Depending on your bank or card provider, the refund may take a few business days to appear.
This cancelled order included
If you would still like the order, just reply to this email and we’ll help you sort it out.
Royal Pop
Hi {{.FirstName}},
We’ve received your Royal Pop order and your payment has gone through successfully.
Order reference: {{.OrderID}}
Paid: {{.PaidDate}}
Amount received: {{.PaidAmount}}
Your order details
We’ll email you again as soon as your order has been packed and shipped.
If you need anything in the meantime, just reply to this email and we’ll help.
Royal Pop
Hi,
A new paid Royal Pop order has been created and is ready for review in the client dashboard.
Order reference: {{.OrderID}}
Created: {{.CreatedDate}}
Order total: {{.OrderAmount}}
Customer: {{.CustomerName}}
Customer email: {{.CustomerEmail}}
Your order details
Use the dashboard to review the order, check stock, and continue fulfilment.
If you need anything, just reply to this email and we’ll help.
Royal Pop
Hi {{.FirstName}},
Your Royal Pop order has been delivered.
Order reference: {{.OrderID}}
Delivered: {{.DeliveredDate}}
Your delivered order
Thank you for your order — we hope you love it.
If you need anything at all, just reply to this email and we’ll help.
Royal Pop