From 241e33af1d9302433599cf7b3c5217fc14e26fae Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sun, 5 Oct 2025 10:39:12 +0200 Subject: [PATCH] feat(stripe): upgrade to stripe-go v83 and update usage Upgraded the Stripe SDK from v78 to v83 in go.mod and go.sum, and updated all code references to match the new API. Refactored session creation to use the new method signatures and types. Adjusted tests and documentation to reflect the updated dependency and API usage. --- go.mod | 2 +- go.sum | 22 ++++------- internal/payments/driver/stripe/checkout.go | 37 +++++++++---------- .../payments/driver/stripe/checkout_test.go | 14 +++---- .../plans/2025-09-27-stripe-checkout-demo.md | 4 +- 5 files changed, 36 insertions(+), 43 deletions(-) diff --git a/go.mod b/go.mod index 7dddab1..851dae6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/rjNemo/payit go 1.25.1 -require github.com/stripe/stripe-go/v78 v78.12.0 +require github.com/stripe/stripe-go/v83 v83.0.0 diff --git a/go.sum b/go.sum index 36936bd..2c4ac7f 100644 --- a/go.sum +++ b/go.sum @@ -2,19 +2,13 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stripe/stripe-go/v78 v78.12.0 h1:YzKjO5Cx1dTfSkqBXzg6GFG7LnRHkZiU0+k0vSF5yt4= -github.com/stripe/stripe-go/v78 v78.12.0/go.mod h1:GjncxVLUc1xoIOidFqVwq+y3pYiG7JLVWiVQxTsLrvQ= -golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 h1:ADo5wSpq2gqaCGQWzk7S5vd//0iyyLeAratkEoG5dLE= -golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/stripe/stripe-go/v83 v83.0.0 h1:00HYu/n80zH6ugy88bWI5sBLbJZ7WmhCXCRQ1N1tuqI= +github.com/stripe/stripe-go/v83 v83.0.0/go.mod h1:nRyDcLrJtwPPQUnKAFs9Bt1NnQvNhNiF6V19XHmPISE= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/payments/driver/stripe/checkout.go b/internal/payments/driver/stripe/checkout.go index c4eb546..f37d5a8 100644 --- a/internal/payments/driver/stripe/checkout.go +++ b/internal/payments/driver/stripe/checkout.go @@ -4,15 +4,14 @@ import ( "context" "errors" - stripesdk "github.com/stripe/stripe-go/v78" - "github.com/stripe/stripe-go/v78/client" + "github.com/stripe/stripe-go/v83" "github.com/rjNemo/payit/config" "github.com/rjNemo/payit/internal/payments" ) type sessionCreator interface { - New(params *stripesdk.CheckoutSessionParams) (*stripesdk.CheckoutSession, error) + Create(ctx context.Context, params *stripe.CheckoutSessionCreateParams) (*stripe.CheckoutSession, error) } // Driver implements the CheckoutDriver interface using the Stripe SDK. @@ -23,11 +22,11 @@ type Driver struct { // NewDriver creates a Stripe-backed checkout driver with the provided credentials. func NewDriver(apiKey string, product config.ProductConfig) *Driver { - stripeClient := client.New(apiKey, nil) + stripeClient := stripe.NewClient(apiKey, nil) return &Driver{ product: product, - sessions: stripeClient.CheckoutSessions, + sessions: stripeClient.V1CheckoutSessions, } } @@ -38,26 +37,26 @@ func (d *Driver) CreateSession(ctx context.Context, req payments.CheckoutSession quantity = 1 } - params := &stripesdk.CheckoutSessionParams{} + params := &stripe.CheckoutSessionCreateParams{} params.Context = ctx - params.SuccessURL = stripesdk.String(d.product.SuccessURL) - params.CancelURL = stripesdk.String(d.product.CancelURL) - params.Mode = stripesdk.String(string(stripesdk.CheckoutSessionModePayment)) - params.PaymentMethodTypes = stripesdk.StringSlice([]string{"card"}) + params.SuccessURL = stripe.String(d.product.SuccessURL) + params.CancelURL = stripe.String(d.product.CancelURL) + params.Mode = stripe.String(string(stripe.CheckoutSessionModePayment)) + params.PaymentMethodTypes = stripe.StringSlice([]string{"card"}) - params.LineItems = append(params.LineItems, &stripesdk.CheckoutSessionLineItemParams{ - Quantity: stripesdk.Int64(quantity), - PriceData: &stripesdk.CheckoutSessionLineItemPriceDataParams{ - Currency: stripesdk.String(d.product.Currency), - UnitAmount: stripesdk.Int64(d.product.PriceCents), - ProductData: &stripesdk.CheckoutSessionLineItemPriceDataProductDataParams{ - Name: stripesdk.String(d.product.Name), - Description: stripesdk.String(d.product.Description), + params.LineItems = append(params.LineItems, &stripe.CheckoutSessionCreateLineItemParams{ + Quantity: stripe.Int64(quantity), + PriceData: &stripe.CheckoutSessionCreateLineItemPriceDataParams{ + Currency: stripe.String(d.product.Currency), + UnitAmount: stripe.Int64(d.product.PriceCents), + ProductData: &stripe.CheckoutSessionCreateLineItemPriceDataProductDataParams{ + Name: stripe.String(d.product.Name), + Description: stripe.String(d.product.Description), }, }, }) - session, err := d.sessions.New(params) + session, err := d.sessions.Create(ctx, params) if err != nil { return payments.CheckoutSessionResult{}, err } diff --git a/internal/payments/driver/stripe/checkout_test.go b/internal/payments/driver/stripe/checkout_test.go index d5cfcdc..268eff4 100644 --- a/internal/payments/driver/stripe/checkout_test.go +++ b/internal/payments/driver/stripe/checkout_test.go @@ -5,19 +5,19 @@ import ( "errors" "testing" - stripesdk "github.com/stripe/stripe-go/v78" + "github.com/stripe/stripe-go/v83" "github.com/rjNemo/payit/config" "github.com/rjNemo/payit/internal/payments" ) type fakeSessionCreator struct { - lastParams *stripesdk.CheckoutSessionParams - result *stripesdk.CheckoutSession + lastParams *stripe.CheckoutSessionCreateParams + result *stripe.CheckoutSession err error } -func (f *fakeSessionCreator) New(params *stripesdk.CheckoutSessionParams) (*stripesdk.CheckoutSession, error) { +func (f *fakeSessionCreator) Create(ctx context.Context, params *stripe.CheckoutSessionCreateParams) (*stripe.CheckoutSession, error) { f.lastParams = params return f.result, f.err } @@ -25,7 +25,7 @@ func (f *fakeSessionCreator) New(params *stripesdk.CheckoutSessionParams) (*stri func TestDriver_CreateSessionSuccess(t *testing.T) { product := testProductConfig() fake := &fakeSessionCreator{ - result: &stripesdk.CheckoutSession{ + result: &stripe.CheckoutSession{ ID: "cs_test_123", URL: "https://stripe.test/checkout", }, @@ -49,7 +49,7 @@ func TestDriver_CreateSessionSuccess(t *testing.T) { if params.Context == nil { t.Fatal("expected context to propagate") } - if params.Mode == nil || *params.Mode != string(stripesdk.CheckoutSessionModePayment) { + if params.Mode == nil || *params.Mode != string(stripe.CheckoutSessionModePayment) { t.Fatalf("unexpected mode: %v", params.Mode) } if len(params.PaymentMethodTypes) != 1 || params.PaymentMethodTypes[0] == nil || *params.PaymentMethodTypes[0] != "card" { @@ -87,7 +87,7 @@ func TestDriver_CreateSessionSuccess(t *testing.T) { func TestDriver_CreateSessionWithCustomQuantity(t *testing.T) { product := testProductConfig() fake := &fakeSessionCreator{ - result: &stripesdk.CheckoutSession{}, + result: &stripe.CheckoutSession{}, } driver := &Driver{product: product, sessions: fake} diff --git a/thoughts/shared/plans/2025-09-27-stripe-checkout-demo.md b/thoughts/shared/plans/2025-09-27-stripe-checkout-demo.md index aa76618..c45806b 100644 --- a/thoughts/shared/plans/2025-09-27-stripe-checkout-demo.md +++ b/thoughts/shared/plans/2025-09-27-stripe-checkout-demo.md @@ -39,7 +39,7 @@ Create the application structure, entrypoint, and configuration loader for envir ### Changes Required **File**: `go.mod` -**Changes**: Add required module dependencies (`github.com/stripe/stripe-go/v78`, optional `github.com/joho/godotenv` if used) and tidy module. +**Changes**: Add required module dependencies (`github.com/stripe/stripe-go/v83`, optional `github.com/joho/godotenv` if used) and tidy module. **File**: `cmd/payit/main.go` (new) **Changes**: Bootstrap configuration, initialize logger, construct HTTP server (delegated to `internal/web`). @@ -82,7 +82,7 @@ type Config struct { #### Manual Verification -- [x] Application starts with placeholder server: `go run ./cmd/payit` *(bind restricted in sandbox; confirmed startup log before failure)* +- [x] Application starts with placeholder server: `go run ./cmd/payit` _(bind restricted in sandbox; confirmed startup log before failure)_ - [x] Missing environment variables cause a clear startup error ## Phase 2: Stripe Checkout Backend