package cart import ( "fmt" "time" messages "git.k6n.net/go-cart-actor/pkg/messages" ) // PaymentStarted registers the beginning of a payment attempt for a cart. // It either upserts the payment entry (based on paymentId) or creates a new one, // marks the cart as having an in-progress payment, and recalculates the PaidInFull flag. func PaymentCompleted(grain *CartGrain, msg *messages.PaymentCompleted) error { if msg == nil { return fmt.Errorf("PaymentStarted: nil payload") } paymentId := msg.PaymentId payment, found := grain.FindPayment(paymentId) if !found { return fmt.Errorf("PaymentStarted: payment not found") } payment.ProcessorReference = msg.ProcessorReference payment.Status = PaymentStatusSuccess payment.Amount = msg.Amount payment.Currency = msg.Currency payment.CompletedAt = asPointer(time.Now()) // maybe update cart status grain.PaymentInProgress-- return nil }