pinax / pinax-stripe-light

a payments Django app for Stripe
MIT License
686 stars 285 forks source link

"No such charge" errors with charge.dispute.funds_withdrawn #590

Open blueyed opened 6 years ago

blueyed commented 6 years ago

charge.dispute.funds_withdrawn events get processed through the ChargeWebhook, but that fails, because it tried to fetch dp_XXX as a charge.

Example event:

{
  "id": "evt_1D9mkxEsFcHZcT2Dtd91RhSB",
  "object": "event",
  "account": "acct_XXX",
  "api_version": "2017-08-15",
  "created": 1536814123,
  "data": {
    "object": {
      "id": "dp_XXX",
      "object": "dispute",
      "amount": 851,
      "balance_transaction": "txn_XXX",
      "balance_transactions": [
        {
          "id": "txn_XXX",
          "object": "balance_transaction",
          "amount": -851,
          "available_on": 1536796800,
          "created": 1536814122,
          "currency": "usd",
          "description": "Chargeback withdrawal for ch_XXX",
          "exchange_rate": null,
          "fee": 1500,
          "fee_details": [
            {
              "amount": 1500,
              "application": null,
              "currency": "usd",
              "description": "Dispute fee",
              "type": "stripe_fee"
            }
          ],
          "net": -2351,
          "source": "dp_XXX",
          "status": "available",
          "type": "adjustment"
        }
      ],
      "charge": "ch_XXX",
      "created": 1536814121,
      "currency": "usd",
      "evidence": {
        "access_activity_log": null,
        "billing_address": "\nUS",
        "cancellation_policy": null,
        "cancellation_policy_disclosure": null,
        "cancellation_rebuttal": null,
        "customer_communication": null,
        "customer_email_address": "bedreib@gmail.com",
        "customer_name": null,
        "customer_purchase_ip": "107.77.224.235",
        "customer_signature": null,
        "duplicate_charge_documentation": null,
        "duplicate_charge_explanation": null,
        "duplicate_charge_id": null,
        "product_description": null,
        "receipt": "file_1D9mkvEsFcHZcT2DXEvpPVh9",
        "refund_policy": null,
        "refund_policy_disclosure": null,
        "refund_refusal_explanation": null,
        "service_date": null,
        "service_documentation": null,
        "shipping_address": null,
        "shipping_carrier": null,
        "shipping_date": null,
        "shipping_documentation": null,
        "shipping_tracking_number": null,
        "uncategorized_file": null,
        "uncategorized_text": null
      },
      "evidence_details": {
        "due_by": 1537660799,
        "has_evidence": false,
        "past_due": false,
        "submission_count": 0
      },
      "is_charge_refundable": false,
      "livemode": true,
      "metadata": {},
      "reason": "duplicate",
      "status": "needs_response"
    }
  },
  "livemode": true,
  "pending_webhooks": 1,
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "charge.dispute.created"
}
InvalidRequestError: Request req_XXX: No such charge: dp_XXX
  File "velodrome/lock8/utils.py", line 385, in ingest_stripe_event
    message=data)
  File "pinax/stripe/actions/events.py", line 39, in add_event
    webhook.process()
  File "pinax/stripe/webhooks.py", line 138, in process
    raise e
  File "pinax/stripe/webhooks.py", line 129, in process
    self.process_webhook()
  File "pinax/stripe/webhooks.py", line 248, in process_webhook
    stripe_account=self.event.stripe_account_stripe_id,
  File "pinax/stripe/actions/charges.py", line 170, in sync_charge
    retrieve(stripe_id, stripe_account=stripe_account)
  File "pinax/stripe/actions/charges.py", line 152, in retrieve
    expand=["balance_transaction"]
  File "stripe/api_resources/abstract/api_resource.py", line 13, in retrieve
    instance.refresh()
  File "stripe/api_resources/abstract/api_resource.py", line 17, in refresh
    self.refresh_from(self.request('get', self.instance_url()))
  File "stripe/stripe_object.py", line 207, in request
    response, api_key = requestor.request(method, url, params, headers)
  File "stripe/api_requestor.py", line 94, in request
    resp = self.interpret_response(rbody, rcode, rheaders)
  File "stripe/api_requestor.py", line 306, in interpret_response
    self.handle_error_response(rbody, rcode, resp.data, rheaders)
  File "stripe/api_requestor.py", line 119, in handle_error_response
    raise err