#idemoov-lo_api

1 messages ¡ Page 1 of 1 (latest)

bright helmBOT
#

👋 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/1413441070905425970

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

digital hound
#
        const charge =
          typeof payment.payment.charge === 'string'
            ? await this.stripeService
                .getInstance()
                .charges.retrieve(payment.payment.charge, { stripeAccount: accountId })
            : payment.payment.charge;

        const balanceTransaction =
          typeof charge.balance_transaction === 'string'
            ? await this.stripeService
                .getInstance()
                .balanceTransactions.retrieve(charge.balance_transaction, {
                  stripeAccount: accountId,
                })
            : charge.balance_transaction;

        application_fee += charge.application_fee_amount ?? 0;
        stripe_fee += (balanceTransaction?.fee ?? 0) - 
(charge.application_fee_amount ?? 0);
        net_amount += balanceTransaction?.net ?? 0;

Code for contexte

#

And with new stripe api version charge no longer exist I think

whole ginkgo
#

Sorry, not exactly clear what it is you're trying to do and what the issue is. How is the invoice.paid event relevant?

#

Can you share the ID (req_xxx) of your request that errors/doesn't work as you expect?

whole ginkgo
digital hound
#
async handleInvoicePaid(invoice: Stripe.InvoicePaidEvent['data']['object'], accountId?: string) {
    const customerId =
      typeof invoice.customer === 'string' ? invoice.customer : invoice.customer.id;
    const user = await this.userRepository.findOneOrFail({
      where: {
        stripeCustomerId: customerId,
        operator: accountId ? { stripeAccountId: accountId } : undefined,
      },
      withDeleted: true,
    });

    // Get charge and balance transaction to retrieve fee information
    if (invoice.status === 'paid') {
      let application_fee = 0;
      let stripe_fee = 0;
      let net_amount = 0;
      let paymentMethod: Stripe.PaymentMethod;
      const payments = await this.stripeService.getInvoicesPayements(
        { invoice: invoice.id },
        accountId,
      );
      if (payments.length === 0) {
        this.logger.error(`No payments found for invoice ${invoice.id}`);
        return;
      }
      for (let i = 0; i < payments.length; i++) {
        const payment = payments[i];
        if (i === 0) {
          let paymentIntent: Stripe.PaymentIntent;
          if (typeof payment.payment.payment_intent === 'string') {
            paymentIntent = await this.stripeService.getPaymentIntent(
              payment.payment.payment_intent,
              accountId,
            );
          } else {
            paymentIntent = payment.payment.payment_intent;
          }
          if (typeof paymentIntent.payment_method === 'string') {
            paymentMethod = await this.stripeService.getPaymentMethod(
              paymentIntent.payment_method,
              accountId,
            );
          } else {
            paymentMethod = paymentIntent.payment_method;
          }
        }

Here's the start of code

#

I don't understand why payment.payment.charge is undefined

#

It's because it was removed too no ?

whole ginkgo
#

Ignore me, one sec

#

Can you share the in_xxx ID of an invoice this code isn't working for?

digital hound
#

probably this one from the event in_1S3cwt5EyZyp1Ds5dkl4blfb

whole ginkgo
#

I guess in_1S3cwt5EyZyp1Ds5dkl4blfb from the event you shared?

#

And this code:

const payments = await this.stripeService.getInvoicesPayements(
        { invoice: invoice.id },
        accountId,
      );

returns a list of objects?

#

What's the actual ch_xxx value payment.payment.charge resolves to?

#

You're going to need to add some logging really, I'm struggling to understand how all the code comes together as you shared it in two blocks

digital hound
#

[Nest] 18 - 09/04/2025, 11:27:32 AM ERROR [TypeError: Cannot read properties of undefined (reading 'balance_transaction')
I think it's unefined

#

Yes I can add logging and retry

#

async getInvoicesPayements(params: Stripe.InvoicePaymentListParams, accountId?: string) {
const payments = await this.stripe.invoicePayments.list(params, { stripeAccount: accountId });
return payments.data;
}

Here's getInvoicesPayements maybe it's here I forgot something

whole ginkgo
#

Can you find the req_xxx ID for this request:

                .getInstance()
                .charges.retrieve(payment.payment.charge, { stripeAccount: accountId })```
#

I don't see any requests to /v1/invoice_payments (endpoint on the account that invoice belongs to. So I think you're not setting the Stripe-Account header correctly

#

Is accountId definitely set?

digital hound
#

req_0WjkBXcjieQ2Se
Like this one yes but I may have fucked up something because I see some request made to the charge endpoint too

whole ginkgo
#

Does this call actually return a Charge object:

                .getInstance()
                .charges.retrieve(payment.payment.charge, { stripeAccount: accountId })```
digital hound
#

I think you can close the issue for now I will add a lot of login so I see exactly what's wrong

#

Probably was me really sorry

whole ginkgo
#

Yeah I suspect somewhere some API call is not returning an object your code expects (likely a missing API param). I'd figure which that is first and then it'll likely be an obvious fix