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: throw bad request while pushing duplicate data to redis #3016

Merged
merged 3 commits into from
Dec 6, 2023

Conversation

dracarys18
Copy link
Member

Type of Change

  • Bugfix

Description

Throw bad request when duplicate data get's inserted in redis.

Motivation and Context

Currently we are throwing 500 when you insert duplicate data in redis. This is quite misleading as it's a genuine error. So throw 400 when you try to push duplicate data.

How did you test it?

  • Create 2 payments with same payment_id and the 2nd response will be 400 bad request.
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_zMqTcJDcr8tGEdWoOMCaVZJX1J959jwtfsEfUHtiUawbHokw6cK6fURjLOPOEtfG' \
--header 'Cookie: token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDYwZTg1NjUtM2E5Yy00ZDA4LTlmNDktMGQ1NzIzNTZkZDdiIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzAxMjUyODc2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTcwMTQyNjA0NSwib3JnX2lkIjoib3JnX2pUeGFQRVJvZVp3czJha3dmTXBiIn0.ZnZodoBk8ZLSYwf-5fH4y376vvWjvwHABOTmAJKZZes' \
--data-raw '{
    "payment_id": "pay_4mHjgFuZJf6ujTf7tjKf",
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "customer_id": "HScustomer1234",
    "email": "[email protected]",
    "amount_to_capture": 6540,
    "description": "Its my first payment request",
    "capture_on": "2022-09-10T10:11:12Z",
    "return_url": "https://google.com",
    "name": "Preetam",
    "phone": "999999999",
    "setup_future_usage": "off_session",
    "phone_country_code": "+65",
    "authentication_type": "three_ds",
    "payment_method": "card",
    "payment_method_type": "debit",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "applepay"
        }
    },
    "browser_info": {
        "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36",
        "accept_header": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "128.0.0.1"
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "preetam",
            "last_name": "revankar"
        },
        "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"
        }
    },
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 6540,
            "account_name": "transaction_processing"
        }
    ],
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
Screenshot 2023-11-29 at 11 58 06 PM

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code

@dracarys18 dracarys18 added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Nov 29, 2023
@dracarys18 dracarys18 added this to the November 2023 Release milestone Nov 29, 2023
@dracarys18 dracarys18 self-assigned this Nov 29, 2023
@dracarys18 dracarys18 requested review from a team as code owners November 29, 2023 18:28
@likhinbopanna likhinbopanna added this pull request to the merge queue Dec 6, 2023
Merged via the queue into main with commit a2405e5 Dec 6, 2023
10 of 12 checks passed
@likhinbopanna likhinbopanna deleted the fix_500_on_duplicate branch December 6, 2023 06:09
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants