我正在尝试使用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")
}
有人知道为什么未定义会话吗?谢谢!
答案 0 :(得分:1)
您需要导入包含session的软件包:Go package docs
import "github.com/stripe/stripe-go/v71/checkout/session"
他们确实从Create a Checkout Session部分链接到它,但他们忘记了代码段中的包含内容。