pinax-stripe-light
pinax-stripe-light copied to clipboard
Webhooks charge.dispute.* do not run, webhook exception "No such charge dp_..."
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.
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"])
)