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(router): added validation to check total orderDetails amount equal to amount in request #2965

Merged
merged 6 commits into from
Nov 27, 2023

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Nov 23, 2023

added validation to check total orderDetails amount equal to amount in request

Type of Change

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

Description

Added validation to check total orderDetails amount equal to amount in request.

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?

Test cases

  1. Where amount and total amount in orderDetails doesn't match.
Screenshot 2023-11-23 at 4 37 06 PM
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_6B2gnO7ZTbAitEgXrQDRsfJVvu6tp98HnNaSGvY8rvIoXwpzn2RALy4TgUiXMqhc' \
--data '{
    "amount": 40,
    "currency": "USD",
    "confirm": false,
    "customer_id": "sahkal",
    "return_url": "https://google.com",
    "description": "For selling Tea",
    "order_details": [
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": null
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        }
    ]
}'

2 . Total amount is not provided but order details object is provided
Screenshot 2023-11-23 at 4 38 20 PM

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_6B2gnO7ZTbAitEgXrQDRsfJVvu6tp98HnNaSGvY8rvIoXwpzn2RALy4TgUiXMqhc' \
--data '{
    "currency": "USD",
    "confirm": false,
    "customer_id": "sahkal",
    "return_url": "https://google.com",
    "description": "For selling Tea",
    "order_details": [
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": null
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        }
    ]
 }'
  1. Where amount and total amount in orderDetails match
Screenshot 2023-11-23 at 4 41 21 PM
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_6B2gnO7ZTbAitEgXrQDRsfJVvu6tp98HnNaSGvY8rvIoXwpzn2RALy4TgUiXMqhc' \
--data '{
    "amount": 20,
    "currency": "USD",
    "confirm": false,
    "customer_id": "sahkal",
    "return_url": "https://google.com",
    "description": "For selling Tea",
    "order_details": [
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": null
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 10,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        }
    ]
}'
  1. where only Amount is provided without orderDetails
Screenshot 2023-11-23 at 4 42 20 PM
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_6B2gnO7ZTbAitEgXrQDRsfJVvu6tp98HnNaSGvY8rvIoXwpzn2RALy4TgUiXMqhc' \
--data '{
    "amount": 20,
    "currency": "USD",
    "confirm": false,
    "customer_id": "sahkal",
    "return_url": "https://google.com",
    "description": "For selling Tea"
}'

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

@sahkal sahkal requested a review from a team as a code owner November 23, 2023 11:08
@sahkal sahkal self-assigned this Nov 23, 2023
@sahkal sahkal added C-bug Category: Bug S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Nov 23, 2023
@sahkal sahkal added this to the November 2023 Release milestone Nov 23, 2023
Copy link
Contributor

@sai-harsha-vardhan sai-harsha-vardhan left a comment

Choose a reason for hiding this comment

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

Can you please add this validation in payments update flow too?

Comment on lines 830 to 832
if let Some(order_details) = &request.order_details {
helpers::validate_order_details_amount(order_details.to_owned(), request.amount)?;
}
Copy link
Member

Choose a reason for hiding this comment

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

the amount is mandated in confirm flow, this should not be the case

@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 27, 2023
Merged via the queue into main with commit 37532d4 Nov 27, 2023
10 of 12 checks passed
@likhinbopanna likhinbopanna deleted the validate-orderDetails-amount-to-totalAmount branch November 27, 2023 05:32
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants