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
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
49 lines
2.0 KiB
Go
49 lines
2.0 KiB
Go
// Copyright 2026 MarketAlly. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package monetize
|
|
|
|
import "context"
|
|
|
|
// ProviderType identifies a payment provider.
|
|
type ProviderType string
|
|
|
|
const (
|
|
ProviderStripe ProviderType = "stripe"
|
|
ProviderPayPal ProviderType = "paypal"
|
|
)
|
|
|
|
// SubscriptionResult holds the IDs returned after creating a subscription.
|
|
type SubscriptionResult struct {
|
|
ProviderSubscriptionID string // Stripe subscription ID or PayPal subscription ID
|
|
ClientSecret string // Stripe PaymentIntent client_secret for frontend confirmation
|
|
}
|
|
|
|
// OneTimePaymentResult holds the IDs returned after creating a one-time payment.
|
|
type OneTimePaymentResult struct {
|
|
ProviderPaymentID string // Stripe PaymentIntent ID or PayPal order ID
|
|
ClientSecret string // Stripe PaymentIntent client_secret for frontend confirmation
|
|
ApprovalURL string // PayPal approval URL (empty for Stripe)
|
|
}
|
|
|
|
// PaymentProvider defines the interface for payment integrations.
|
|
type PaymentProvider interface {
|
|
// CreateSubscription creates a recurring subscription for the given customer/price.
|
|
// customerEmail is used to find or create the customer on the provider side.
|
|
// stripePriceID or paypalPlanID from the product is used.
|
|
CreateSubscription(ctx context.Context, customerEmail, providerPriceID string, metadata map[string]string) (*SubscriptionResult, error)
|
|
|
|
// CreateOneTimePayment creates a one-time payment (for lifetime access).
|
|
CreateOneTimePayment(ctx context.Context, customerEmail string, amountCents int64, currency string, metadata map[string]string) (*OneTimePaymentResult, error)
|
|
|
|
// CancelSubscription cancels an active subscription by its provider ID.
|
|
CancelSubscription(ctx context.Context, providerSubscriptionID string) error
|
|
|
|
// VerifyWebhookSignature verifies the webhook payload signature.
|
|
// Returns the raw event payload if valid.
|
|
VerifyWebhookSignature(payload []byte, signature string) ([]byte, error)
|
|
|
|
// Type returns the provider type.
|
|
Type() ProviderType
|
|
}
|