Go版Stripe Checkout教程无法编译,undefined: session

Go version Stripe Checkout tutorial can't be compiled, undefined: session

我正在尝试使用 golang 和杜松子酒 Stripe Checkout tutorial。但由于错误 undefined: session.

,无法构建以下代码
package main

import (
    "github.com/gin-gonic/gin"
    "net/http"
    stripe "github.com/stripe/stripe-go/v71"
)

func main(){
    r := gin.Default()

    r.GET("/buy/:id", func(c *gin.Context) {
        stripe.Key = "sk_test_MyKey............"

        params := &stripe.CheckoutSessionParams{
            PaymentMethodTypes: stripe.StringSlice([]string{
                    "card",
                    "ideal",
            }),
            LineItems: []*stripe.CheckoutSessionLineItemParams{
                    &stripe.CheckoutSessionLineItemParams{
                            PriceData: &stripe.CheckoutSessionLineItemPriceDataParams{
                                Currency: stripe.String("stripe.String(stripe.CurrencyEUR)"),
                                ProductData: &stripe.CheckoutSessionLineItemPriceDataProductDataParams{
                                    Name: stripe.String("T-shirt"),
                                },
                                UnitAmount: stripe.Int64(2000),
                            },
                            Quantity: stripe.Int64(1),
                    },
            },
            Mode: stripe.String("payment"),
            SuccessURL: stripe.String("https://example.com/success?session_id={CHECKOUT_SESSION_ID}"),
            CancelURL: stripe.String("https://example.com/cancel"),
        }
        s, err := session.New(params)
        if err != nil {
            log.Println(err)
        } else {
            c.JSON(http.StatusOK, gin.H{
                "SessionID": s.id,
            })  
        }
    r.Run(":8080")
}

有谁知道为什么 session 未定义?谢谢!

您需要导入包含session: Go package docs

的包
import "github.com/stripe/stripe-go/v71/checkout/session"

他们从 Create a Checkout Session 部分对其进行了 link,但他们忘记了代码片段中的包含。