juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
12.08k stars 1.27k forks source link

fix(connector): [Paypal] dispute webhook deserialization failure #5111

Closed KiranKBR closed 3 months ago

KiranKBR commented 3 months ago

Type of Change

Description

This refactored branch resolves the PayPal dispute webhook deserialization issue. -> It was failing to identify the webhook entity type and object reference ID. -> I updated the fields accordingly to resolve the deserialization issue.

Additional Changes

Motivation and Context

Motivation https://github.com/juspay/hyperswitch/issues/5069

there are some filed refactors included which resolved the problem

How did you test it?

I ran the ngrok for frowarding webhook payload to localhost with url (https://697b-219-65-110-2.ngrok-free.app/webhooks/merchant_1719300138/paypal)

I have created dispute webhook through paypal simulator and these are the logs : Incoming webhook Payload:

{
  "id": "WH-4M0448861G563140B-9EX36365822141321",
  "create_time": "2018-06-21T13:36:33.000Z",
  "resource_type": "dispute",
  "event_type": "CUSTOMER.DISPUTE.CREATED",
  "summary": "A new dispute opened with Case # PP-000-042-663-135",
  "resource": {
    "disputed_transactions": [
      {
        "seller_transaction_id": "00D10444LD479031K",
        "seller": {
          "merchant_id": "RD465XN5VS364",
          "name": "Test Store"
        },
        "items": [],
        "seller_protection_eligible": true
      }
    ],
    "reason": "MERCHANDISE_OR_SERVICE_NOT_RECEIVED",
    "dispute_channel": "INTERNAL",
    "update_time": "2018-06-21T13:35:44.000Z",
    "create_time": "2018-06-21T13:35:44.000Z",
    "messages": [
      {
        "posted_by": "BUYER",
        "time_posted": "2018-06-21T13:35:52.000Z",
        "content": "qwqwqwq"
      }
    ],
    "links": [
      {
        "href": "https://api.paypal.com/v1/customer/disputes/PP-000-042-663-135",
        "rel": "self",
        "method": "GET"
      },
      {
        "href": "https://api.paypal.com/v1/customer/disputes/PP-000-042-663-135/send-message",
        "rel": "send_message",
        "method": "POST"
      }
    ],
    "dispute_amount": {
      "currency_code": "USD",
      "value": "3.00"
    },
    "dispute_id": "PP-000-042-663-135",
    "dispute_life_cycle_stage": "INQUIRY",
    "status": "OPEN"
  },
  "links": [
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-4M0448861G563140B-9EX36365822141321",
      "rel": "self",
      "method": "GET",
      "encType": "application/json"
    },
    {
      "href": "https://api.paypal.com/v1/notifications/webhooks-events/WH-4M0448861G563140B-9EX36365822141321/resend",
      "rel": "resend",
      "method": "POST",
      "encType": "application/json"
    }
  ],
  "event_version": "1.0"
}

Dispute Creation:

image

Source Verification: Due to these are Mock events , we cant verify them through Paypal so I have done source verification as true to check further flows like Database record creation and triggering outgoing webhooks.

Database Record Creation:

image

Outgoing Webhook Response Payload:

{
    "merchant_id": "merchant_1719481316",
    "event_id": "evt_0190594e16ab7f38abd50ca6f32707b9",
    "event_type": "dispute_opened",
    "content": {
        "type": "dispute_details",
        "object": {
            "dispute_id": "dp_rgC7BN7DQRQ9YlksqCmO",
            "payment_id": "pay_qW4qVbLZXOO1GQsd0mQ3",
            "attempt_id": "00D10444LD479031K",
            "amount": "300",
            "currency": "USD",
            "dispute_stage": "pre_dispute",
            "dispute_status": "dispute_opened",
            "connector": "paypal",
            "connector_status": "Open",
            "connector_dispute_id": "PP-000-042-663-135",
            "connector_reason": "MERCHANDISE_OR_SERVICE_NOT_RECEIVED",
            "connector_reason_code": "MERCHANDISE_OR_SERVICE_NOT_RECEIVED",
            "challenge_required_by": null,
            "connector_created_at": "2018-06-21T13:35:44.000Z",
            "connector_updated_at": "2018-06-21T13:35:44.000Z",
            "created_at": "2024-06-27T10:46:48.214Z",
            "profile_id": "pro_AKqLxMihwY7h8QqvuPfH",
            "merchant_connector_id": "mca_q1lwLDnNEPzyGvClsHsR"
        }
    },
    "timestamp": "2024-06-27T10:46:48.235Z"
}

Checklist