add cancel
Some checks failed
Build and Publish / BuildAndDeployAmd64 (push) Successful in 45s
Build and Publish / BuildAndDeployArm64 (push) Has been cancelled

This commit is contained in:
matst80
2025-12-05 08:30:59 +01:00
parent b4ffb9da85
commit ea3eb2f0f3
7 changed files with 172 additions and 52 deletions

View File

@@ -27,6 +27,7 @@ func NewCheckoutMutationRegistry(ctx *CheckoutMutationContext) actor.MutationReg
actor.NewMutation(HandleSetPickupPoint),
actor.NewMutation(HandleRemoveDelivery),
actor.NewMutation(HandleContactDetailsUpdated),
actor.NewMutation(HandlePaymentCancelled),
)
return reg
}

View 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
})
}

View File

@@ -11,13 +11,21 @@ func asPickupPoint(p *messages.PickupPoint, deliveryId uint32) *PickupPoint {
if p == nil {
return nil
}
if p.Address == nil {
return &PickupPoint{
Id: p.Id,
Name: p.Name,
DeliveryId: deliveryId,
}
}
return &PickupPoint{
Id: p.Id,
Name: p.Name,
Address: p.Address,
City: p.City,
Country: p.Country,
Zip: p.Zip,
DeliveryId: deliveryId,
Id: p.Id,
Name: p.Name,
Address: &p.Address.AddressLine1,
City: &p.Address.City,
Zip: &p.Address.Zip,
Country: &p.Address.Country,
}
}

View File

@@ -36,14 +36,7 @@ func HandleSetPickupPoint(g *CheckoutGrain, m *messages.SetPickupPoint) error {
for _, d := range g.Deliveries {
if d.Id == uint32(m.DeliveryId) {
d.PickupPoint = &PickupPoint{
Id: m.PickupPoint.Id,
Name: m.PickupPoint.Name,
Address: m.PickupPoint.Address,
City: m.PickupPoint.City,
Zip: m.PickupPoint.Zip,
Country: m.PickupPoint.Country,
}
d.PickupPoint = asPickupPoint(m.PickupPoint, d.Id)
return nil
}
}