Files
go-cart-actor/pkg/cart/mutation_payment_completed.go
matst80 060b3dfbf0
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 36s
Build and Publish / BuildAndDeployArm64 (push) Successful in 3m59s
more changes
2025-12-01 20:15:48 +01:00

34 lines
912 B
Go

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
}