gpt4 book ai didi

php - Stripe - 创建客户并添加到具有试用期的计划

转载 作者:行者123 更新时间:2023-12-05 05:21:49 29 4
gpt4 key购买 nike

我能够创建客户并将其添加到订阅计划;以下代码有效:

\Stripe\Stripe::setApiKey("sk_test_tz7AKV73RPCd7p**********");

// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"plan" => $plan_id,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));

然后如果我添加一个 trial_period_days"=> 30 选项,我会收到以下错误:

1 exception(s): Exception #0 (Stripe\Error\InvalidRequest): Received unknown parameter: trial_period_days

我将其添加到选项散列中,如下所示:

// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"plan" => $plan_id,
"trial_period_days" => 30,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));

最佳答案

好的,我知道了; trial_period_days 是一个应该在 Subscription 创建期间使用的参数,所以我按如下方式编辑了我的代码:

// create Customer
$customer = \Stripe\Customer::create(array(
"email" => $email,
"source" => $token,
"metadata" => array(
"nome" => $name,
"tel" => $tel,
"indirizzo" => $indirizzo,
"città" => $address_city,
"provincia" => $address_state,
"cap" => $address_zip
),
));

// associate Customer to the Plan
\Stripe\Subscription::create(array(
"customer" => $customer,
"plan" => $plan_id,
"trial_period_days" => 30,
));

关于php - Stripe - 创建客户并添加到具有试用期的计划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42022784/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com