无法更新现有客户的订购数量

时间:2019-05-24 06:54:39

标签: php stripe-payments payment-gateway subscription

我正在尝试更新现有的条带订阅数量,但出现错误。我不确定我的代码是否正确,因为我是新用户。

我已经检索了现有的订阅详细信息,然后尝试更新订阅数量。

 \Stripe\Stripe::setApiKey(config('services.stripe.secret'));

 $SubscriptionDtl= \Stripe\Subscription::retrieve("sub_F0IJi5YQiZZgKw");
 $quantity=$SubscriptionDtl['quantity'];
 $data=$SubscriptionDtl['data'];
 $customer=$SubscriptionDtl['customer'];
 $plan=$SubscriptionDtl['plan']; 

 try{

    $subscription = \Stripe\Subscription::update([
        'customer' => $customer,
        'items' => [
            [
                'plan' => $plan['id'],
                'quantity' =>$quantity+1,
            ],
        ],
    ]);

}catch(Exception $ex){
    die($ex->getMessage());

}

当前出现以下错误:“ urlencode()期望参数1为字符串,给定数组”

预期为客户更新订阅数量。可以帮我吗?

1 个答案:

答案 0 :(得分:0)

更新以下代码块
$subscription = \Stripe\Subscription::update([
        'customer' => $customer,
        'items' => [
            [
                'plan' => $plan['id'],
                'quantity' =>$quantity+1,
            ],
        ],
    ]);

对此

$subscription = \Stripe\Subscription::update([
        'customer' => $customer,
        'items' => [
            'plan' => $plan['id'],
            'quantity' =>$quantity+1,
        ],
    ]);