add cancel
This commit is contained in:
30
pkg/checkout/mutation_cancel_payment.go
Normal file
30
pkg/checkout/mutation_cancel_payment.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package checkout
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"slices"
|
||||
|
||||
messages "git.k6n.net/go-cart-actor/proto/checkout"
|
||||
)
|
||||
|
||||
func HandlePaymentCancelled(g *CheckoutGrain, m *messages.PaymentDeclined) error {
|
||||
|
||||
payment, found := g.FindPayment(m.PaymentId)
|
||||
if !found {
|
||||
return ErrPaymentNotFound
|
||||
}
|
||||
if payment.CompletedAt != nil {
|
||||
return errors.New("payment already completed")
|
||||
}
|
||||
g.PaymentInProgress--
|
||||
g.AmountInCentsStarted -= payment.Amount
|
||||
g.Payments = removePayment(g.Payments, payment.PaymentId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removePayment(payment []*Payment, s string) []*Payment {
|
||||
return slices.DeleteFunc(payment, func(p *Payment) bool {
|
||||
return p.PaymentId == s
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user