mirror of
https://github.com/rjNemo/payit
synced 2026-06-06 02:16:40 +00:00
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.
This commit is contained in:
parent
bf721dc130
commit
241e33af1d
5 changed files with 36 additions and 43 deletions
2
go.mod
2
go.mod
|
|
@ -2,4 +2,4 @@ module github.com/rjNemo/payit
|
||||||
|
|
||||||
go 1.25.1
|
go 1.25.1
|
||||||
|
|
||||||
require github.com/stripe/stripe-go/v78 v78.12.0
|
require github.com/stripe/stripe-go/v83 v83.0.0
|
||||||
|
|
|
||||||
22
go.sum
22
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/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 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
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 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
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/v83 v83.0.0 h1:00HYu/n80zH6ugy88bWI5sBLbJZ7WmhCXCRQ1N1tuqI=
|
||||||
github.com/stripe/stripe-go/v78 v78.12.0/go.mod h1:GjncxVLUc1xoIOidFqVwq+y3pYiG7JLVWiVQxTsLrvQ=
|
github.com/stripe/stripe-go/v83 v83.0.0/go.mod h1:nRyDcLrJtwPPQUnKAFs9Bt1NnQvNhNiF6V19XHmPISE=
|
||||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023 h1:ADo5wSpq2gqaCGQWzk7S5vd//0iyyLeAratkEoG5dLE=
|
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
|
||||||
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
|
||||||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
|
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
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=
|
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,14 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
stripesdk "github.com/stripe/stripe-go/v78"
|
"github.com/stripe/stripe-go/v83"
|
||||||
"github.com/stripe/stripe-go/v78/client"
|
|
||||||
|
|
||||||
"github.com/rjNemo/payit/config"
|
"github.com/rjNemo/payit/config"
|
||||||
"github.com/rjNemo/payit/internal/payments"
|
"github.com/rjNemo/payit/internal/payments"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sessionCreator interface {
|
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.
|
// 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.
|
// NewDriver creates a Stripe-backed checkout driver with the provided credentials.
|
||||||
func NewDriver(apiKey string, product config.ProductConfig) *Driver {
|
func NewDriver(apiKey string, product config.ProductConfig) *Driver {
|
||||||
stripeClient := client.New(apiKey, nil)
|
stripeClient := stripe.NewClient(apiKey, nil)
|
||||||
|
|
||||||
return &Driver{
|
return &Driver{
|
||||||
product: product,
|
product: product,
|
||||||
sessions: stripeClient.CheckoutSessions,
|
sessions: stripeClient.V1CheckoutSessions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,26 +37,26 @@ func (d *Driver) CreateSession(ctx context.Context, req payments.CheckoutSession
|
||||||
quantity = 1
|
quantity = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
params := &stripesdk.CheckoutSessionParams{}
|
params := &stripe.CheckoutSessionCreateParams{}
|
||||||
params.Context = ctx
|
params.Context = ctx
|
||||||
params.SuccessURL = stripesdk.String(d.product.SuccessURL)
|
params.SuccessURL = stripe.String(d.product.SuccessURL)
|
||||||
params.CancelURL = stripesdk.String(d.product.CancelURL)
|
params.CancelURL = stripe.String(d.product.CancelURL)
|
||||||
params.Mode = stripesdk.String(string(stripesdk.CheckoutSessionModePayment))
|
params.Mode = stripe.String(string(stripe.CheckoutSessionModePayment))
|
||||||
params.PaymentMethodTypes = stripesdk.StringSlice([]string{"card"})
|
params.PaymentMethodTypes = stripe.StringSlice([]string{"card"})
|
||||||
|
|
||||||
params.LineItems = append(params.LineItems, &stripesdk.CheckoutSessionLineItemParams{
|
params.LineItems = append(params.LineItems, &stripe.CheckoutSessionCreateLineItemParams{
|
||||||
Quantity: stripesdk.Int64(quantity),
|
Quantity: stripe.Int64(quantity),
|
||||||
PriceData: &stripesdk.CheckoutSessionLineItemPriceDataParams{
|
PriceData: &stripe.CheckoutSessionCreateLineItemPriceDataParams{
|
||||||
Currency: stripesdk.String(d.product.Currency),
|
Currency: stripe.String(d.product.Currency),
|
||||||
UnitAmount: stripesdk.Int64(d.product.PriceCents),
|
UnitAmount: stripe.Int64(d.product.PriceCents),
|
||||||
ProductData: &stripesdk.CheckoutSessionLineItemPriceDataProductDataParams{
|
ProductData: &stripe.CheckoutSessionCreateLineItemPriceDataProductDataParams{
|
||||||
Name: stripesdk.String(d.product.Name),
|
Name: stripe.String(d.product.Name),
|
||||||
Description: stripesdk.String(d.product.Description),
|
Description: stripe.String(d.product.Description),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
session, err := d.sessions.New(params)
|
session, err := d.sessions.Create(ctx, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return payments.CheckoutSessionResult{}, err
|
return payments.CheckoutSessionResult{}, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,19 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
stripesdk "github.com/stripe/stripe-go/v78"
|
"github.com/stripe/stripe-go/v83"
|
||||||
|
|
||||||
"github.com/rjNemo/payit/config"
|
"github.com/rjNemo/payit/config"
|
||||||
"github.com/rjNemo/payit/internal/payments"
|
"github.com/rjNemo/payit/internal/payments"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeSessionCreator struct {
|
type fakeSessionCreator struct {
|
||||||
lastParams *stripesdk.CheckoutSessionParams
|
lastParams *stripe.CheckoutSessionCreateParams
|
||||||
result *stripesdk.CheckoutSession
|
result *stripe.CheckoutSession
|
||||||
err error
|
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
|
f.lastParams = params
|
||||||
return f.result, f.err
|
return f.result, f.err
|
||||||
}
|
}
|
||||||
|
|
@ -25,7 +25,7 @@ func (f *fakeSessionCreator) New(params *stripesdk.CheckoutSessionParams) (*stri
|
||||||
func TestDriver_CreateSessionSuccess(t *testing.T) {
|
func TestDriver_CreateSessionSuccess(t *testing.T) {
|
||||||
product := testProductConfig()
|
product := testProductConfig()
|
||||||
fake := &fakeSessionCreator{
|
fake := &fakeSessionCreator{
|
||||||
result: &stripesdk.CheckoutSession{
|
result: &stripe.CheckoutSession{
|
||||||
ID: "cs_test_123",
|
ID: "cs_test_123",
|
||||||
URL: "https://stripe.test/checkout",
|
URL: "https://stripe.test/checkout",
|
||||||
},
|
},
|
||||||
|
|
@ -49,7 +49,7 @@ func TestDriver_CreateSessionSuccess(t *testing.T) {
|
||||||
if params.Context == nil {
|
if params.Context == nil {
|
||||||
t.Fatal("expected context to propagate")
|
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)
|
t.Fatalf("unexpected mode: %v", params.Mode)
|
||||||
}
|
}
|
||||||
if len(params.PaymentMethodTypes) != 1 || params.PaymentMethodTypes[0] == nil || *params.PaymentMethodTypes[0] != "card" {
|
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) {
|
func TestDriver_CreateSessionWithCustomQuantity(t *testing.T) {
|
||||||
product := testProductConfig()
|
product := testProductConfig()
|
||||||
fake := &fakeSessionCreator{
|
fake := &fakeSessionCreator{
|
||||||
result: &stripesdk.CheckoutSession{},
|
result: &stripe.CheckoutSession{},
|
||||||
}
|
}
|
||||||
|
|
||||||
driver := &Driver{product: product, sessions: fake}
|
driver := &Driver{product: product, sessions: fake}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ Create the application structure, entrypoint, and configuration loader for envir
|
||||||
### Changes Required
|
### Changes Required
|
||||||
|
|
||||||
**File**: `go.mod`
|
**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)
|
**File**: `cmd/payit/main.go` (new)
|
||||||
**Changes**: Bootstrap configuration, initialize logger, construct HTTP server (delegated to `internal/web`).
|
**Changes**: Bootstrap configuration, initialize logger, construct HTTP server (delegated to `internal/web`).
|
||||||
|
|
@ -82,7 +82,7 @@ type Config struct {
|
||||||
|
|
||||||
#### Manual Verification
|
#### 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
|
- [x] Missing environment variables cause a clear startup error
|
||||||
|
|
||||||
## Phase 2: Stripe Checkout Backend
|
## Phase 2: Stripe Checkout Backend
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue