commit 94c4a86661a61dfc04762524eb681e28e0fd8e07
parent 22bf6bae578b7daa4c2f7dbb89e6af6023226364
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Fri, 11 Oct 2024 13:34:25 -0700
Do email verification check before billing
Only create a Stripe Checkout or Billing Portal if there is a
verified email. While Stripe would then just collect it for me, I
don't want to have to fetch the email from them when I already have
everything working on my server.
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/internal/backend/order.go b/internal/backend/order.go
@@ -1,6 +1,7 @@
package backend
import (
+ "errors"
"github.com/stripe/stripe-go/v72"
)
@@ -10,6 +11,10 @@ func (e *Env) CreatePortal(username string) (*stripe.BillingPortalSession, error
return nil, err
}
+ if err := e.verifyUserForBilling(username); err != nil {
+ return nil, err
+ }
+
params := &stripe.BillingPortalSessionParams{
Customer: stripe.String(user.stripeCustomerID),
ReturnURL: stripe.String("http://www.spaceplanner.app"),
@@ -23,6 +28,10 @@ func (e *Env) CreateCheckout(username string, price string) (*stripe.CheckoutSes
return nil, err
}
+ if err := e.verifyUserForBilling(username); err != nil {
+ return nil, err
+ }
+
p, err := e.Price(price)
if err != nil {
return nil, err
@@ -42,3 +51,14 @@ func (e *Env) CreateCheckout(username string, price string) (*stripe.CheckoutSes
}
return e.Stripe.CheckoutSessions.New(params);
}
+
+func (e *Env) verifyUserForBilling(username string) error {
+ emails, err := e.UserEmails(username)
+ if err != nil {
+ return err
+ }
+ if emails.Verified == nil {
+ return errors.New("Cannot checkout without verifying email")
+ }
+ return nil
+}