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): [Stripe] Deserialization Error while parsing Dispute Webhook Body #3256

Merged
merged 3 commits into from
Jan 8, 2024

Conversation

Sakilmostak
Copy link
Contributor

Type of Change

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

Description

meta_data struct is not present in case of dispute resulting in error during deserialization.

Additional Changes

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

Motivation and Context

How did you test it?

Steps to test:

Through Postman

  • Update merchant account with webhook url to recieve webhooks
  • Update Payment connector(Stripe) with merchant_secret

In Stripe dashboard, update the webhook url to hyperswitch's webhook endpoint with formant

{{base_url}}/webhooks/{{merchant_id}}/stripe
Screenshot 2024-01-05 at 6 28 26 PM

Different Events:

  • Create a payment through Stripe:
    { "amount": 6540, "currency": "USD", "confirm": true, "capture_method": "automatic", "capture_on": "2022-09-10T10:11:12Z", "amount_to_capture": 6540, "customer_id": "StripeCustomer", "email": "guest@example.com", "name": "John Doe", "phone": "999999999", "phone_country_code": "+65", "description": "Its my first payment request", "authentication_type": "no_three_ds", "return_url": "https://duck.com", "setup_future_usage": "on_session", "payment_method": "card", "payment_method_type": "credit", "payment_method_data": { "card": { "card_number": "4242424242424242", "card_exp_month": "10", "card_exp_year": "25", "card_holder_name": "joseph Doe", "card_cvc": "123" } }, "billing": { "address": { "line1": "1467", "line2": "Harrison Street", "line3": "Harrison Street", "city": "San Fransico", "state": "California", "zip": "94122", "country": "US", "first_name": "joseph", "last_name": "Doe" }, "phone": { "number": "8056594427", "country_code": "+91" } }, "shipping": { "address": { "line1": "1467", "line2": "Harrison Street", "line3": "Harrison Street", "city": "San Fransico", "state": "California", "zip": "94122", "country": "US", "first_name": "joseph", "last_name": "Doe" }, "phone": { "number": "8056594427", "country_code": "+91" } }, "statement_descriptor_name": "joseph", "statement_descriptor_suffix": "JS", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "routing": { "type": "single", "data": "stripe" } }

Following are the webhook recieved through hyperswitch
Screenshot 2024-01-05 at 6 13 06 PM
Screenshot 2024-01-05 at 6 13 03 PM

  • Create a Refund Through Stripe:
    { "payment_id": "{{payment_id}}", "amount": 600, "reason": "Customer returned product", "refund_type": "instant", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" } }

Following are the webhooks recieved through hyperswitch:
Screenshot 2024-01-05 at 6 15 36 PM

  • Create a Dispute through Stripe:
    { "amount": 6540, "currency": "USD", "confirm": true, "capture_method": "automatic", "capture_on": "2022-09-10T10:11:12Z", "amount_to_capture": 6540, "customer_id": "StripeCustomer", "email": "guest@example.com", "name": "John Doe", "phone": "999999999", "phone_country_code": "+65", "description": "Its my first payment request", "authentication_type": "no_three_ds", "return_url": "https://duck.com", "setup_future_usage": "on_session", "payment_method": "card", "payment_method_type": "credit", "payment_method_data": { "card": { "card_number": "4000000000000259", "card_exp_month": "10", "card_exp_year": "25", "card_holder_name": "joseph Doe", "card_cvc": "123" } }, "billing": { "address": { "line1": "1467", "line2": "Harrison Street", "line3": "Harrison Street", "city": "San Fransico", "state": "California", "zip": "94122", "country": "US", "first_name": "joseph", "last_name": "Doe" }, "phone": { "number": "8056594427", "country_code": "+91" } }, "shipping": { "address": { "line1": "1467", "line2": "Harrison Street", "line3": "Harrison Street", "city": "San Fransico", "state": "California", "zip": "94122", "country": "US", "first_name": "joseph", "last_name": "Doe" }, "phone": { "number": "8056594427", "country_code": "+91" } }, "statement_descriptor_name": "joseph", "statement_descriptor_suffix": "JS", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" }, "routing": { "type": "single", "data": "stripe" } }

Payment through this card will create a dispute option against that payment in Stripe Dashboard
Raise a counter or accept the dispute in dashboard to receive the webhooks.

Screenshot 2024-01-05 at 6 13 01 PM Screenshot 2024-01-05 at 6 12 59 PM

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
  • I added a CHANGELOG entry if applicable

@Sakilmostak Sakilmostak added A-connector-integration Area: Connector integration C-bug Category: Bug labels Jan 5, 2024
@Sakilmostak Sakilmostak self-assigned this Jan 5, 2024
@Sakilmostak Sakilmostak requested a review from a team as a code owner January 5, 2024 13:10
}

#[derive(Debug, Deserialize)]
pub struct WebhookEventObjectDataWithMetaData {
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 having this new struct, let's make metadata->order_id as option field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done👍

@ArjunKarthik ArjunKarthik added the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Jan 5, 2024
@Sakilmostak Sakilmostak force-pushed the fix_stripe_webhook_events branch from 3c7accb to f1d8eec Compare January 5, 2024 13:55
@Sakilmostak Sakilmostak removed the S-waiting-on-author Status: This PR is incomplete or needs to address review comments label Jan 5, 2024
@@ -1861,7 +1861,11 @@ impl api::IncomingWebhook for Stripe {
match details.event_data.event_object.metadata {
// if order_id is present
Some(meta_data) => api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::PaymentAttemptId(meta_data.order_id),
api_models::payments::PaymentIdType::PaymentAttemptId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Since our condition is based on order_id and not metadata, match statement can be rewritten as

Suggested change
api_models::payments::PaymentIdType::PaymentAttemptId(
match details
.event_data
.event_object
.metadata
.and_then(|metadata| metadata.order_id)
{
// if order_id is present
Some(order_id) => api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::PaymentAttemptId(order_id),
),
// else used connector_transaction_id
None => api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::ConnectorTransactionId(
details.event_data.event_object.id,
),
),
}

@@ -1875,7 +1879,11 @@ impl api::IncomingWebhook for Stripe {
match details.event_data.event_object.metadata {
// if order_id is present
Some(meta_data) => api_models::webhooks::ObjectReferenceId::PaymentId(
api_models::payments::PaymentIdType::PaymentAttemptId(meta_data.order_id),
api_models::payments::PaymentIdType::PaymentAttemptId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, Instead of checking metadata, extract order_id and match order_id for some or None

@@ -1915,7 +1923,11 @@ impl api::IncomingWebhook for Stripe {
match meta_data.is_refund_id_as_reference {
// if the order_id is refund_id
Some(_) => api_models::webhooks::ObjectReferenceId::RefundId(
api_models::webhooks::RefundIdType::RefundId(meta_data.order_id),
api_models::webhooks::RefundIdType::RefundId(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, Instead of checking metadata, extract order_id and match order_id for some or None

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jan 8, 2024
Merged via the queue into main with commit 01b4ac3 Jan 8, 2024
9 of 11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the fix_stripe_webhook_events branch January 8, 2024 07:00
pixincreate added a commit that referenced this pull request Jan 8, 2024
* 'main' of github.com:juspay/hyperswitch:
  fix(connector): [Stripe] Deserialization Error while parsing Dispute Webhook Body (#3256)
  refactor(euclid_wasm): Update wasm config (#3222)
  fix(analytics): added response to the connector outgoing event (#3129)
  fix(analytics): fixed response code to 501 (#3119)
  fix(connector): [NMI] Populating `ErrorResponse` with required fields and Mapping `connector_response_reference_id` (#3214)
  feat(merchant_account): Add list multiple merchants in `MerchantAccountInterface` (#3220)
  feat: include version number in response headers and on application startup (#3045)
  chore: address Rust 1.75 clippy lints (#3231)
  feat: add deep health check (#3210)
  feat(analytics): adding outgoing webhooks kafka event (#3140)
  refactor: address panics due to indexing and slicing (#3233)
  fix(users): Fix wrong redirection url in magic link (#3217)
  fix(user): add integration_completed enum in metadata type (#3245)
  chore(version): v1.106.1
  fix(connector): [iatapay] change refund amount (#3244)
  chore(version): v1.106.0
  test(postman): update postman collection files
  fix(core): fix recurring mandates flow for cyber source (#3224)
  chore: fix channel handling for consumer workflow loop (#3223)
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-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants