mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package form
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/commerce/email"
|
|
"github.com/hanzoai/commerce/models/form"
|
|
"github.com/hanzoai/commerce/models/organization"
|
|
"github.com/hanzoai/commerce/models/submission"
|
|
"github.com/hanzoai/commerce/models/subscriber"
|
|
|
|
. "github.com/hanzoai/commerce/types"
|
|
)
|
|
|
|
var hanzoEmail = email.Email{Address: "[email protected]", Name: "Hanzo"}
|
|
|
|
// Forward email to configured recpeients
|
|
func forward(c context.Context, org *organization.Organization, f *form.Form, s interface{}) {
|
|
if !f.Forward.Enabled {
|
|
return
|
|
}
|
|
|
|
metadata := make(Map)
|
|
|
|
// Determine where to send replies
|
|
replyTo := ""
|
|
|
|
switch v := s.(type) {
|
|
case *subscriber.Subscriber:
|
|
replyTo = v.Email
|
|
metadata = v.Metadata
|
|
case *submission.Submission:
|
|
replyTo = v.Email
|
|
metadata = v.Metadata
|
|
}
|
|
|
|
// Forward form submission
|
|
html := ""
|
|
for k, v := range metadata {
|
|
html += fmt.Sprintf("<b>%s</b>: %s<br><br>", k, v)
|
|
}
|
|
|
|
// Setup email message
|
|
message := email.NewMessage()
|
|
message.Subject = "New submission for form " + f.Name
|
|
message.From = hanzoEmail
|
|
message.AddTos(email.Email{Address: f.Forward.Email, Name: f.Forward.Name})
|
|
message.ReplyTo = email.Email{Address: replyTo}
|
|
message.HTML = html
|
|
email.Send(c, message, nil)
|
|
}
|