Skip to content

Conversation

jagan-jaya
Copy link
Contributor

@jagan-jaya jagan-jaya commented Apr 3, 2025

Type of Change

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

Description

A recent change in this PR removed the usage of DomainStorageError in all the places and started using StorageError everywhere.

Previously, DataStorage and RedisError were manually converted into StorageError based on few conditions which was missing in the mentioned PR resulting in resource_not_found being thrown as 5xx instead of 4xx.

StorageError::DatabaseError(i) => match i.current_context() {
                DatabaseError::DatabaseConnectionError => DataStorageError::DatabaseConnectionError,
                // TODO: Update this error type to encompass & propagate the missing type (instead of generic `db value not found`)
                DatabaseError::NotFound => {
                    DataStorageError::ValueNotFound(String::from("db value not found"))
                }
                // TODO: Update this error type to encompass & propagate the duplicate type (instead of generic `db value not found`)
                DatabaseError::UniqueViolation => DataStorageError::DuplicateValue {
                    entity: "db entity",
                    key: None,
                },
                err => DataStorageError::DatabaseError(error_stack::report!(*err)),
            }

This PR handles the manual conversion logic for DataStorageError and RedisError

Additional Changes

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

Motivation and Context

Resource_not_found being thrown as 5xx instead of 4xx

Create a payment with confirm false and try to confirm the payment with invalid publishable key

Request

Create a payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_KuDhgIFqeK0Qn8YjYAouk6ztEqJnElMO79hYsBooODvx09okKXcmeEj8bUU6mwXq' \
--data-raw '{
    "amount": 1000,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "customer_id": "ad",
    "profile_id": "pro_3LcIbwh0xcM5yfjgk3ie",
    "email": "[email protected]",
    "description": "Hello this is description",
    "shipping": {
        "address": {
            "state": "zsaasdas",
            "city": "Banglore",
            "country": "US",
            "line1": "sdsdfsdf",
            "line2": "hsgdbhd",
            "line3": "alsksoe",
            "zip": "571201",
            "first_name": "joseph",
            "last_name": "doe"
        },
        "phone": {
            "number": "123456789",
            "country_code": "+1"
        }
    },
    "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": "123456789",
            "country_code": "+1"
        }
    },
    "setup_future_usage": "off_session",
    "order_details": null
}'

confirm the payment with invalid publishable key

curl --location 'http://localhost:8080/payments/pay_mBeU1Aorcd7KB81NXAgV/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_42efcc8f61704637b51150f3413a1f8ca' \
--data '{
    "payment_method": "card",
    "payment_method_type": "credit",
    "client_secret": "pay_mBeU1Aorcd7KB81NXAgV_secret_BC5WU8N6YMeIKOcgm2qH",
    "profile_id": "pro_3LcIbwh0xcM5yfjgk3ie",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "CLBRW dffdg",
            "card_cvc": "737"
        }
    },
    "payment_type": "new_mandate",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "125.0.0.1",
            "user_agent": "amet irure esse"
        }
    }
}'

Confirm Payment Response

500 Internal Server Error
{
    "error": {
        "type": "api",
        "message": "Something went wrong",
        "code": "HE_00"
    }
}

How did you test it?

Create a payment with confirm false and try to confirm the payment with invalid publishable key

Request

Create a payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_KuDhgIFqeK0Qn8YjYAouk6ztEqJnElMO79hYsBooODvx09okKXcmeEj8bUU6mwXq' \
--data-raw '{
    "amount": 1000,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "customer_id": "ad",
    "profile_id": "pro_3LcIbwh0xcM5yfjgk3ie",
    "email": "[email protected]",
    "description": "Hello this is description",
    "shipping": {
        "address": {
            "state": "zsaasdas",
            "city": "Banglore",
            "country": "US",
            "line1": "sdsdfsdf",
            "line2": "hsgdbhd",
            "line3": "alsksoe",
            "zip": "571201",
            "first_name": "joseph",
            "last_name": "doe"
        },
        "phone": {
            "number": "123456789",
            "country_code": "+1"
        }
    },
    "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": "123456789",
            "country_code": "+1"
        }
    },
    "setup_future_usage": "off_session",
    "order_details": null
}'

confirm the payment with invalid publishable key

curl --location 'http://localhost:8080/payments/pay_sdeU1Aorcd7KB81NXASD/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_42efcc8f61704637b51150f3413a1f8ca' \
--data '{
    "payment_method": "card",
    "payment_method_type": "credit",
    "client_secret": "pay_sdeU1Aorcd7KB81NXASD_secret_BC5WU8N6YMeIKOcgm2qH",
    "profile_id": "pro_3LcIbwh0xcM5yfjgk3ie",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "CLBRW dffdg",
            "card_cvc": "737"
        }
    },
    "payment_type": "new_mandate",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "125.0.0.1",
            "user_agent": "amet irure esse"
        }
    }
}'

Confirm Payment Response

401 Unathorized
{
    "error": {
        "type": "invalid_request",
        "message": "API key not provided or invalid API key used",
        "code": "IR_01"
    }
}
Retrieve invalid payment id

Request

curl --location 'http://localhost:8080/payments/pay_FgG1La2kxeukSzIHUl8ns' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom-dbd' \
--header 'api-key: dev_r6d1taIlStKeCplYDnDuPFrDT3Be1ZDq6pf0fTOOXioRoIi2pSOF5Jc8kzJJqNdz'

Response

404 Not found
{
    "error": {
        "type": "invalid_request",
        "message": "Payment does not exist in our records",
        "code": "HE_02"
    }
}
Retrieve invalid refund id

Request

curl --location 'http://localhost:8080/refunds/ref_kL0UzbPptCK3qZLXH6KO' \
--header 'Accept: application/json' \
--header 'api-key: dev_r6d1taIlStKeCplYDnDuPFrDT3Be1ZDq6pf0fTOOXioRoIi2pSOF5Jc8kzJJqNdz'

Response

404 Not found
{
    "error": {
        "type": "invalid_request",
        "message": "Refund does not exist in our records.",
        "code": "HE_02"
    }
}
Retrieve invalid merchant id

Request

curl --location 'http://localhost:8080/accounts/merchant_1743660591s' \
--header 'Accept: application/json' \
--header 'api-key: test_admin'

Response

404 Not found
{
    "error": {
        "type": "invalid_request",
        "message": "Merchant account does not exist in our records",
        "code": "HE_02"
    }
}
Retrieve customers using invalid API key

Request

curl --location 'http://localhost:8080/customers/list' \
--header 'Accept: application/json' \
--header 'api-key: dev_r6d1taIlStKeCplYDnDuPFrDT3Be1ZDq6pf0fTOOXioRoIi2pSOF5Jc8kzJJqNdz'

Response

401 Unauthorized
{
    "error": {
        "type": "invalid_request",
        "message": "API key not provided or invalid API key used",
        "code": "IR_01"
    }
}
Retrieve session tokens using invalid Publishable key

Request

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'accept: */*' \
--header 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
--header 'api-key: pk_dev_b72a47690f4f4a95a8a447b8221b5370s' \
--header 'x-browser-name: Chrome' \
--header 'x-browser-version: 127.0.0' \
--header 'x-client-platform: web' \
--header 'x-client-version: 0.91.7' \
--header 'x-merchant-domain: www-merchant.com' \
--header 'x-payment-confirm-source: sdk' \
--data '{
    "payment_id": "pay_pZNPfQY46nMLV5X225oW",
    "client_secret": "pay_pZNPfQY46nMLV5X225oW_secret_wrQsBzqleBKnhoOu3bLR",
    "wallets": [],
    "delayed_session_token": false
}'

Response

401 Unauthorized
{
    "error": {
        "type": "invalid_request",
        "message": "API key not provided or invalid API key used",
        "code": "IR_01"
    }
}
Retrieve merchant account payment methods using invalid Publishable key

Request

curl --location 'http://localhost:8080/account/payment_methods?client_secret=pay_pZNPfQY46nMLV5X225oW_secret_wrQsBzqleBKnhoOu3bLR' \
--header 'accept: */*' \
--header 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
--header 'api-key: pk_dev_b72a47690f4f4a95a8a447b8221b5370s' \
--header 'content-type: application/json' \
--header 'priority: u=1, i' \
--header 'sec-ch-ua: "Not)A;Brand";v="99", "Google Chrome";v="127", "Chromium";v="127"' \
--header 'sec-ch-ua-mobile: ?0' \
--header 'sec-ch-ua-platform: "macOS"' \
--header 'sec-fetch-dest: empty' \
--header 'sec-fetch-mode: cors' \
--header 'sec-fetch-site: same-origin' \
--header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36' \
--header 'x-browser-name: Chrome' \
--header 'x-browser-version: 127.0.0' \
--header 'x-client-platform: web' \
--header 'x-client-version: 0.91.7' \
--header 'x-payment-confirm-source: sdk'

Response

401 Unauthorized
{
    "error": {
        "type": "invalid_request",
        "message": "API key not provided or invalid API key used",
        "code": "IR_01"
    }
}

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

Copy link

semanticdiff-com bot commented Apr 3, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/storage_impl/src/errors.rs  21% smaller

@jagan-jaya jagan-jaya marked this pull request as ready for review April 3, 2025 07:52
@jagan-jaya jagan-jaya requested a review from a team as a code owner April 3, 2025 07:52
@jagan-jaya jagan-jaya self-assigned this Apr 3, 2025
@Gnanasundari24 Gnanasundari24 enabled auto-merge April 3, 2025 08:00
@SanchithHegde
Copy link
Member

Disabling auto-merge, since the PR is yet to be reviewed.

@SanchithHegde SanchithHegde disabled auto-merge April 3, 2025 08:18
ShankarSinghC
ShankarSinghC previously approved these changes Apr 3, 2025
SanchithHegde
SanchithHegde previously approved these changes Apr 3, 2025
@jagan-jaya jagan-jaya dismissed stale reviews from SanchithHegde and ShankarSinghC via 9562ae1 April 3, 2025 09:59
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Apr 3, 2025
Merged via the queue into main with commit b25f071 Apr 3, 2025
15 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the fix-db-not-found-error branch April 3, 2025 12:18
pixincreate added a commit that referenced this pull request Apr 4, 2025
…acilitapay-pix-pmt

* 'main' of github.com:juspay/hyperswitch: (33 commits)
  fix(connector): [Nexixpay] handle error code and message in failure response (#7713)
  fix(connector): [Coingate] Fix Wasm Changes  (#7716)
  fix(config): add billing payment sync configs in different environments (#7708)
  chore(dashboard): update dashboard toml (#7703)
  chore(postman): update auth for payment connectors in postman collection (#7702)
  feat(connector): [BANKOFAMERICA] Enable SamsungPay In Dashboard (#7677)
  feat(session): Added dpa_client_id, provider to click to pay session response (#7683)
  feat(core): add network error related columns in payment attempt [v2] (#7706)
  chore(version): 2025.04.04.0
  refactor(accounts): move accounts related tables to accounts schema (#7626)
  revert: implement `NameType` for name validation (#6734) (#7717)
  fix(errors): Entry not found error as 4xx instead of 5xx (#7712)
  refactor(analytics): default config for forex_enabled (#7695)
  refactor(core): made provider field in ctp_service_details backward compatible (#7705)
  refactor(openapi): modify profile-delete auth to AdminAPIKey in API doc (#7697)
  fix: web-docker pull from docker hub (#7700)
  ci(cypress): fix iatapay upi payments (#7698)
  docs: Updated next steps after deployment setup on Readme (#7686)
  chore(version): 2025.04.03.0
  fix(connector): [JPMORGAN, PAYU, DIGITALVIRGO, BITPAY, HELCIM, PAYBOX] Replaced lazystatic macros with LazyLock (#7524)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants