Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions data/purchase.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@ import (

// Purchase defines a set of keys for a purchase event.
type Purchase struct {
// Type defines a unique key.
// This help allow us to create the create when we only have the json representation of this data
Type events.EventObjectType `bson:"objectType" json:"objectType"`

App events.App `bson:"app" json:"app"`
Workspace events.Workspace `bson:"workspace" json:"workspace"`

Pricing OneTimePricing `bson:"pricing" json:"pricing"`

// BoughtAt defines when the app was purchased
BoughtAt time.Time `bson:"boughtAt" json:"boughtAt"`

// IsSelfManaged tells us whether the purchase is managed by the user or externally managed
IsSelfManaged bool `bson:"isSelfManaged" json:"isSelfManaged"`

// IsBundle tells us whether the purchase is a bundle
IsBundle bool `bson:"isBundle" json:"isBundle"`

// FromBundle defines if the app is inside a bundle and this event was triggered from a bundle
FromBundle bool `bson:"fromBundle" json:"fromBundle"`

// FromBundleID indicates which bundle id triggered this purchase event for the app
FromBundleID string `bson:"fromBundleId,omitempty" json:"fromBundleId,omitempty"`
// objectType defines a unique key.
// This helps allow us to create the create when we only have the JSON representation of this data.
ObjectType events.EventObjectType `bson:"objectType" json:"objectType"`
App events.App `bson:"app" json:"app"`
Workspace events.Workspace `bson:"workspace" json:"workspace"`
Pricing OneTimePricing `bson:"pricing" json:"pricing"`
BoughtAt time.Time `bson:"boughtAt" json:"boughtAt"`
IsSelfManaged bool `bson:"isSelfManaged" json:"isSelfManaged"`
IsBundle bool `bson:"isBundle" json:"isBundle"`
FromBundle bool `bson:"fromBundle" json:"fromBundle"`
FromBundleID string `bson:"fromBundleID,omitempty" json:"fromBundleID,omitempty"`
}

// OneTimePricing defines the pricing and fields for a purchase
// There is no way to have different tiers for an one time purchase
// OneTimePricing defines the pricing and fields for a purchase.
// There is no way to have different tiers for a one-time purchase.
type OneTimePricing struct {
Price float32 `bson:"price" json:"price"`
}

// SetPurchaseTime sets the BoughtAt field with the specified time in the local timezone.
func (p *Purchase) SetPurchaseTime(t time.Time) {
p.BoughtAt = t
}

// GetPurchaseTime returns the BoughtAt field as a time.Time value in the local timezone.
func (p *Purchase) GetPurchaseTime() time.Time {
return p.BoughtAt
}