GithubHelp home page GithubHelp logo

Comments (9)

stanmattingly avatar stanmattingly commented on June 24, 2024 1

@arnav13081994 sorry for the delayed response here. We just had another come through that is failing to sync. Here is what the item json looks like:

{ amount: -20807, amount_excluding_tax: -20807, currency: 'usd', description: 'Unused time on Basic after 26 Jan 2023', discount_amounts: [ { amount: 0, discount: 'di_1MUcN9BrbFy7JWmB6zU6YBv7' } ], discountable: False, discounts: [], id: 'il_1MUcN9BrbFy7JWmBGWNb4Zt9', invoice_item: 'ii_1MUcN9BrbFy7JWmBCYdLtzTl', object: 'line_item' }

In the same error stack, the api is returning that the invoice is not existent as well. This is 100% related to proration line items that stripe automatically generates.

from dj-stripe.

arnav13081994 avatar arnav13081994 commented on June 24, 2024 1

@dustinblanchard Turns out the root cause of this issue is that the SubscriptionItems referred in the JSON are actually deleted and hence the sync was failing as it should have. Raised a PR to just ignore such errors so at least the sync will no longer fail.

from dj-stripe.

dustinblanchard avatar dustinblanchard commented on June 24, 2024

@jleclanche Any thoughts here? If there is an easy way to identify these special Subscription Items, @stanmattingly and I can potentially work on a PR.

from dj-stripe.

jleclanche avatar jleclanche commented on June 24, 2024

Very difficult to say without access to the stripe account.

from dj-stripe.

arnav13081994 avatar arnav13081994 commented on June 24, 2024

@stanmattingly What dj-stripe version are you on?

from dj-stripe.

stanmattingly avatar stanmattingly commented on June 24, 2024

@arnav13081994 We are on 2.8.3

from dj-stripe.

arnav13081994 avatar arnav13081994 commented on June 24, 2024

@stanmattingly Not able to reproduce this issue. Please share the SubscriptionItem json if possible. It might be some case that we might have missed.

from dj-stripe.

mikedom avatar mikedom commented on June 24, 2024

I'm getting a sync failure as well from any event that is attached to a customer that changed their subscription (so there is a proration amount). The error from dj-stripe is:

InvalidRequestError at /stripe/webhook/<wh_id>/
Request req_<req_id>: Invalid subscription_item id: si_<si_id>
Some of the data looks like:
       "object": "line_item",
            "amount": -917,
            "amount_excluding_tax": -917,
            "currency": "usd",
            "description": "Unused time on <product> after 11 Dec 2023",

I'm using version 2.8.3

from dj-stripe.

dustinblanchard avatar dustinblanchard commented on June 24, 2024

@arnav13081994 @jleclanche

We've ended up monkey patching StripeModel._stripe_object_to_line_items to ignore any with "unused time" in the description. This feels like a hacky approach but we couldn't find anything else to key off of.

        @classmethod
        def presshook_stripe_object_to_line_items(
            cls, target_cls, data, invoice, api_key=djstripe_settings.STRIPE_SECRET_KEY
        ):
            lines = data.get("lines")
            if not lines:
                return []

            lineitems = []
            for line in lines.auto_paging_iter():
                # Skip line items that cause errors from proration
                if "unused time" in line.get("description", "").lower():
                    continue

                if invoice.id:
                    save = True
                    line.setdefault("invoice", invoice.id)

                else:
                    # Don't save invoice items for ephemeral invoices
                    save = False

                line.setdefault("customer", invoice.customer.id)
                line.setdefault("date", int(dateformat.format(invoice.created, "U")))

                item, _ = target_cls._get_or_create_from_stripe_object(
                    line, refetch=False, save=save, api_key=api_key
                )
                lineitems.append(item)

            return lineitems

        StripeModel._stripe_object_to_line_items = presshook_stripe_object_to_line_items

from dj-stripe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.