【问题标题】:Stripe - Create Customer and add to a plan with trial periodStripe - 创建客户并添加到具有试用期的计划中
【发布时间】:2017-02-03 11:07:11
【问题描述】:

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

\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
    ),
));

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-26
      • 2016-09-06
      • 2016-11-18
      • 2019-06-21
      • 2021-02-20
      • 2023-01-18
      • 2017-04-20
      • 2014-11-12
      相关资源
      最近更新 更多