refactor/checkout (#8)
Co-authored-by: matst80 <mats.tornberg@gmail.com> Reviewed-on: #8 Co-authored-by: Mats Törnberg <mats@tornberg.me> Co-committed-by: Mats Törnberg <mats@tornberg.me>
This commit was merged in pull request #8.
This commit is contained in:
37
pkg/checkout/mutation_payment_completed.go
Normal file
37
pkg/checkout/mutation_payment_completed.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package checkout
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
messages "git.k6n.net/go-cart-actor/proto/checkout"
|
||||
)
|
||||
|
||||
// PaymentCompleted registers the completion of a payment for a checkout.
|
||||
func HandlePaymentCompleted(g *CheckoutGrain, m *messages.PaymentCompleted) error {
|
||||
if m == nil {
|
||||
return fmt.Errorf("PaymentCompleted: nil payload")
|
||||
}
|
||||
paymentId := m.PaymentId
|
||||
payment, found := g.FindPayment(paymentId)
|
||||
|
||||
if !found {
|
||||
return fmt.Errorf("PaymentCompleted: payment not found")
|
||||
}
|
||||
|
||||
payment.ProcessorReference = m.ProcessorReference
|
||||
payment.Status = PaymentStatusSuccess
|
||||
payment.Amount = m.Amount
|
||||
payment.Currency = m.Currency
|
||||
payment.CompletedAt = &time.Time{}
|
||||
if m.CompletedAt != nil {
|
||||
*payment.CompletedAt = m.CompletedAt.AsTime()
|
||||
} else {
|
||||
*payment.CompletedAt = time.Now()
|
||||
}
|
||||
|
||||
// Update checkout status
|
||||
g.PaymentInProgress--
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user