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.64k stars 1.36k forks source link

fix(connector): [Volt] handle 5xx error for Volt payments webhooks #6576

Closed swangi-kumari closed 6 days ago

swangi-kumari commented 1 week ago

Type of Change

Description

handle 5xx error for Volt payments webhooks

In the Volt connector for payment webhooks in production, a field is occasionally changing. The payment field sometimes comes as id instead, with the same expected value as payment. Since it’s coming as id rather than payment, the webhook body deserialization is failing, causing a 5xx error. To prevent this, I have added an alias for payment as id.

Additional Changes

Motivation and Context

How did you test it?

Configure webhooks in volt dashboard.

  1. Create a open_banking_uk Payment via Volt

    
    curl --location 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: {}' \
    --data-raw '{
    "amount": 8000,
    "currency": "EUR",
    "confirm": true,
      "capture_method": "automatic",
      "capture_on": "2022-09-10T10:11:12Z",
      "amount_to_capture": 8000,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
      "authentication_type": "no_three_ds",
    "return_url": "https://www.google.com/",
    "payment_method": "bank_redirect",
    "payment_method_type": "open_banking_uk",
    "payment_method_data": {
        "bank_redirect": {
            "open_banking_uk": {
            }
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "DE",
            "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": "DE",
            "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"
    },
    
    "profile_id": "pro_dHxsLE73VVQwBZfzx9Il"
    }

'

Complete payment using redirection link.

2. Create a Refund

curl --location 'http://localhost:8080/refunds' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: {}' \ --data '{ "payment_id": "pay_KvWJlcOapPbt7YzEY08t", "amount": 577, "reason": "Customer returned product", "refund_type": "instant", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" } }'


Check for webhooks in Volt dashboard under transactions.  
Then for Notifications check for all webhooks, In All the 4 notifications `PENDING ` , `COMPLETED`, `RECEIVED` and `REFUND_CONFIRMED ` should have status `Delivered` and http code `200 OK`. 

<img width="1164" alt="Screenshot 2024-11-14 at 7 17 34 PM" src="https://github.com/user-attachments/assets/b1ab4fa5-efa3-4959-bb70-1e44633307dd">

## Checklist
<!-- Put an `x` in the boxes that apply -->

- [x] I formatted the code `cargo +nightly fmt --all`
- [x] I addressed lints thrown by `cargo clippy`
- [x] I reviewed the submitted code
- [ ] I added unit tests for my changes where possible
semanticdiff-com[bot] commented 1 week ago

Review changes with  SemanticDiff

Changed Files
| File | Status | | :--- | :--- | | [](https://app.semanticdiff.com/gh/juspay/hyperswitch/pull/6576/changes#crates/hyperswitch_connectors/src/connectors/volt/transformers.rs)  [crates/hyperswitch\_connectors/src/connectors/volt/transformers\.rs](https://app.semanticdiff.com/gh/juspay/hyperswitch/pull/6576/changes#crates/hyperswitch_connectors/src/connectors/volt/transformers.rs) | [](https://app.semanticdiff.com/gh/juspay/hyperswitch/pull/6576/changes#crates/hyperswitch_connectors/src/connectors/volt/transformers.rs)  0% smaller |