登录
首页 >  Golang >  Go问答

Golang:如何在 go 中成功创建新的 Stripe PaymentIntent?示例 go 代码有一个名为“ paymentintent ”的未定义变量。

来源:stackoverflow

时间:2024-04-11 17:45:34 229浏览 收藏

积累知识,胜过积蓄金银!毕竟在Golang开发的过程中,会遇到各种各样的问题,往往都是一些细节知识点还没有掌握好而导致的,因此基础知识点的积累是很重要的。下面本文《Golang:如何在 go 中成功创建新的 Stripe PaymentIntent?示例 go 代码有一个名为“ paymentintent ”的未定义变量。》,就带大家讲解一下知识点,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

stripe文档有以下代码:

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

我遇到的问题是 paymentintent 未定义。我该如何解决这个问题?


解决方案


这是完整的代码,希望对您有所帮助。

从终端安装以下库,

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

现在从终端运行这两个命令,

go mod it v1
go mod tidy

现在只需将您的密钥和电子邮件 id 添加到以下代码中并执行它,您将获得 payment intent 对象的响应。 包主要

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("[email protected]"),
    }
    pi, _ := paymentintent.New(params)
    fmt.Println(pi)
}

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>