使用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中没有这个类。
解决步骤
升级Stripe PHP SDK
用Composer执行更新命令:composer update stripe/stripe-php升级完成后,确认SDK版本不低于v7.100.0,可通过以下代码查看版本:
echo \Stripe\Stripe::VERSION;验证代码正确性
升级后,确保代码中:- 替换
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
相关产品推荐
相关产品推荐

