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 fixtures
|
|
|
|
import (
|
|
"github.com/zap-proto/zip"
|
|
|
|
"github.com/hanzoai/commerce/models/order"
|
|
"github.com/hanzoai/commerce/models/types/country"
|
|
"github.com/hanzoai/commerce/models/types/currency"
|
|
"github.com/hanzoai/commerce/models/types/productcachedvalues"
|
|
|
|
. "github.com/hanzoai/commerce/models/lineitem"
|
|
)
|
|
|
|
var Order = New("order", func(c *zip.Ctx) *order.Order {
|
|
db := getNamespaceDb(c)
|
|
|
|
u := UserCustomer(c)
|
|
p := Product(c)
|
|
Coupon(c)
|
|
|
|
ord := order.New(db)
|
|
ord.UserId = u.Id()
|
|
ord.GetOrCreate("UserId=", ord.UserId)
|
|
|
|
ord.ShippingAddress.Name = "Jackson Shirts"
|
|
ord.ShippingAddress.Line1 = "1234 Kansas Drive"
|
|
ord.ShippingAddress.City = "Overland Park"
|
|
|
|
ctr, _ := country.FindByISO3166_2("US")
|
|
sd, _ := ctr.FindSubDivision("Kansas")
|
|
|
|
ord.ShippingAddress.State = sd.Code
|
|
ord.ShippingAddress.Country = ctr.Codes.Alpha2
|
|
ord.ShippingAddress.PostalCode = "66212"
|
|
|
|
ord.Currency = currency.USD
|
|
ord.Items = []LineItem{
|
|
LineItem{
|
|
ProductCachedValues: productcachedvalues.ProductCachedValues{
|
|
Price: currency.Cents(100),
|
|
},
|
|
ProductId: p.Id(),
|
|
Quantity: 20,
|
|
},
|
|
}
|
|
|
|
ord.CouponCodes = []string{"SUCH-COUPON", "FREE-DOGE"}
|
|
ord.UpdateAndTally(nil)
|
|
ord.MustPut()
|
|
|
|
return ord
|
|
})
|