Files
commerce/api/checkout/tasks/capture.go
zeekay 1943f1c093 Hanzo Commerce
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
2026-09-23 21:52:16 -07:00

62 lines
1.8 KiB
Go

package tasks
import (
"context"
"github.com/hanzoai/commerce/api/checkout/util"
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/delay"
"github.com/hanzoai/commerce/email"
"github.com/hanzoai/commerce/models/order"
"github.com/hanzoai/commerce/models/organization"
"github.com/hanzoai/commerce/models/user"
)
var CaptureAsync = delay.Func("capture-async", func(ctx context.Context, orgId string, ordId string) {
db := datastore.New(ctx)
org := organization.New(db)
org.MustGetById(orgId)
nsdb := datastore.NewNamespaced(org.Namespaced(ctx)) // per-org order/user store (Red MED-1)
ord := order.New(nsdb)
usr := user.New(nsdb)
ord.MustGetById(ordId)
usr.MustGetById(ord.UserId)
if !ord.Test || usr.Test {
util.UpdateMailchimp(ctx, org, ord, usr)
}
// payments := make([]*payment.Payment, 0)
// if _, err := payment.Query(nsdb).Ancestor(ord.Key()).GetAll(payments); err != nil {
// log.Error("Unable to find payments associated with order '%s'", ord.Id())
// }
// sendOrderConfirmation(ctx, org, ord, payments[0].Buyer)
// saveRedemptions(ctx, ord)
// saveReferral(ctx, org, ord)
// updateCart(ctx, ord)
// updateStats(ctx, org, ord, payments)
// updateMailchimp(ctx, org, ord)
})
var SendOrderConfirmation = delay.Func("send-order-confirmation", func(ctx context.Context, orgId, ordId, emailAddress, firstName, lastName string) {
db := datastore.New(ctx)
org := organization.New(db)
org.MustGetById(orgId)
nsdb := datastore.NewNamespaced(org.Namespaced(ctx)) // per-org order/user store (Red MED-1)
ord := order.New(nsdb)
ord.MustGetById(ordId)
// Send Create user
usr := new(user.User)
usr.Email = emailAddress
usr.FirstName = firstName
usr.LastName = lastName
usr.Init(ord.Datastore())
email.SendOrderConfirmation(ctx, org, ord, usr)
})