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

使用Stripe Connect账户创建AccountSession遇属性未定义错误求助

解决Stripe PHP SDK中$stripe->accountSessions未定义的问题

问题描述

使用Stripe Connected Account创建AccountSession时,执行代码出现错误:

"message": "Undefined property: Stripe\Service\CoreServiceFactory::$accountSessions"

核心原因

这个错误是因为你使用的Stripe PHP SDK版本过低,accountSessions服务是在Stripe PHP SDK v7.100.0版本才引入的,旧版本SDK中没有这个类。

解决步骤

  1. 升级Stripe PHP SDK
    用Composer执行更新命令:

    composer update stripe/stripe-php
    

    升级完成后,确认SDK版本不低于v7.100.0,可通过以下代码查看版本:

    echo \Stripe\Stripe::VERSION;
    
  2. 验证代码正确性
    升级后,确保代码中:

    • 替换api_key为你的真实密钥
    • 替换{{CONNECTED_ACCOUNT_ID}}为实际的关联账户ID
    • 修正语法问题(原代码中catch块的闭合括号位置有误,需确保代码结构完整)

修正后的完整代码示例

$stripe = new \Stripe\StripeClient([
    "api_key" => 'sk_test_你的密钥',
]);

try {
    $account_session = $stripe->accountSessions->create([
        'account' => 'acct_你的关联账户ID',
        'components' => [
            'account_onboarding' => [
                'enabled' => true
            ],
        ],
    ]);

    echo json_encode([
        'client_secret' => $account_session->client_secret
    ]);
} catch (Exception $e) {
    error_log("调用Stripe API创建账户会话时出错: {$e->getMessage()}");
    http_response_code(500);
    echo json_encode(['error' => $e->getMessage()]);
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 03:27:34