30 lines
540 B
Go
30 lines
540 B
Go
package checkout
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
messages "git.k6n.net/go-cart-actor/proto/checkout"
|
|
)
|
|
|
|
func asPointer[T any](value T) *T {
|
|
return &value
|
|
}
|
|
|
|
var ErrPaymentNotFound = errors.New("payment not found")
|
|
|
|
func HandlePaymentDeclined(g *CheckoutGrain, m *messages.PaymentDeclined) error {
|
|
|
|
payment, found := g.FindPayment(m.PaymentId)
|
|
if !found {
|
|
return ErrPaymentNotFound
|
|
}
|
|
|
|
payment.CompletedAt = asPointer(time.Now())
|
|
payment.Status = "failed"
|
|
g.PaymentInProgress--
|
|
g.AmountInCentsStarted -= payment.Amount
|
|
|
|
return nil
|
|
}
|