mirror of
https://github.com/KevinMidboe/planetposen-mail.git
synced 2025-10-29 09:40:32 +00:00
Mail api for sending order confirmation to planetposen customers
This commit is contained in:
63
mail/order_confirmation.go
Normal file
63
mail/order_confirmation.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type OrderMailSender interface {
|
||||
SendOrderConfirmation(ctx context.Context, record Record) error
|
||||
}
|
||||
|
||||
type Product struct {
|
||||
Name string
|
||||
Image string
|
||||
Description string
|
||||
Quantity int
|
||||
Price float32
|
||||
Currency string
|
||||
}
|
||||
|
||||
type OrderConfirmationData struct {
|
||||
// PageTitle string
|
||||
Email string
|
||||
OrderId string
|
||||
Products []Product
|
||||
}
|
||||
|
||||
type EmailTemplateData struct {
|
||||
PageTitle string
|
||||
OrderId string
|
||||
Products []Product
|
||||
}
|
||||
|
||||
type OrderConfirmationEmailData struct {
|
||||
Subject string
|
||||
FromName string
|
||||
FromEmail string
|
||||
ToEmail string
|
||||
Markup string
|
||||
}
|
||||
|
||||
type Record struct {
|
||||
Email string
|
||||
// FullName string
|
||||
Status string
|
||||
OrderConfirmationEmailData OrderConfirmationEmailData
|
||||
}
|
||||
|
||||
func OrderConfirmation(payload OrderConfirmationData) (*OrderConfirmationEmailData, error) {
|
||||
var emailTemplate EmailTemplateData
|
||||
emailTemplate.PageTitle = "Planetposen purchase"
|
||||
emailTemplate.OrderId = payload.OrderId
|
||||
emailTemplate.Products = payload.Products
|
||||
|
||||
orderConfirmationEmailData := buildOrderConfirmation(emailTemplate)
|
||||
if orderConfirmationEmailData == nil {
|
||||
return nil, fmt.Errorf("couldn't build order confirmation template for orderId %s", payload.OrderId)
|
||||
}
|
||||
|
||||
orderConfirmationEmailData.ToEmail = payload.Email
|
||||
|
||||
return orderConfirmationEmailData, nil
|
||||
}
|
||||
Reference in New Issue
Block a user