#daichi-go-price
1 messages · Page 1 of 1 (latest)
What version of our stripe-go library are you using?
"github.com/stripe/stripe-go/v72"
So I believe 72?
I imported some packages like below
"github.com/stripe/stripe-go/v72/customer"
"github.com/stripe/stripe-go/v72/sub"
But so am I supposed to add something like "github.com/stripe/stripe-go/v72/price". ???
Gotcha, prices were added in a 71 version so I was just checking.
Yes, are you already doing that import for prices?
I tried
go get -u "github.com/stripe/stripe-go/v72/price"
But didn't work
so it should be "github.com/stripe/stripe-go/v71/price" ????
Current version of your package should work. Still looking at what might be happening here
Actually "github.com/stripe/stripe-go/v71/price" this worked
Even though "github.com/stripe/stripe-go/v72/price" didn't work
👋
Stepping in as Pompey needs to step away
Hmm that sounds like you are on v71, no?
Yeah, but we are using v72
Now it's like this
Also, to retrieve the price (like 10$) from price_id is something like below code, correct?
p, err := price.Get(priceID, nil)
I get the error something like below
"status":401,"message":"You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). See https://stripe.com/docs/api#authentication for details, or we can help at https://support.stripe.com/.\",\"type\":\"invalid_request_error\"
I do set the API key for Stripe, so maybe it causes problem because I use v71?
Hey @steep torrent what do you see locally in your stripe-go install in the VERSION file?
Like the error you mentioned above seems to confirm you have the right version and you can use the Price API and you incorrectly set your API key in the code that calls that API
Yeah I can now see that I set the API key for v72 but not v71 since I just created v71 folder locally by myself
doesn't make sense to use v71
stick with v72, or really v74 which is the latest version
So go get -u "github.com/stripe/stripe-go/v72/price" because this didn't work
read https://github.com/stripe/stripe-go#installation closely, it explains how to use go modules, which you plausibly haven't used/configured properly yet so you were stuck on v70
So theoretically, I just need to do go get -u github.com/stripe/stripe-go/v74 to import the package. But still doesn't recognize price. I also did go get -u github.com/stripe/stripe-go/v74/price and it didn't give me errors but still don't show that I imported successfully.
I don't see price package there
yeah because I really think you aren;'t installing this properly
remove the entire stripe folder
and then use go modules
have you use go modules before? Because if not you need to read up on this first
'go get' is no longer supported outside a module.``` like I get this if I don't configure modules properly
I didn't get this
I'll try
yeah I think it's because you have a different go version I assume (like go the tooling, not stripe-go)
go modules have been the default for a while now in the go ecosystem so we also switched to it 2+ years ago
We are using go 1.15 now, can it be a problem?
no no all go versions work fine, just you need to basically figure out how to use go modules in your project
Ok, I'll look into it, thx. I'll send message if I have other issues.
yeah we have go.mod
For Stripe part, it shows github.com/stripe/stripe-go/v72 v72.122.0
okay then if you create a Price with v72 it should work fine
But it doesn't.....
import "fmt"
import "github.com/stripe/stripe-go/v72"
import "github.com/stripe/stripe-go/v72/price"
func main() {
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.PriceParams{
Currency: stripe.String(string(stripe.CurrencyUSD)),
ProductData: &stripe.PriceProductDataParams{
Name: stripe.String("product name"),
},
Recurring: &stripe.PriceRecurringParams{
Interval: stripe.String("month"),
},
UnitAmount: stripe.Int64(1200),
}
p, _ := price.New(params)
fmt.Printf("Got: \n", p.ID)
}```
this is my basic example. It uses v72. I didn't have it like you did so I did $ go get -u github.com/stripe/stripe-go/v72 go: downloading github.com/stripe/stripe-go/v72 v72.122.0
that command added the info to both go.mod and to go.sum
I still don't know why you can use price.New() but I can't....
So since my colleague can user customer, I should be also able to use price as well. Maybe I'll ask him how he did
Cuz I really have no clue since I can see that I imported on go.mod but doesn't show it on the file....
stripe-go has existed for many years. The customer API existed 8+ years ago when we built the library. The Price API was added in 2021.
stripe-go changed in v71 and required go modules. If you don't install stripe-go properly you end up with v70 by default always. And that one does not have the Price API though it has Customer or Subscription that are many years old
My take here is that you are using the wrong stripe-go version
try creating a Customer and give me the id cus_123 and I can look up that request and tell you which version your code uses
cus_MtF18AuS2l1c2e
Even though my go.mod shows v72?
https://dashboard.stripe.com/test/logs/req_KYex81EP94qT2G this is your API request. You can see it used v72.58.0 so not the version you were talking about
can you share your exact code for what created the Customer?
(remove your API key)
func (pah *paymentHandler) CreateCustomer(ctx context.Context, user *entity.User, creditToken string) (string, error) {
params := &stripe.CustomerParams{
Description: stripe.String(user.UID),
Email: stripe.String(user.Email),
Source: &stripe.SourceParams{Token: &creditToken},
}
c, err := customer.New(params)
}
Oh yeah I just checked it, and the reason is I somehow updated the version. But does it matter?
daichi-go-price
I don't understnad what you're saying
I'm sorry you're giving me so little to help you
Please provide real end to end example showing how you run that exact code
because right now you said you used version X but you are on version Y (though same major) and there seems to be a lot of confusion
I made it back to the original version.
And this is the exact code
func (pah *paymentHandler) CreateCustomer(ctx context.Context, user *entity.User, creditToken string) (string, error) {
params := &stripe.CustomerParams{
Description: stripe.String(user.UID),
Email: stripe.String(user.Email),
Source: &stripe.SourceParams{Token: &creditToken},
}
c, err := customer.New(params)
if err == nil {
return c.ID, nil
} else {
if stripeErr, ok := err.(*stripe.Error); ok {
switch stripeErr.Code {
case stripe.ErrorCodeTokenAlreadyUsed:
logz.Errorf(ctx, fmt.Sprintf("This token is already used: %s", stripeErr.Msg))
return "", entity.GetGraphqlError(entity.ERR_STRIPE_TOKEN_ALREADY_USED)
default:
logz.Errorf(ctx, fmt.Sprintf("Another Stripe error occurred: %s", stripeErr.Code))
return "", entity.GetGraphqlError(entity.ERR_STRIPE)
}
} else {
logz.Errorf(ctx, fmt.Sprintf("An error occurred that was unrelated to Stripe."))
return "", entity.GetGraphqlError(entity.ERR_INTERNAL_SERVER_ERROR)
}
}
}
import "fmt"
import "github.com/stripe/stripe-go/v72"
import "github.com/stripe/stripe-go/v72/price"
func main() {
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.PriceParams{
Currency: stripe.String(string(stripe.CurrencyUSD)),
ProductData: &stripe.PriceProductDataParams{
Name: stripe.String("product name"),
},
Recurring: &stripe.PriceRecurringParams{
Interval: stripe.String("month"),
},
UnitAmount: stripe.Int64(1200),
}
p, _ := price.New(params)
fmt.Printf("Got: \n", p.ID)
}```
The problem is I don't see anywhere how you load stripe-go, where you set the API key, etc
Try to run a simple end to end example instead like my script above
Because I set the API key in the different directory, that's why it doesn't show here.
stripeSecretKey := os.Getenv("STRIPE_SECRET_KEY")
if stripeSecretKey == "" {
logz.Criticalf(ctx, "STRIPE_SECRET_KEY no set")
os.Exit(1)
}
stripe.Key = getSecret(os.Getenv("STRIPE_SECRET_KEY"))
in this file, it imports like
import (stripe "github.com/stripe/stripe-go/v72")
Sorry but we seem to be still quite lost on the basics of the problem
that's why I'm trying to push you to debug this clearly step by step
earlier you said you couldn't import price at all. Later you said you hit a "API key not defined" which is completely different
so I'm asking if you can try a really simple end to end example that hardcodes the API key and just creates the Price and see if that works
Exactly, previously I had error for not being able to import, but now I can. I honestly don't know why.
And now the problem still remains: not being able to use price. In other words, I can't do price.Get() or price.Update().
So I can't even create Price as you show on the above, because I can't call price.New()
Where did you import the package in this file though
import ( "backend/app/entity" "context" "fmt" "github.com/glassonion1/logz" "github.com/mythrnr/paypayopa-sdk-go" "github.com/stripe/stripe-go/v72" "github.com/stripe/stripe-go/v72/customer" "github.com/stripe/stripe-go/v72/sub" )
like this?
I don't know, I'm asking
like this code you shared never including the price package
so it's normal your IDE says "I don't know what price is"
"backend/app/entity"
"context"
"fmt"
"github.com/glassonion1/logz"
"github.com/mythrnr/paypayopa-sdk-go"
"github.com/stripe/stripe-go/v72"
"github.com/stripe/stripe-go/v72/customer"
"github.com/stripe/stripe-go/v72/sub"
"github.com/stripe/stripe-go/v72/price"
)```
like if you add that last line it should work after that I think
what even
I'm sorry but we're reaching a point where I have no clue what is going on.
Then, I realized there is no such a package unlike sub and customer. They have package, so I thought I'm missing something.
The Price APIs were added in https://github.com/stripe/stripe-go/blob/master/CHANGELOG.md#7170---2020-04-29 which is 71.7.0 back in April 2020. The v72 absolutely has price
So it really feels like you do not have v72 installed properly
something is broken in your setup .I would remove that stripe folder completely from scratch
and then I would re-run the install for it
I actually did already cuz you told me 15 min ago, and still same
well, I'll ask colleague then. Cuz I have no clue as well
I mean you clearly only have the sub and customer folder
you're missing everything else right?
like there's a folder for each package: price, plan, product, charge, paymentintent, etc.
Ok, I actually didn't even know that
I thought we need to import manually when we need it
So my colleague set up wrong?
oh boy
that explains a lot
Sorry I'm not a go expert either I mostly know how to make my code work to help go devs
but really you are supposed to have the entire stripe-go library locally, it's like an external package, you have to get everything you see in the filesystem on https://github.com/stripe/stripe-go
so you're supposed to see account.go and an account folder with client.go in it, and same for the 30+ packages we have in it, it's our entire API
and the idea with go is that you don't care about that,you tell your app/system "hey I want to use the package stripe-go" and it downloads and configures it all for you
like gem install stripe in ruby or npm install stripe in Node.js, etc.
I need to ask how he installed it, cuz that sounds like the root cause
like this is what I see in my go home where I have various packages
I have multiple versions of stripe-go, and I have other libs (it's a new laptop so I didn't install much yet)
I completely eliminated Stripe folder, and I removed stripe part from go.mod. Then when I did go mod tidy, it somehow restores everything what it was (only sub and customer).
I see....
yeah I wonder if you have a cached version that is incorrect somewhere
which operating system are you on?
MacOS
$ echo $GOPATH that is where my go modules are installed
maybe check there if you have the wrong data/cache for stripe?
Idk how but it doesn't return anything.....
ah so you must have installed/configured go differently
So yeah you likely want to talk to your colleague about setting up go properly and making sure it installs the library completely
But I wrote export GOROOT="/usr/local/go" in my .zshrc
So it is really werid
ok, will do
Like if I do $ go get github.com/spf13/cobra go: downloading github.com/spf13/cobra v1.6.1 go: downloading github.com/spf13/pflag v1.0.5 go: downloading github.com/inconshreveable/mousetrap v1.0.1 go: added github.com/spf13/cobra v1.6.1
that is me downloading that cobra module (no idea what it is, I just googled for a common example)
and now I have ~/go/pkg/mod/github.com/spf13 $ ls cobra@v1.6.1 pflag@v1.0.5
like the whole libraries were downloaded there and have the full code and then I have ```module ~/go/src
go 1.16
require (
github.com/spf13/cobra v1.6.1 // indirect
github.com/stripe/stripe-go/v72 v72.122.0
github.com/stripe/stripe-go/v74 v74.0.0 // indirect
)
in my go.mod file now andgithub.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=``` in my go.sum
so you must have a similar thing happening whenever you get stripe-go and hopefully your colleague can figure out what is incorrect!
Yeah I do understand what you are showing
I just can't think of how he imported like this....
like, is it even possible to import partially.....
but yeah, I'll ask
thx for the help for long time
And my GOROOT has what I expect so yeah, idk
yeah it feels like you have the right data in your go modules but then when your code runs it, for some reasons, overrides that and just had a separate limited/broken version of stripe-go
clearly your picture shows a different version of stripe-go than what your code is really using