Files
commerce/api/checkout/null/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

35 lines
750 B
Go

package null
import (
"errors"
"github.com/hanzoai/commerce/models/order"
"github.com/hanzoai/commerce/models/organization"
"github.com/hanzoai/commerce/models/payment"
)
var FailedToCaptureCharge = errors.New("Failed to capture charge")
func Capture(org *organization.Organization, ord *order.Order) (*order.Order, []*payment.Payment, error) {
db := ord.Datastore()
payments := make([]*payment.Payment, 0)
_, err := payment.Query(db).Ancestor(ord.Key()).GetAll(&payments)
if err != nil {
return nil, payments, err
}
// Capture any uncaptured payments
for _, p := range payments {
if !p.Captured {
// Update payment
p.Captured = true
p.Status = payment.Paid
p.Init(db)
p.Put()
}
}
return ord, payments, nil
}