2
0
Files
gitcaddy-server/models/monetize/monetize_setting.go
logikonline d1f20f6b46
All checks were successful
Build and Release / Create Release (push) Successful in 0s
Build and Release / Unit Tests (push) Successful in 3m10s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 5m13s
Build and Release / Lint (push) Successful in 5m25s
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Successful in 3m13s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Successful in 8h5m42s
Build and Release / Build Binaries (amd64, darwin, macos) (push) Successful in 7m30s
Build and Release / Build Binaries (arm64, darwin, macos) (push) Successful in 7m55s
Build and Release / Build Binary (linux/arm64) (push) Successful in 7m36s
feat(ci): add repository subscription monetization system
Implement complete subscription monetization system for repositories with Stripe and PayPal integration. Includes:
- Database models and migrations for monetization settings, subscription products, and user subscriptions
- Payment provider abstraction layer with Stripe and PayPal implementations
- Admin UI for configuring payment providers and viewing subscriptions
- Repository settings UI for managing subscription products and tiers
- Subscription checkout flow and webhook handlers for payment events
- Access control to gate repository code behind active subscriptions
2026-01-31 13:37:07 -05:00

64 lines
1.6 KiB
Go

// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT
package monetize
import (
"context"
"code.gitcaddy.com/server/v3/models/db"
)
// Setting stores instance-wide payment provider configuration.
// There is at most one row in this table (ID=1).
// TableName maps to the original migration table name.
func (*Setting) TableName() string { return "monetize_setting" }
type Setting struct {
ID int64 `xorm:"pk autoincr"`
StripeEnabled bool `xorm:"NOT NULL DEFAULT false"`
StripeSecretKey string `xorm:"TEXT"`
StripePublishableKey string `xorm:"TEXT"`
StripeWebhookSecret string `xorm:"TEXT"`
PayPalEnabled bool `xorm:"NOT NULL DEFAULT false"`
PayPalClientID string `xorm:"TEXT"`
PayPalClientSecret string `xorm:"TEXT"`
PayPalWebhookID string `xorm:"VARCHAR(255)"`
PayPalSandbox bool `xorm:"NOT NULL DEFAULT false"`
}
func init() {
db.RegisterModel(new(Setting))
}
// GetSetting returns the singleton payment configuration row.
// If no row exists, returns a zero-value struct (everything disabled).
func GetSetting(ctx context.Context) (*Setting, error) {
s := &Setting{}
has, err := db.GetEngine(ctx).Get(s)
if err != nil {
return nil, err
}
if !has {
return &Setting{}, nil
}
return s, nil
}
// SaveSetting upserts the singleton payment configuration.
func SaveSetting(ctx context.Context, s *Setting) error {
e := db.GetEngine(ctx)
existing := &Setting{}
has, err := e.Get(existing)
if err != nil {
return err
}
if has {
s.ID = existing.ID
_, err = e.ID(s.ID).AllCols().Update(s)
return err
}
_, err = e.Insert(s)
return err
}