pinax-stripe-light icon indicating copy to clipboard operation
pinax-stripe-light copied to clipboard

Webhooks charge.dispute.* do not run, webhook exception "No such charge dp_..."

Open iarp opened this issue 8 years ago • 1 comments

I was wondering why my charge.dispute.* webhooks were not being called and found the following error in the EventProcesingException table

Request req_A2uKij9DtBcmE9: No such charge: dp_19inKzJpiYFmIJDZDWqmnY1F

With ngrok I'm able to see what is being sent and the following is:

{
  "id": "evt_19inL0JpiYFmIJDZtDhsSWd8",
  "object": "event",
  "api_version": "2017-01-27",
  "created": 1486052494,
  "data": {
    "object": {
      "id": "dp_19inKzJpiYFmIJDZDWqmnY1F",
      "object": "dispute",
      "amount": 6500,
      "charge": "ch_19.......",

"id" is the only instance where dp_19... can be found. The proper charge id can be found in "charge" instead of id.

iarp avatar Feb 02 '17 17:02 iarp

Looking at the webhooks.py I saw the class ChargeWebhook has a def process_webhook method.

I copied that method into the class ChargeDisputeCreatedWebhook and changed from "id" to "charge" and everything works fine. However I know that charge.succeeded and charge.failed work as is so perhaps these dispute ones require another class of their own.

I created a new subclass ChargeDisputeWebhook(Webhook) and applied it to the ChargeDispute* classes and everything works.

class ChargeDisputeWebhook(Webhook):

    def process_webhook(self):
        charges.sync_charge_from_stripe_data(
            stripe.Charge.retrieve(self.event.message["data"]["object"]["charge"])
        )

iarp avatar Feb 02 '17 17:02 iarp