#jain-kunal_error

1 messages ยท Page 1 of 1 (latest)

unique canyonBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1379848281927979009

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

ashen sundial
#

Hi can you share the request id where you're getting this error

brazen sage
#

req_AyRFb5dVwGzU88
req_uuPc3DEZmjMvFs
req_F6X49PSw4mwL4J
req_TrYRh9BTYMr34e
req_9aS7zOnl1HgLQz

unique canyonBOT
obtuse aspen
#

Hey there, I'm taking over from my colleague. Let me take a look.

#

Looking at req_AyRFb5dVwGzU88 the customer cus_SPJpCtUfMyhDgI being used in the request is associated with another account. Not the account (acct_1RRuFjPG0QhJ8OcG) you're making the request on.

#

That's why the error is being returned.

#

I recommend double checking to make sure you're using the API keys associated with the account the customer was created on.

brazen sage
#

let customerId = "";

    const existingCustomers = await stripe.customers.list({
        email: contractor?.email,
        limit: 1
    }, {
        stripeAccount: contractor?.accountId
    });

    customerId = existingCustomers?.data?.[0]?.id;

    if(!existingCustomers || existingCustomers.data.length === 0 || !customerId) {
        const customer = await stripe.customers.create({
            email: contractor.email,
            name: contractor?.fullName,
            metadata: {
                userId: contractor?.id,
                accountId: contractor?.accountId
            }
        }, {
            stripeAccount: contractor?.accountId // Create customer on the connected account
        });
        customerId = customer?.id;
    }

     // Create Stripe invoice
    const invoice = await stripe.invoices.create({
        customer: customerId,
        currency: job?.currency || 'mxn',
        metadata: {
            jobId: job.id,
            contractorId: job.contractorId,
            transferGroup: job.id
        },
        description: `Payment for job completion - Job ID: ${job.id}`,
        auto_advance: true, // Automatically finalize the invoice
    });

    // Add invoice item
    await stripe.invoiceItems.create({
        customer: accountId,
        invoice: invoice.id,
        amount: parseFloat(job?.totalAmount) * 100 || 0, // Convert to cents
        currency: job?.currency || 'mxn',
        description: job?.description || `Job completion payment`,
        metadata: {
            jobId: job.id,
            contractorId: job.contractorId
        }
    });

    // Finalize the invoice
    const finalizedInvoice = await stripe.invoices.finalizeInvoice(invoice.id);
#

I am kind of using this part.

#

trying with same accoutn id and customer id.

brazen sage
obtuse aspen
#

Sorry, we won't be able to connect on a call.

#

I took a look at the customer creation request and I can see that the customer was created on an Express Connected Account via the Platform Account (acct_1RRuFjPG0QhJ8OcG). So in this case the customer cus_SPJpCtUfMyhDgI is on the connected account not the platform. So you're request to created the invoice should be on the connected account.

brazen sage
#

my use case is create invoice bank transfer after their trnasfer is done.
can I do for this as well?

obtuse aspen
#

Can you clarify your question please.

brazen sage
#

I want to create an invoice after a client has completed a bank transfer (not before). Is it possible to generate the invoice after confirming the transfer is done?

#

My use case is to create an invoice for a bank transfer after the customer has completed the transfer. Can Stripe support this?

For example:

A client sends a bank transfer using Stripe.

After I confirm the payment is received in the bank, I want to generate an invoice in Stripe for accounting/record purposes.

I don't want to create a payment link or invoice before the bank transfer โ€” only after it's confirmed.

Is there a recommended way to handle this flow in Stripe?

obtuse aspen
#

That's not invoices work in the Stripe sense. You're referring to a receipt of payment.

unique canyonBOT