英文:
Stripe API call (Payment Intent creation) failed: x509 certificate signed by unknown authority
问题
我正在尝试在服务器端(使用Go语言)实例化一个PaymentIntent,就像这个示例一样,但是遇到了这个错误Request failed with error: Post "https://api.stripe.com/v1/payment_intents": x509: certificate signed by unknown authority
。我已经确保像下面这样分配了测试密钥,但错误仍然存在。这与SSL证书有关吗?我正在使用Docker在本地测试我的应用程序(localhost)。
我的代码:
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/paymentintent"
)
func CreateStripePaymentIntent(subtotal float32) (string, error) {
// 使用金额和货币创建一个PaymentIntent
stripe.Key = os.Getenv("STRIPE_SECRET_KEY")
fmt.Println(stripe.Key)
params := &stripe.PaymentIntentParams{
Amount: stripe.Int64(int64(subtotal)),
Currency: stripe.String(string(stripe.CurrencyUSD)),
}
pi, err := paymentintent.New(params)
if err != nil {
return "", fmt.Errorf("pi.New: %v", err) // ========> 在调用Stripe API时出错
}
return pi.ClientSecret, nil
}
英文:
I am trying to instantiate a PaymentIntent on the server-side (using Go) just like this example but met with this error Request failed with error: Post "https://api.stripe.com/v1/payment_intents": x509: certificate signed by unknown authority
. I have made sure to assign the test secret key like below, but the error still persists. Does it have something to do with SSL certificate? I am testing my app locally using Docker (localhost).
My code:
import (
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/paymentintent"
)
func CreateStripePaymentIntent(subtotal float32) (string, error) {
// Create a PaymentIntent with amount and currency
stripe.Key = os.Getenv("STRIPE_SECRET_KEY")
fmt.Println(stripe.Key)
params := &stripe.PaymentIntentParams{
Amount: stripe.Int64(int64(subtotal)),
Currency: stripe.String(string(stripe.CurrencyUSD)),
}
pi, err := paymentintent.New(params)
if err != nil {
return "", fmt.Errorf("pi.New: %v", err) // =======> ERROR HERE WHEN CALLING STRIPE API
}
return pi.ClientSecret, nil
}
答案1
得分: 1
由于我使用scratch
Docker镜像运行服务器,所以没有SSL证书可用。只需要从第一阶段(我的构建是多阶段构建)复制证书COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
。
英文:
Since I run the server using scratch
Docker image, there is no SSL certificate to use. Just need to copy the certs from first stage (Mine is a multi-staged build) COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论