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

调用Cashier Stripe集成的createOrGetStripeCustomer函数时遇无效对象错误

解决Stripe Cashier createOrGetStripeCustomer()的「Invalid object」错误

问题出在你的stripeAddress()方法返回值格式不符合Stripe的要求。Stripe要求地址是结构化的对象,而非拼接后的字符串。

正确实现方式

修改stripeAddress()方法,返回符合Stripe规范的关联数组:

/**
 * Get the customer address that should be synced to Stripe.
 */
public function stripeAddress(): array|null
{
    // 若所有地址字段为空,返回null避免无效对象
    if (empty($this->address_line1) && empty($this->address_line2) && empty($this->postal_code) && empty($this->country)) {
        return null;
    }

    return [
        'line1' => $this->address_line1,
        'line2' => $this->address_line2,
        'postal_code' => $this->postal_code,
        'country' => $this->country,
    ];
}

错误原因

  • Stripe的Customer对象中address字段需要是包含line1、line2、postal_code、country等键的结构化对象,而非字符串。
  • 原方法返回的拼接字符串无法被Stripe解析为有效地址对象,因此触发「Invalid object」错误。
  • 新增空值判断,避免传递全空的地址结构给Stripe。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 08:52:08