Golang: How do I successfully create a new Stripe PaymentIntent in go? The example go code has an undefined variable named "paymentintent."

Viewed 611

The Stripe documentation has the following code:

// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"

params := &stripe.PaymentIntentParams{
  Amount: stripe.Int64(1099),
  Currency: stripe.String(string(stripe.CurrencyUSD)),
}
pi, _ := paymentintent.New(params)
// Pass the client secret to the client

The issue I'm having is that paymentintent is undefined. How can I solve this issue?

1 Answers

Here is the complete code, Hope it helps.

install the following libraries from terminal,

go get github.com/stripe/stripe-go/v72
go get  github.com/stripe/stripe-go/v72/paymentintent

Now run the two commands from the terminal,

go mod it V1
go mod tidy

Now just add your secret keys and email ids to the following codes and execute it, you will get the response of the Payment Intent object. package main

import (
    "fmt"

    "github.com/stripe/stripe-go/v72"
    "github.com/stripe/stripe-go/v72/paymentintent"
)

func main() {
    fmt.Println("here its payment processing")

    // Set your secret key. Remember to switch to your live secret key in production.
    // See your keys here: https://dashboard.stripe.com/apikeys
    stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"

    params := &stripe.PaymentIntentParams{
        Amount:   stripe.Int64(1000),
        Currency: stripe.String(string(stripe.CurrencyUSD)),
        PaymentMethodTypes: stripe.StringSlice([]string{
            "card",
        }),
        ReceiptEmail: stripe.String("your@mail.com"),
    }
    pi, _ := paymentintent.New(params)
    fmt.Println(pi)
}
Related