add more payment related shit
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user