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
35 lines
750 B
Go
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
|
|
}
|