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

PHP环境下从Stripe关联账户获取Checkout Session报错求助

解决Stripe关联账户Checkout Session获取报错:The resource ID cannot be null or whitespace

正确代码示例

直接给出可正确获取关联账户Checkout Session的代码写法:

$stripe = new \Stripe\StripeClient('sk_live_......');

// 核心:将stripe_account作为请求选项(第三个参数)传递
$session = $stripe->checkout->sessions->retrieve(
    $_GET['session_id'],
    ['expand' => ['payment_intent']],
    ['stripe_account' => 'acct_.....']
);

报错根源排查

你遇到的The resource ID cannot be null or whitespace错误,核心原因大概率是以下几点:

  • $_GET['session_id']为空或格式错误:即使后台的Session ID正确,也要先验证前端传递的参数有效性,比如添加调试代码:
    var_dump($_GET['session_id']); // 确认输出是cs_开头的合法Session ID
    exit;
    
  • SDK版本兼容性问题:若使用较旧版本的Stripe PHP SDK,stripe_account需要放到第二个参数$params中,而非第三个$options:
    $session = $stripe->checkout->sessions->retrieve(
        $_GET['session_id'],
        [
            'expand' => ['payment_intent'],
            'stripe_account' => 'acct_.....'
        ]
    );
    
  • 关联账户ID不匹配:确认acct_.....是该Session所属的关联账户ID,而非其他账户。

额外排查步骤

  1. 先去掉expand参数,尝试获取基础Session信息,验证是否仍报错:
    $session = $stripe->checkout->sessions->retrieve(
        $_GET['session_id'],
        [],
        ['stripe_account' => 'acct_.....']
    );
    
  2. 升级Stripe SDK到最新稳定版,旧版本可能存在参数解析bug:
    composer update stripe/stripe-php
    

关键说明

关联账户的Checkout Session获取逻辑,就是基于主账户密钥,通过stripe_account选项指定要操作的关联账户,和主账户的获取方法逻辑一致,只是多了这个选项参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 15:45:35