条带 - 创建客户并添加到试用期的计划中

时间:2017-02-03 11:07:11

标签: php stripe-payments

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

\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个异常:异常#0(Stripe \ Error \ InvalidRequest):已收到   未知参数: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
    ),
));

1 个答案:

答案 0 :(得分:0)

好的,我明白了; 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,
));