add more payment related shit
This commit is contained in:
32
pkg/cart/mutation_payment_completed.go
Normal file
32
pkg/cart/mutation_payment_completed.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cart
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
messages "git.k6n.net/go-cart-actor/pkg/messages"
|
||||
)
|
||||
|
||||
// PaymentStarted registers the beginning of a payment attempt for a cart.
|
||||
// It either upserts the payment entry (based on paymentId) or creates a new one,
|
||||
// marks the cart as having an in-progress payment, and recalculates the PaidInFull flag.
|
||||
func PaymentCompleted(grain *CartGrain, msg *messages.PaymentCompleted) error {
|
||||
if msg == nil {
|
||||
return fmt.Errorf("PaymentStarted: nil payload")
|
||||
}
|
||||
paymentId := msg.PaymentId
|
||||
payment, found := grain.FindPayment(paymentId)
|
||||
if !found {
|
||||
return fmt.Errorf("PaymentStarted: payment not found")
|
||||
}
|
||||
|
||||
payment.ProcessorReference = msg.ProcessorReference
|
||||
payment.Status = PaymentStatusSuccess
|
||||
payment.Amount = msg.Amount
|
||||
payment.Currency = msg.Currency
|
||||
payment.CompletedAt = asPointer(time.Now())
|
||||
|
||||
// maybe update cart status
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user