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
29 lines
629 B
Go
29 lines
629 B
Go
package sendgrid
|
|
|
|
import (
|
|
"github.com/hanzoai/commerce/log"
|
|
"github.com/hanzoai/commerce/types/email"
|
|
)
|
|
|
|
// Add subscriber to list
|
|
func (api API) Subscribe(list *email.List, sub *email.Subscriber) error {
|
|
c := api.Context
|
|
|
|
// Ensure contact exists
|
|
contact, err := api.UpdateContact(sub)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Add contact to list
|
|
res, err := api.Request("POST", "/v3/contactdb/lists/"+list.Id+"/recipients/"+contact.Id, nil, nil)
|
|
if err != nil {
|
|
return log.Error("Failed to add contact to list: %v", err, c)
|
|
}
|
|
log.Info(res.StatusCode, c)
|
|
log.Info(res.Body, c)
|
|
log.Info(res.Headers, c)
|
|
|
|
return nil
|
|
}
|