#alexis.saviot
1 messages · Page 1 of 1 (latest)
What don't you understand exactly? Can you be more specific?
It should be the same as creation: https://stripe.com/docs/api/subscriptions/create?lang=php
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
@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
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
items' => [ [
'id' => 'si_123',
'quantity' => $count1,
],
[
'id' => 'si_456',
'quantity' => $count2,
],]
that id is needed
for the item
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
Let me see
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,
],
],
);
}
}
ah, just missing a layer, its an array of objects:
'items' => [ [
'id' => $itemId,
'quantity' => $count,
] ],
Sorry i missed that above
ok thanks !