Documentation
¶
Overview ¶
Package models holds the persisted Cashier tables (transactions, subscriptions) and their migrations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Migrations ¶
Migrations creates the Cashier tables. Exposed via the plugin's Migrations() so they run alongside application migrations.
Types ¶
type Purchase ¶ added in v1.6.0
type Purchase struct {
database.Model
Platform string `json:"platform" gorm:"index"` // apple|google
Subject string `json:"subject" gorm:"index"` // user id
ProductID string `json:"product_id" gorm:"index"`
TransactionID string `json:"transaction_id"`
OriginalTransactionID string `json:"original_transaction_id" gorm:"uniqueIndex:idx_purchase_orig"`
Subscription bool `json:"subscription"`
Status string `json:"status" gorm:"index"` // active|expired|canceled|refunded
ExpiresAt *time.Time `json:"expires_at"`
AutoRenewing bool `json:"auto_renewing"`
Environment string `json:"environment"` // production|sandbox
}
Purchase mirrors a verified in-app purchase from Apple or Google.
Like Subscription it is a mirror: the store owns the transaction, and this row is what an access check reads. The stable key is OriginalTransactionID — every renewal of one store subscription shares it, so upserting on it keeps one row per entitlement rather than one per renewal.
type Refund ¶ added in v1.6.0
type Refund struct {
database.Model
Gateway string `json:"gateway" gorm:"index"`
GatewayID string `json:"gateway_id" gorm:"index"` // refund id
PaymentID string `json:"payment_id" gorm:"index"` // the charge it reverses
Subject string `json:"subject" gorm:"index"`
Amount int64 `json:"amount"`
Currency string `json:"currency"`
Status string `json:"status" gorm:"index"` // pending|succeeded|failed
Reason string `json:"reason"`
}
Refund records a reversal against a transaction, across any gateway.
type Subscription ¶
type Subscription struct {
database.Model
Gateway string `json:"gateway" gorm:"index"`
GatewayID string `json:"gateway_id" gorm:"uniqueIndex:idx_sub_gateway_id"` // subscription id
Subject string `json:"subject" gorm:"index"` // user id
Plan string `json:"plan"`
PriceID string `json:"price_id"`
Status string `json:"status" gorm:"index"` // canonical SubscriptionStatus
CustomerID string `json:"customer_id" gorm:"index"`
CurrentPeriodEnd *time.Time `json:"current_period_end"`
TrialEnd *time.Time `json:"trial_end"`
CancelAt *time.Time `json:"cancel_at"` // scheduled cancel at period end
EndsAt *time.Time `json:"ends_at"` // access boundary
CanceledAt *time.Time `json:"canceled_at"`
// RevenueCat-style entitlement context (see cashier.Entitlement).
PeriodType string `json:"period_type"` // trial|intro|normal|promotional|grace
Source string `json:"source"` // purchase|promotional
WillRenew bool `json:"will_renew"`
}
Subscription mirrors a gateway subscription locally for access checks.
It is a mirror, not the source of truth: the gateway owns the billing, and this row is updated from webhooks and verification so an access check is one indexed local read rather than a call out to the provider on every request.
func (Subscription) Active ¶
func (s Subscription) Active() bool
Active reports whether the subscription currently grants access.
A subscription cancelled but paid through the end of the period still grants access until EndsAt: cancelling is not the same as losing access, and revoking on the cancel event rather than the period boundary is a common way to short-change a paying customer.
func (Subscription) TableName ¶
func (Subscription) TableName() string
TableName is the DB table for subscriptions.
type Transaction ¶
type Transaction struct {
database.Model
Gateway string `json:"gateway" gorm:"index"` // stripe|razorpay|payu
GatewayID string `json:"gateway_id" gorm:"index"` // order/session/payment id
Reference string `json:"reference" gorm:"index"` // app order id
Subject string `json:"subject" gorm:"index"` // user id
Plan string `json:"plan"`
Amount int64 `json:"amount"` // smallest currency unit (paise/cents)
Currency string `json:"currency"`
Status string `json:"status" gorm:"index"` // created|paid|failed|refunded
Meta string `json:"meta"` // optional JSON blob
}
Transaction records a single charge/payment across any gateway.
func (Transaction) TableName ¶
func (Transaction) TableName() string
TableName is the DB table for transactions.