#Nagual
1 messages · Page 1 of 1 (latest)
Hi Jack
And this is code prior to calling create item lines
const itemsGroupedByItemType: ItemsByItemType = itemsToProcess.reduce<{ [itemTypeId: string]: LeanDocument<ItemDocument>[] }>((acc, item) => {
const itemTypeId = item.itemType.toString();
if (!acc[itemTypeId]) {
acc[itemTypeId] = [];
}
acc[itemTypeId].push(item);
return acc;
}, {});
const { invoiceUrl, invoiceId, clientStripeId } = await this.paymentService.createDraftInvoice({ clientId });
for (const itemTypeId in itemsGroupedByItemType) {
const items = itemsGroupedByItemType[itemTypeId];
this.logger.log(`Item being charged: ${JSON.stringify(items, null, 2)}`);
await this.paymentService.createLineItems({ clientStripeId, invoiceId, items });
}
Can you tell what you expect and what you get?
I expect to add multiple line items to one draft invoice, but right now what is happening it creates one line item and adds all quantities to it
Each line should be a different product in stripe
This is my customer right now
And If I want to charge this invoice right now
Everything will end up in first item
Like it happened here
What does itemCount resolve to?
Qty that you see in query
I group items by itemType, pass that in a loop
count them for qty
Can you share the request IDs? Here's how you can find them: https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
req_luKWTVOER6U2pB
Here everything is already groped in one lineItem
OK, so I saw you've sent a request to create a line item of 2525 quality, is it what you intent to do?
No, in my logs it was shown that multiple itemTypes were sent to the loop
Is it possible that invoiceItems.create doesn't create one item at a time?
and it waits until I do invoice.pay?
Does itemsGroupedByItemType() return a new array? or it basically just adding new items to acc array?
What it does it creates new object:
{itemTypeId: [items], itemTypeId:[items]}
Also based on what I see in the invoice logs (https://dashboard.stripe.com/test/invoices/in_1My2YXEXgt2M1K6ktkwYRmi9), your code only create one invoice item and its amount is 2525
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I don't see any other POST request to create another invoice item.
I'm setting new logs in the flow to follow and make sure proper items are passed. I'll write back in maybe 10 minutes
Is that ok?
There's a possibility that your code only execute the loop once, and therefore only one invoice item is added.
I'd suggest you to put more logs in your code and debug.
Sure, let me know if you need any other help when you are back
Thank you Jack
Jack just letting you, you were spot on.
Issue was in itemsGroupedByItemType.
const itemType = item.itemType as any as ItemTypeDocument;
const itemTypeId: string = itemType._id.toString();
This solved the issue
It was casting itemTypeId to object instead of string and than it just put all in the same array