add more payment related shit
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 37s
Build and Publish / BuildAndDeployArm64 (push) Successful in 4m10s

This commit is contained in:
matst80
2025-12-01 18:35:32 +01:00
parent d23bfe62a1
commit c227870f13
15 changed files with 821 additions and 173 deletions

View File

@@ -0,0 +1,32 @@
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
return nil
}