add cancel
This commit is contained in:
@@ -27,6 +27,7 @@ func NewCheckoutMutationRegistry(ctx *CheckoutMutationContext) actor.MutationReg
|
||||
actor.NewMutation(HandleSetPickupPoint),
|
||||
actor.NewMutation(HandleRemoveDelivery),
|
||||
actor.NewMutation(HandleContactDetailsUpdated),
|
||||
actor.NewMutation(HandlePaymentCancelled),
|
||||
)
|
||||
return reg
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user