django-paypal icon indicating copy to clipboard operation
django-paypal copied to clipboard

application/json vs application/x-www-form-urlencoded

Open basictheprogram opened this issue 1 year ago • 0 comments

Using the Webhooks simulator in 2023-Aug it looks like a events Content-type are application/json. This code will not work

    # Avoid the RawPostDataException. See original issue for details:
    # https://github.com/spookylukey/django-paypal/issues/79
    if not request.META.get("CONTENT_TYPE", "").startswith("application/x-www-form-urlencoded"):
        raise AssertionError(CONTENT_TYPE_ERROR)

Example from the Webhook simulator

{
  "id": "WH-4YP718828D2768154-96229356YL4818534",
  "create_time": "2015-10-07T16:45:17Z",
  "resource_type": "sale",
  "event_type": "PAYMENT.SALE.DENIED",
  "summary": "A EUR 17.47 EUR sale payment was denied",
  "resource": {
    "parent_payment": "PAY-9SM48294F4717633YKYKUXNQ",
    "update_time": "2015-10-07T16:43:35Z",
    "amount": {
      "total": "17.47",
      "currency": "EUR"
    },
    "payment_mode": "INSTANT_TRANSFER",
    "create_time": "2015-10-07T16:43:35Z",
    "protection_eligibility": "INELIGIBLE",
    "links": [
      {
        "href": "https://api.paypal.com/v1/payments/sale/0UV619993K905211J",
        "rel": "self",
        "method": "GET"
      },
      {
        "href": "https://api.paypal.com/v1/payments/sale/0UV619993K905211J/refund",
        "rel": "refund",
        "method": "POST"
      },
      {
        "href": "https://api.paypal.com/v1/payments/payment/PAY-9SM48294F4717633YKYKUXNQ",
        "rel": "parent_payment",
        "method": "GET"
      }
    ],
    "id": "0UV619993K905211J",
    "state": "denied"
  },
  "links": [
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-4YP718828D2768154-96229356YL4818534",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-4YP718828D2768154-96229356YL4818534/resend",
      "rel": "resend",
      "method": "POST",
      "encType": "application/json"
    }
  ],
  "event_version": "1.0"
}```

basictheprogram avatar Aug 22 '23 19:08 basictheprogram