簡體   English   中英

Stripe API 調用(支付意圖創建)失敗:x509 證書由未知機構簽名

[英]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) {
    // 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
}

由於我使用scratch Docker 映像運行服務器,因此沒有 SSL 證書可供使用。 只需要從第一階段復制證書(我的是多階段構建) COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM