Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 11 commits into from
Jul 1, 2024

Conversation

KiranKBR
Copy link
Contributor

@KiranKBR KiranKBR commented Jun 25, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

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

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

Motivation #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

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@KiranKBR KiranKBR added the C-refactor Category: Refactor label Jun 25, 2024
@KiranKBR KiranKBR self-assigned this Jun 25, 2024
@KiranKBR KiranKBR requested a review from a team as a code owner June 25, 2024 00:11
@KiranKBR KiranKBR linked an issue Jun 25, 2024 that may be closed by this pull request
@KiranKBR KiranKBR changed the title do refactor for dispute webhook issue refactor(connector): do changes for paypal dispute webhook issue Jun 25, 2024
swangi-kumari
swangi-kumari previously approved these changes Jun 25, 2024
@swangi-kumari swangi-kumari added the A-connector-integration Area: Connector integration label Jun 25, 2024
Copy link
Contributor

@swangi-kumari swangi-kumari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hii @KiranKBR ,

  1. Please add a proper title and description for this PR.
  2. Please attach all the test cases and db screenshots.

@KiranKBR KiranKBR changed the title refactor(connector): do changes for paypal dispute webhook issue refactor(connector): do changes for paypal dispute webhook deserialisation issue Jun 26, 2024
@KiranKBR KiranKBR changed the title refactor(connector): do changes for paypal dispute webhook deserialisation issue refactor(connector): do changes for paypal dispute webhook deserialization issue Jun 26, 2024
@KiranKBR KiranKBR changed the title refactor(connector): do changes for paypal dispute webhook deserialization issue refactor(connector): refactor for paypal dispute webhook deserialization issue Jun 26, 2024
srujanchikke
srujanchikke previously approved these changes Jun 27, 2024
@KiranKBR KiranKBR changed the title refactor(connector): refactor for paypal dispute webhook deserialization issue fix(connector): [Paypal] refactor for paypal dispute webhook deserialization issue Jun 27, 2024
@KiranKBR KiranKBR changed the title fix(connector): [Paypal] refactor for paypal dispute webhook deserialization issue fix(connector): [Paypal] fix dispute webhook deserialization failure Jun 27, 2024
@KiranKBR KiranKBR force-pushed the paypal-dispute-webhook-issue branch from 8b15b40 to 27144e2 Compare June 27, 2024 11:12
@sai-harsha-vardhan sai-harsha-vardhan changed the title fix(connector): [Paypal] fix dispute webhook deserialization failure fix(connector): [Paypal] dispute webhook deserialization failure Jun 27, 2024
.first()
.map(|transaction| transaction.reference_id.clone())
.map(|transaction| transaction.seller_transaction_id.clone())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If seller_transaction_id is not our id, we should change PaymentIdType to ConnectorTransactionId instead of PaymentAttemptId

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be seller_transaction_id

| PaypalWebhookEventType::CustomerDisputeResolved
| PaypalWebhookEventType::CustomerDisputedUpdated
| PaypalWebhookEventType::RiskDisputeCreated => Some(
PaypalWebhookEventType::CustomerDisputeResolved => Some(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check the outcome code for all the Dispute events right, why is this change required here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They r sending outcome_code for resolved events only

transformers::PaypalResource::PaypalCardWebhooks(_)
| transformers::PaypalResource::PaypalRedirectsWebhooks(_)
| transformers::PaypalResource::PaypalRefundWebhooks(_) => {
Err(errors::ConnectorError::WebhookResourceObjectNotFound.into())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of throwing Badrequest (4xx) here, can we make it as a 5xx?

@KiranKBR KiranKBR force-pushed the paypal-dispute-webhook-issue branch from 43c50ef to 39c1616 Compare June 28, 2024 07:02
PaypalWebhookEventType::PaymentAuthorizationCreated
PaypalWebhookEventType::CustomerDisputeCreated
| PaypalWebhookEventType::RiskDisputeCreated
| PaypalWebhookEventType::CustomerDisputedUpdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, we should get outcome_code for CustomerDisputedUpdated to identify the event. Can we please check?

Copy link
Contributor Author

@KiranKBR KiranKBR Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked, we are not getting outcome_code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please share the sample payload for CustomerDisputedUpdated event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have shared u via slack

transformers::PaypalResource::PaypalCardWebhooks(_)
| transformers::PaypalResource::PaypalRedirectsWebhooks(_)
| transformers::PaypalResource::PaypalRefundWebhooks(_) => {
Err(errors::ConnectorError::ResponseDeserializationFailed.into())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have an attach_printable here?

Copy link
Contributor Author

@KiranKBR KiranKBR Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@KiranKBR KiranKBR force-pushed the paypal-dispute-webhook-issue branch from b1eef65 to e9a39d8 Compare July 1, 2024 06:52
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 1, 2024
Merged via the queue into main with commit af2497b Jul 1, 2024
11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the paypal-dispute-webhook-issue branch July 1, 2024 12:32
pixincreate added a commit that referenced this pull request Jul 2, 2024
…ror-handling-in-cypress

* 'main' of github.com:juspay/hyperswitch:
  fix(auth_methods): Add checks for duplicate `auth_method` in create API (#5161)
  chore(version): 2024.07.02.0
  fix(router): rename the browser name header to `x-browser-name` (#5162)
  fix(router): mark retry payment as failure if `connector_tokenization` fails (#5114)
  fix(connector): [Paypal] dispute webhook deserialization failure (#5111)
  feat(analytics): Add v2 payment analytics (payment-intents analytics) (#5150)
  feat(globalsearch): Implement tag-based filters in global search (#5151)
  refactor(connector): Add amount conversion framework to iatapay along with amount conversion code to connector template (#4866)
  feat(payment_link): add multiple custom css support in business level  (#5137)
  feat(connector): [Bambora Apac] Template for integration (#5062)
  feat(tls): add support for https in actix web (#5089)
  chore(ci): fix ci tests failing by removing them (#5167)
  chore(version): 2024.07.01.0
  chore(postman): update Postman collection files
  ci(postman): log request id for user tests (#5159)
  chore(euclid_wasm): make field domain optional wasm (#5154)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paypal webhook disputes
5 participants