~evanj/cms

26d435c1aef9fd8eb1d76d227921fd08159b9e1f — Evan J 2 months ago ed17a21
Test(s/stripe): Attempting to understand Stripe error message received
on cms-tip.evanjon.es. Invalid transaction ID?
1 files changed, 13 insertions(+), 6 deletions(-)

M internal/s/stripe/stripe.go
M internal/s/stripe/stripe.go => internal/s/stripe/stripe.go +13 -6
@@ 2,6 2,7 @@ package stripe

import (
	"context"
	"fmt"
	"log"

	"git.sr.ht/~evanj/cms/internal/m/org"


@@ 78,16 79,20 @@ func (s Stripe) StartCheckout(ctx context.Context, user user.User, t tier.Tier) 
}

func (s Stripe) CompleteCheckout(ctx context.Context, sessionID string) error {
	fmt.Println("Session ID?", sessionID)

	sess, err := session.Get(sessionID, &lib.CheckoutSessionParams{
		PaymentIntentData: &lib.CheckoutSessionPaymentIntentDataParams{},
	})
	if err != nil {
		return errors.Wrap(err, "transaction session not found")
		s.log.Println(err)
		return errors.New("transaction session not found")
	}

	c, err := customer.Get(sess.Customer.ID, nil)
	if err != nil {
		return errors.Wrap(err, "customer not found")
		s.log.Println(err)
		return errors.New("customer not found")
	}
	if c.Subscriptions == nil {
		return errors.New("corrupted customer object")


@@ 114,7 119,8 @@ func (s Stripe) CompleteCheckout(ctx context.Context, sessionID string) error {

	user, err := s.db.UserGetFromToken(ctx, c.Description)
	if err != nil {
		return errors.Wrap(err, "mangled user token")
		s.log.Println(err)
		return errors.New("mangled user token")
	}

	return s.db.OrgUpdateTier(ctx, user, user.Org(), t, c.ID)


@@ 127,7 133,8 @@ func (s Stripe) CancelSubscription(ctx context.Context, user user.User) error {

	c, err := customer.Get(user.Org().PaymentCustomerID(), nil)
	if err != nil {
		return errors.Wrap(err, "customer not found")
		s.log.Println(err)
		return errors.New("customer not found")
	}
	if c.Subscriptions == nil {
		return errors.New("corrupted customer object")


@@ 143,8 150,8 @@ func (s Stripe) CancelSubscription(ctx context.Context, user user.User) error {
		if err != nil {
			if err := s.db.OrgUpdateTier(ctx, user, user.Org(), currTier, c.ID); err != nil {
				// TODO: Better way to report this to ourselves?
				s.log.Println("big error: sub update in DB but not reflected in stripe")
				return errors.Wrap(err, "your subscription has been cancelled within Skipper CMS but not our payment processor: please contact an admin")
				s.log.Println("big error: sub update in DB but not reflected in stripe", err)
				return errors.New("your subscription has been cancelled within Skipper CMS but not our payment processor: please contact an admin")
			}
			return errors.Wrap(err, "failed to cancel subscription")
		}