You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Stripe JS v1至v3时出现Stripe.setPublishableKey不是函数错误求解决

Fixing "Stripe.setPublishableKey is not a function" in Stripe.js v3

Hey there! That error makes total sense because Stripe.js v3 completely changed how you initialize the library—setPublishableKey was a v1-specific method that got removed in the v3 rewrite. Here's how to fix it step by step:

  • First, confirm you're loading the correct Stripe.js version
    Make sure your script tag points to v3, not the old v1. The valid v3 script import looks like this:

    <script src="https://js.stripe.com/v3/"></script>
    
  • Replace setPublishableKey with a Stripe instance
    In v1, you'd initialize the library like this (which won't work in v3):

    // Old v1 code (deprecated)
    Stripe.setPublishableKey('pk_test_YourPublishableKeyHere');
    

    In v3, you create a Stripe instance directly by passing your publishable key as an argument:

    // New v3 code
    const stripe = Stripe('pk_test_YourPublishableKeyHere');
    

    You'll use this stripe instance for all subsequent operations—like creating payment elements, generating tokens, or handling payments.

  • Update other v1-specific methods
    If you had other v1 code (like Stripe.createToken), you'll need to switch to instance methods too. For example:

    // Old v1 token creation
    Stripe.createToken(cardElement, function(status, response) { /* handle response */ });
    
    // New v3 token creation (promise-based)
    stripe.createToken(cardElement).then(function(result) {
      if (result.error) {
        // Handle error
      } else {
        // Use the token
      }
    });
    

That should clear up the error and get your Stripe v3 integration running smoothly!

内容的提问来源于stack exchange,提问作者user9495286

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:46:16