#alexis.saviot

1 messages · Page 1 of 1 (latest)

tired daggerBOT
swift prawn
#

What don't you understand exactly? Can you be more specific?

torn bear
#

@mortal hornet it sounds like you're trying to update the quantity for a specific existing item, is that right?
If so, you need to include id=si_123 of the existing subscription item in the items[0] to indicate that

mortal hornet
#

here is my code, maybe you can explain me my error ? ``` $subscription = $stripe->subscriptions->all([
'customer' => $user['stripe_id'],
]);
$subs = $subscription->data;
foreach($subs as $sub) {
$stripe->subscriptions->update(
$sub->id,
[
'items' => [
'quantity' => $count,
],
],
);
}````I want to update the quantity assigned to an existing subscription

torn bear
#
items' => [ [
             'id' => 'si_123',
             'quantity' => $count1,
          ],
          [
             'id' => 'si_456',
             'quantity' => $count2,
          ],]
#

that id is needed

#

for the item

mortal hornet
#

oh sorry I didn't undestand your previous message, i'll try this

#

thanks

#

ok I get the id for the item, I set it like you show to me, but I still have the same error : Uncaught (Status 400) (Request req_YGIroDCbxjMj5e) Invalid array
thrown

torn bear
#

Let me see

mortal hornet
#

my code updated : ``` public function updatePlan($count, $user)
{
$stripe = new \Stripe\StripeClient($this::$config['STRIPE']['PRIVATE_KEY']);

$subscription = $stripe->subscriptions->all([
  'customer' => $user['stripe_id'],
]);
// var_dump($subscription);die;

$count = $user['credit'] + $count;
$subs = $subscription->data;
foreach($subs as $sub) {
  foreach($sub->items->data as $item) $itemId = $item->id;
  
  $stripe->subscriptions->update(
    $sub->id,
    [
      'items' => [
          'id' => $itemId,
          'quantity' => $count,
      ],
    ],
  );
}

}

torn bear
#

ah, just missing a layer, its an array of objects:

'items' => [ [
              'id' => $itemId,
              'quantity' => $count,
          ] ],

Sorry i missed that above

mortal hornet
#

ok thanks !