#daichi-go-price

1 messages · Page 1 of 1 (latest)

uncut otterBOT
neat adder
#

What version of our stripe-go library are you using?

steep torrent
neat adder
#

Gotcha, prices were added in a 71 version so I was just checking.

#

Yes, are you already doing that import for prices?

steep torrent
neat adder
#

Current version of your package should work. Still looking at what might be happening here

steep torrent
tranquil sapphire
#

👋

#

Stepping in as Pompey needs to step away

#

Hmm that sounds like you are on v71, no?

steep torrent
#

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?

trail meteor
#

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

steep torrent
#

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

trail meteor
#

doesn't make sense to use v71

#

stick with v72, or really v74 which is the latest version

steep torrent
#

So go get -u "github.com/stripe/stripe-go/v72/price" because this didn't work

trail meteor
steep torrent
#

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

trail meteor
#

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
steep torrent
trail meteor
#

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

steep torrent
#

We are using go 1.15 now, can it be a problem?

trail meteor
#

no no all go versions work fine, just you need to basically figure out how to use go modules in your project

steep torrent
#

Ok, I'll look into it, thx. I'll send message if I have other issues.

trail meteor
#

do you have a mod.init in your project?

#

or go.mod sorry, go is not my forte

steep torrent
#

yeah we have go.mod

trail meteor
#

okay what do you have in it for stripe?

steep torrent
#

For Stripe part, it shows github.com/stripe/stripe-go/v72 v72.122.0

trail meteor
#

okay then if you create a Price with v72 it should work fine

steep torrent
#

But it doesn't.....

trail meteor
#

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

steep torrent
#

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....

trail meteor
#

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

steep torrent
#

cus_MtF18AuS2l1c2e

steep torrent
trail meteor
#

can you share your exact code for what created the Customer?

#

(remove your API key)

steep torrent
#

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?

trail meteor
#

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

steep torrent
#

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)
    }
}

}

trail meteor
#

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

steep torrent
#

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"))

steep torrent
trail meteor
#

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

steep torrent
#

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()

trail meteor
#

Where did you import the package in this file though

steep torrent
#

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?

trail meteor
#

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

steep torrent
#

I've already tried

#

And didn't work

trail meteor
#

what even

#

I'm sorry but we're reaching a point where I have no clue what is going on.

steep torrent
#

Then, I realized there is no such a package unlike sub and customer. They have package, so I thought I'm missing something.

trail meteor
#

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

steep torrent
#

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

trail meteor
#

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.

steep torrent
#

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?

trail meteor
#

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

steep torrent
#

what the

#

ok

trail meteor
#

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.

steep torrent
#

I need to ask how he installed it, cuz that sounds like the root cause

trail meteor
#

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)

steep torrent
#

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).

trail meteor
#

yeah I wonder if you have a cached version that is incorrect somewhere

#

which operating system are you on?

steep torrent
#

MacOS

trail meteor
#

$ echo $GOPATH that is where my go modules are installed

#

maybe check there if you have the wrong data/cache for stripe?

steep torrent
#

Idk how but it doesn't return anything.....

trail meteor
#

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

steep torrent
#

But I wrote export GOROOT="/usr/local/go" in my .zshrc
So it is really werid

#

ok, will do

trail meteor
#

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

#

so you must have a similar thing happening whenever you get stripe-go and hopefully your colleague can figure out what is incorrect!

steep torrent
#

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

trail meteor
#

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