#Mathieu-inovices
1 messages ยท Page 1 of 1 (latest)
sub_1Jtab7D9WJsCYyaSCRVPGJ6h
Thanks for the ID, can you also share with me the code that give you the error?
You mean my backend code ?
Yes please
public function getEstimatedAmounts(Organization $organization, array $items, bool $withLines = false): array
{
$invoiceOption = [
'customer' => $this->getCustomerId($organization),
'subscription_items' => $this->getFormattedSubscriptionItems($items),
'subscription_default_tax_rates' => [$this->getDefaultTaxRateId()],
];
if ($withLines) {
$invoiceOption['expand'] = ['lines.data.price.product'];
}
$subscriptionId = $organization->getStripeSubscriptionId();
if ($subscriptionId) {
$invoiceOption['subscription'] = $subscriptionId;
$invoiceOption['subscription_proration_behavior'] = 'always_invoice';
}
$invoice = $this->stripeClient->invoices->upcoming($invoiceOption);
$toReturn = [
'subtotal' => NumberUtils::convertCentsToEuro($invoice->subtotal),
'tax' => NumberUtils::convertCentsToEuro($invoice->tax),
'total' => NumberUtils::convertCentsToEuro($invoice->total),
];
if ($withLines) {
$lines = [];
foreach ($invoice['lines'] as $line) {
$lines[$line['price']['product']['name']] = [
'amount' => NumberUtils::convertCentsToEuro($line['amount']),
'quantity' => $line['quantity']
];
}
$toReturn['lines'] = $lines;
}
return $toReturn;
}
the getFormattedSubscriptionItems method return items like this :
[
"price" => price_XXX,
"quantity" => 1,
]
Is this statement $invoice = $this->stripeClient->invoices->upcoming($invoiceOption); giving you the error ?
yes
if in subscription_items there is price id that are not in the subscription it's working well but if the price id are already on the subscription it fails with the mention error "Cannot add multiple subscription items with the same plan: price_XXXXXXXXX"
Are you able to print out the $invoiceOption object that is passed to the $stripeClient->invoices->upcoming?
hum should i pass the subscription item id in the subscription_items array for it to work ?
yeah it's working now that i pass it in the subscription_items i think it is what i was missing
That is great, so you just add in the id into the subscription_items array?
yep, if the user want's to update the quantity of an item on his subscription i must provide the subscription item id. I'm gonna update my model to take that in account.
Thanks for your help on debugging this with me ๐
Don't mention it, the problem is mostly solved by you ๐