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

@@ -1,21 +1,26 @@
package cart
import (
"errors"
"time"
messages "git.k6n.net/go-cart-actor/pkg/messages"
)
func asPointer[T any](value T) *T {
return &value
}
var ErrPaymentNotFound = errors.New("payment not found")
func PaymentDeclined(grain *CartGrain, req *messages.PaymentDeclined) error {
grain.PaymentStatus = "declined"
grain.PaymentDeclinedNotices = append(grain.PaymentDeclinedNotices, Notice{
Timestamp: time.Now(),
Message: req.Message,
Code: req.Code,
})
// Optionally clear checkout order if in progress
if grain.CheckoutOrderId != "" {
grain.CheckoutOrderId = ""
payment, found := grain.FindPayment(req.PaymentId)
if !found {
return ErrPaymentNotFound
}
payment.CompletedAt = asPointer(time.Now())
payment.Status = PaymentStatusFailed
return nil
}