diff --git a/pkg/cart/cart-grain.go b/pkg/cart/cart-grain.go index 33e1b7c..37edbe1 100644 --- a/pkg/cart/cart-grain.go +++ b/pkg/cart/cart-grain.go @@ -90,32 +90,37 @@ type Marking struct { } type CartGrain struct { - mu sync.RWMutex - lastItemId uint32 - lastDeliveryId uint32 - lastVoucherId uint32 - lastAccess time.Time - lastChange time.Time // unix seconds of last successful mutation (replay sets from event ts) - userId string - InventoryReserved bool `json:"inventoryReserved"` - Id CartId `json:"id"` - Items []*CartItem `json:"items"` - TotalPrice *Price `json:"totalPrice"` - TotalDiscount *Price `json:"totalDiscount"` - Deliveries []*CartDelivery `json:"deliveries,omitempty"` - Processing bool `json:"processing"` - PaymentInProgress bool `json:"paymentInProgress"` - OrderReference string `json:"orderReference,omitempty"` - PaymentStatus string `json:"paymentStatus,omitempty"` - Vouchers []*Voucher `json:"vouchers,omitempty"` - Notifications []CartNotification `json:"cartNotification,omitempty"` - SubscriptionDetails map[string]*SubscriptionDetails `json:"subscriptionDetails,omitempty"` - PaymentDeclinedNotices []Notice `json:"paymentDeclinedNotices,omitempty"` - ConfirmationViewCount int `json:"confirmationViewCount,omitempty"` - ConfirmationLastViewedAt time.Time `json:"confirmationLastViewedAt,omitempty"` - CheckoutOrderId string `json:"checkoutOrderId,omitempty"` - CheckoutStatus string `json:"checkoutStatus,omitempty"` - CheckoutCountry string `json:"checkoutCountry,omitempty"` + mu sync.RWMutex + lastItemId uint32 + lastDeliveryId uint32 + lastVoucherId uint32 + lastAccess time.Time + lastChange time.Time // unix seconds of last successful mutation (replay sets from event ts) + userId string + InventoryReserved bool `json:"inventoryReserved"` + Id CartId `json:"id"` + Items []*CartItem `json:"items"` + TotalPrice *Price `json:"totalPrice"` + TotalDiscount *Price `json:"totalDiscount"` + Deliveries []*CartDelivery `json:"deliveries,omitempty"` + Processing bool `json:"processing"` + PaymentInProgress bool `json:"paymentInProgress"` + OrderReference string `json:"orderReference,omitempty"` + PaymentStatus string `json:"paymentStatus,omitempty"` + Vouchers []*Voucher `json:"vouchers,omitempty"` + Notifications []CartNotification `json:"cartNotification,omitempty"` + SubscriptionDetails map[string]*SubscriptionDetails `json:"subscriptionDetails,omitempty"` + PaymentDeclinedNotices []Notice `json:"paymentDeclinedNotices,omitempty"` + Confirmation *ConfirmationStatus `json:"confirmation,omitempty"` + CheckoutOrderId string `json:"checkoutOrderId,omitempty"` + CheckoutStatus string `json:"checkoutStatus,omitempty"` + CheckoutCountry string `json:"checkoutCountry,omitempty"` +} + +type ConfirmationStatus struct { + Code *string `json:"code,omitempty"` + ViewCount int `json:"viewCount"` + LastViewedAt time.Time `json:"lastViewedAt"` } type Voucher struct { diff --git a/pkg/cart/mutation_confirmation_viewed.go b/pkg/cart/mutation_confirmation_viewed.go index 450aa80..6718414 100644 --- a/pkg/cart/mutation_confirmation_viewed.go +++ b/pkg/cart/mutation_confirmation_viewed.go @@ -7,7 +7,15 @@ import ( ) func ConfirmationViewed(grain *CartGrain, req *messages.ConfirmationViewed) error { - grain.ConfirmationViewCount++ - grain.ConfirmationLastViewedAt = time.Now() + if grain.Confirmation == nil { + grain.Confirmation = &ConfirmationStatus{ + ViewCount: 1, + LastViewedAt: time.Now(), + } + } else { + grain.Confirmation.ViewCount++ + grain.Confirmation.LastViewedAt = time.Now() + } + return nil }