From: Ahmad Khalifa <ahmad@khalifa.ws>
Subject: Disable stripe depend as not in debian
Forwarded: not-needed
Last-Update: 2024-12-13

Functionally takes out dependency and command line arguments
for anything stripe/payment related due to missing package:
- github.com/stripe/stripe-go

This functionality is critical to ntfy.sh so unlikely to be removed
and the changes are everywhere. For now leaving patch debian-only
to see how often it needs repatching.

---
 cmd/serve.go                   |   28 +++++++++++++--------------
 server/server.go               |   42 ++++++++++++++++++++---------------------
 server/server_account.go       |   12 +++++------
 server/server_account_test.go  |    1 
 server/server_payments.go      |    2 +
 server/server_payments_test.go |    1 
 user/manager.go                |    6 ++---
 user/manager_test.go           |    1 
 user/types.go                  |    6 ++---
 9 files changed, 52 insertions(+), 47 deletions(-)

--- a/user/manager.go
+++ b/user/manager.go
@@ -7,7 +7,7 @@
 	"errors"
 	"fmt"
 	"github.com/mattn/go-sqlite3"
-	"github.com/stripe/stripe-go/v74"
+	// "github.com/stripe/stripe-go/v74"
 	"golang.org/x/crypto/bcrypt"
 	"heckel.io/ntfy/v2/log"
 	"heckel.io/ntfy/v2/util"
@@ -1030,8 +1030,8 @@
 		Billing: &Billing{
 			StripeCustomerID:            stripeCustomerID.String,                                          // May be empty
 			StripeSubscriptionID:        stripeSubscriptionID.String,                                      // May be empty
-			StripeSubscriptionStatus:    stripe.SubscriptionStatus(stripeSubscriptionStatus.String),       // May be empty
-			StripeSubscriptionInterval:  stripe.PriceRecurringInterval(stripeSubscriptionInterval.String), // May be empty
+			StripeSubscriptionStatus:    string(stripeSubscriptionStatus.String),                          // May be empty
+			StripeSubscriptionInterval:  string(stripeSubscriptionInterval.String),                        // May be empty
 			StripeSubscriptionPaidUntil: time.Unix(stripeSubscriptionPaidUntil.Int64, 0),                  // May be zero
 			StripeSubscriptionCancelAt:  time.Unix(stripeSubscriptionCancelAt.Int64, 0),                   // May be zero
 		},
--- a/user/types.go
+++ b/user/types.go
@@ -2,7 +2,7 @@
 
 import (
 	"errors"
-	"github.com/stripe/stripe-go/v74"
+	// "github.com/stripe/stripe-go/v74"
 	"heckel.io/ntfy/v2/log"
 	"net/netip"
 	"regexp"
@@ -139,8 +139,8 @@
 type Billing struct {
 	StripeCustomerID            string
 	StripeSubscriptionID        string
-	StripeSubscriptionStatus    stripe.SubscriptionStatus
-	StripeSubscriptionInterval  stripe.PriceRecurringInterval
+	StripeSubscriptionStatus    string
+	StripeSubscriptionInterval  string
 	StripeSubscriptionPaidUntil time.Time
 	StripeSubscriptionCancelAt  time.Time
 }
--- a/cmd/serve.go
+++ b/cmd/serve.go
@@ -5,7 +5,7 @@
 import (
 	"errors"
 	"fmt"
-	"github.com/stripe/stripe-go/v74"
+	// "github.com/stripe/stripe-go/v74"
 	"github.com/urfave/cli/v2"
 	"github.com/urfave/cli/v2/altsrc"
 	"heckel.io/ntfy/v2/log"
@@ -89,8 +89,8 @@
 	altsrc.NewStringFlag(&cli.StringFlag{Name: "visitor-email-limit-replenish", Aliases: []string{"visitor_email_limit_replenish"}, EnvVars: []string{"NTFY_VISITOR_EMAIL_LIMIT_REPLENISH"}, Value: util.FormatDuration(server.DefaultVisitorEmailLimitReplenish), Usage: "interval at which burst limit is replenished (one per x)"}),
 	altsrc.NewBoolFlag(&cli.BoolFlag{Name: "visitor-subscriber-rate-limiting", Aliases: []string{"visitor_subscriber_rate_limiting"}, EnvVars: []string{"NTFY_VISITOR_SUBSCRIBER_RATE_LIMITING"}, Value: false, Usage: "enables subscriber-based rate limiting"}),
 	altsrc.NewBoolFlag(&cli.BoolFlag{Name: "behind-proxy", Aliases: []string{"behind_proxy", "P"}, EnvVars: []string{"NTFY_BEHIND_PROXY"}, Value: false, Usage: "if set, use X-Forwarded-For header to determine visitor IP address (for rate limiting)"}),
-	altsrc.NewStringFlag(&cli.StringFlag{Name: "stripe-secret-key", Aliases: []string{"stripe_secret_key"}, EnvVars: []string{"NTFY_STRIPE_SECRET_KEY"}, Value: "", Usage: "key used for the Stripe API communication, this enables payments"}),
-	altsrc.NewStringFlag(&cli.StringFlag{Name: "stripe-webhook-key", Aliases: []string{"stripe_webhook_key"}, EnvVars: []string{"NTFY_STRIPE_WEBHOOK_KEY"}, Value: "", Usage: "key required to validate the authenticity of incoming webhooks from Stripe"}),
+	// altsrc.NewStringFlag(&cli.StringFlag{Name: "stripe-secret-key", Aliases: []string{"stripe_secret_key"}, EnvVars: []string{"NTFY_STRIPE_SECRET_KEY"}, Value: "", Usage: "key used for the Stripe API communication, this enables payments"}),
+	// altsrc.NewStringFlag(&cli.StringFlag{Name: "stripe-webhook-key", Aliases: []string{"stripe_webhook_key"}, EnvVars: []string{"NTFY_STRIPE_WEBHOOK_KEY"}, Value: "", Usage: "key required to validate the authenticity of incoming webhooks from Stripe"}),
 	altsrc.NewStringFlag(&cli.StringFlag{Name: "billing-contact", Aliases: []string{"billing_contact"}, EnvVars: []string{"NTFY_BILLING_CONTACT"}, Value: "", Usage: "e-mail or website to display in upgrade dialog (only if payments are enabled)"}),
 	altsrc.NewBoolFlag(&cli.BoolFlag{Name: "enable-metrics", Aliases: []string{"enable_metrics"}, EnvVars: []string{"NTFY_ENABLE_METRICS"}, Value: false, Usage: "if set, Prometheus metrics are exposed via the /metrics endpoint"}),
 	altsrc.NewStringFlag(&cli.StringFlag{Name: "metrics-listen-http", Aliases: []string{"metrics_listen_http"}, EnvVars: []string{"NTFY_METRICS_LISTEN_HTTP"}, Usage: "ip:port used to expose the metrics endpoint (implicitly enables metrics)"}),
@@ -186,8 +186,8 @@
 	visitorEmailLimitBurst := c.Int("visitor-email-limit-burst")
 	visitorEmailLimitReplenishStr := c.String("visitor-email-limit-replenish")
 	behindProxy := c.Bool("behind-proxy")
-	stripeSecretKey := c.String("stripe-secret-key")
-	stripeWebhookKey := c.String("stripe-webhook-key")
+	// stripeSecretKey := c.String("stripe-secret-key")
+	// stripeWebhookKey := c.String("stripe-webhook-key")
 	billingContact := c.String("billing-contact")
 	metricsListenHTTP := c.String("metrics-listen-http")
 	enableMetrics := c.Bool("enable-metrics") || metricsListenHTTP != ""
@@ -291,12 +291,12 @@
 		return errors.New("if upstream-base-url is set, base-url must also be set")
 	} else if upstreamBaseURL != "" && baseURL != "" && baseURL == upstreamBaseURL {
 		return errors.New("base-url and upstream-base-url cannot be identical, you'll likely want to set upstream-base-url to https://ntfy.sh, see https://ntfy.sh/docs/config/#ios-instant-notifications")
-	} else if authFile == "" && (enableSignup || enableLogin || enableReservations || stripeSecretKey != "") {
+	} else if authFile == "" && (enableSignup || enableLogin || enableReservations) {
 		return errors.New("cannot set enable-signup, enable-login, enable-reserve-topics, or stripe-secret-key if auth-file is not set")
 	} else if enableSignup && !enableLogin {
 		return errors.New("cannot set enable-signup without also setting enable-login")
-	} else if stripeSecretKey != "" && (stripeWebhookKey == "" || baseURL == "") {
-		return errors.New("if stripe-secret-key is set, stripe-webhook-key and base-url must also be set")
+	// } else if stripeSecretKey != "" && (stripeWebhookKey == "" || baseURL == "") {
+	//	return errors.New("if stripe-secret-key is set, stripe-webhook-key and base-url must also be set")
 	} else if twilioAccount != "" && (twilioAuthToken == "" || twilioPhoneNumber == "" || twilioVerifyService == "" || baseURL == "" || authFile == "") {
 		return errors.New("if twilio-account is set, twilio-auth-token, twilio-phone-number, twilio-verify-service, base-url, and auth-file must also be set")
 	} else if messageSizeLimit > server.DefaultMessageSizeLimit {
@@ -340,10 +340,10 @@
 	}
 
 	// Stripe things
-	if stripeSecretKey != "" {
-		stripe.EnableTelemetry = false // Whoa!
-		stripe.Key = stripeSecretKey
-	}
+	// if stripeSecretKey != "" {
+	//	stripe.EnableTelemetry = false // Whoa!
+	//	stripe.Key = stripeSecretKey
+	//}
 
 	// Add default forbidden topics
 	disallowedTopics = append(disallowedTopics, server.DefaultDisallowedTopics...)
@@ -402,8 +402,8 @@
 	conf.VisitorEmailLimitReplenish = visitorEmailLimitReplenish
 	conf.VisitorSubscriberRateLimiting = visitorSubscriberRateLimiting
 	conf.BehindProxy = behindProxy
-	conf.StripeSecretKey = stripeSecretKey
-	conf.StripeWebhookKey = stripeWebhookKey
+	// conf.StripeSecretKey = stripeSecretKey
+	// conf.StripeWebhookKey = stripeWebhookKey
 	conf.BillingContact = billingContact
 	conf.EnableSignup = enableSignup
 	conf.EnableLogin = enableLogin
--- a/server/server.go
+++ b/server/server.go
@@ -56,7 +56,7 @@
 	messageCache      *messageCache                       // Database that stores the messages
 	webPush           *webPushStore                       // Database that stores web push subscriptions
 	fileCache         *fileCache                          // File system based cache that stores attachments
-	stripe            stripeAPI                           // Stripe API, can be replaced with a mock
+	stripe            *string                             // Stripe API, can be replaced with a mock
 	priceCache        *util.LookupCache[map[string]int64] // Stripe price ID -> price as cents (USD implied!)
 	metricsHandler    http.Handler                        // Handles /metrics if enable-metrics set, and listen-metrics-http not set
 	closeChan         chan bool
@@ -157,10 +157,10 @@
 	if conf.SMTPSenderAddr != "" {
 		mailer = &smtpSender{config: conf}
 	}
-	var stripe stripeAPI
-	if conf.StripeSecretKey != "" {
-		stripe = newStripeAPI()
-	}
+	// var stripe stripeAPI
+	// if conf.StripeSecretKey != "" {
+	//	stripe = newStripeAPI()
+	// }
 	messageCache, err := createMessageCache(conf)
 	if err != nil {
 		return nil, err
@@ -220,9 +220,9 @@
 		messages:        messages,
 		messagesHistory: []int64{messages},
 		visitors:        make(map[string]*visitor),
-		stripe:          stripe,
+		// stripe:          stripe,
 	}
-	s.priceCache = util.NewLookupCache(s.fetchStripePrices, conf.StripePriceCacheDuration)
+	// s.priceCache = util.NewLookupCache(s.fetchStripePrices, conf.StripePriceCacheDuration)
 	return s, nil
 }
 
@@ -479,18 +479,18 @@
 		return s.ensureUser(s.withAccountSync(s.handleAccountReservationAdd))(w, r, v)
 	} else if r.Method == http.MethodDelete && apiAccountReservationSingleRegex.MatchString(r.URL.Path) {
 		return s.ensureUser(s.withAccountSync(s.handleAccountReservationDelete))(w, r, v)
-	} else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingSubscriptionPath {
-		return s.ensurePaymentsEnabled(s.ensureUser(s.handleAccountBillingSubscriptionCreate))(w, r, v) // Account sync via incoming Stripe webhook
-	} else if r.Method == http.MethodGet && apiAccountBillingSubscriptionCheckoutSuccessRegex.MatchString(r.URL.Path) {
-		return s.ensurePaymentsEnabled(s.ensureUserManager(s.handleAccountBillingSubscriptionCreateSuccess))(w, r, v) // No user context!
-	} else if r.Method == http.MethodPut && r.URL.Path == apiAccountBillingSubscriptionPath {
-		return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingSubscriptionUpdate))(w, r, v) // Account sync via incoming Stripe webhook
-	} else if r.Method == http.MethodDelete && r.URL.Path == apiAccountBillingSubscriptionPath {
-		return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingSubscriptionDelete))(w, r, v) // Account sync via incoming Stripe webhook
-	} else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingPortalPath {
-		return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingPortalSessionCreate))(w, r, v)
-	} else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingWebhookPath {
-		return s.ensurePaymentsEnabled(s.ensureUserManager(s.handleAccountBillingWebhook))(w, r, v) // This request comes from Stripe!
+	// } else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingSubscriptionPath {
+	// 	return s.ensurePaymentsEnabled(s.ensureUser(s.handleAccountBillingSubscriptionCreate))(w, r, v) // Account sync via incoming Stripe webhook
+	// } else if r.Method == http.MethodGet && apiAccountBillingSubscriptionCheckoutSuccessRegex.MatchString(r.URL.Path) {
+	// 	return s.ensurePaymentsEnabled(s.ensureUserManager(s.handleAccountBillingSubscriptionCreateSuccess))(w, r, v) // No user context!
+	// } else if r.Method == http.MethodPut && r.URL.Path == apiAccountBillingSubscriptionPath {
+	// 	return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingSubscriptionUpdate))(w, r, v) // Account sync via incoming Stripe webhook
+	// } else if r.Method == http.MethodDelete && r.URL.Path == apiAccountBillingSubscriptionPath {
+	// 	return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingSubscriptionDelete))(w, r, v) // Account sync via incoming Stripe webhook
+	// } else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingPortalPath {
+	// 	return s.ensurePaymentsEnabled(s.ensureStripeCustomer(s.handleAccountBillingPortalSessionCreate))(w, r, v)
+	// } else if r.Method == http.MethodPost && r.URL.Path == apiAccountBillingWebhookPath {
+	// 	return s.ensurePaymentsEnabled(s.ensureUserManager(s.handleAccountBillingWebhook))(w, r, v) // This request comes from Stripe!
 	} else if r.Method == http.MethodPut && r.URL.Path == apiAccountPhoneVerifyPath {
 		return s.ensureUser(s.ensureCallsEnabled(s.withAccountSync(s.handleAccountPhoneNumberVerify)))(w, r, v)
 	} else if r.Method == http.MethodPut && r.URL.Path == apiAccountPhonePath {
@@ -503,8 +503,8 @@
 		return s.ensureWebPushEnabled(s.limitRequests(s.handleWebPushDelete))(w, r, v)
 	} else if r.Method == http.MethodGet && r.URL.Path == apiStatsPath {
 		return s.handleStats(w, r, v)
-	} else if r.Method == http.MethodGet && r.URL.Path == apiTiersPath {
-		return s.ensurePaymentsEnabled(s.handleBillingTiersGet)(w, r, v)
+	// } else if r.Method == http.MethodGet && r.URL.Path == apiTiersPath {
+	// 	return s.ensurePaymentsEnabled(s.handleBillingTiersGet)(w, r, v)
 	} else if r.Method == http.MethodGet && r.URL.Path == matrixPushPath {
 		return s.handleMatrixDiscovery(w)
 	} else if r.Method == http.MethodGet && r.URL.Path == metricsPath && s.metricsHandler != nil {
--- a/server/server_account.go
+++ b/server/server_account.go
@@ -179,12 +179,12 @@
 			logvr(v, r).Err(err).Warn("Error removing web push subscriptions for %s", u.Name)
 		}
 	}
-	if u.Billing.StripeSubscriptionID != "" {
-		logvr(v, r).Tag(tagStripe).Info("Canceling billing subscription for user %s", u.Name)
-		if _, err := s.stripe.CancelSubscription(u.Billing.StripeSubscriptionID); err != nil {
-			return err
-		}
-	}
+	// if u.Billing.StripeSubscriptionID != "" {
+	// 	logvr(v, r).Tag(tagStripe).Info("Canceling billing subscription for user %s", u.Name)
+	// 	if _, err := s.stripe.CancelSubscription(u.Billing.StripeSubscriptionID); err != nil {
+	// 		return err
+	// 	}
+	// }
 	if err := s.maybeRemoveMessagesAndExcessReservations(r, v, u, 0); err != nil {
 		return err
 	}
--- a/server/server_payments.go
+++ b/server/server_payments.go
@@ -1,3 +1,5 @@
+//go:build ignore
+
 package server
 
 import (
--- a/server/server_account_test.go
+++ b/server/server_account_test.go
@@ -1,3 +1,4 @@
+//go:build ignore
 package server
 
 import (
--- a/server/server_payments_test.go
+++ b/server/server_payments_test.go
@@ -1,3 +1,4 @@
+//go:build ignore
 package server
 
 import (
--- a/user/manager_test.go
+++ b/user/manager_test.go
@@ -1,3 +1,4 @@
+//go:build ignore
 package user
 
 import (
