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: address non-digit character cases in card number validation #4649

Merged
merged 9 commits into from
May 17, 2024

Conversation

Chethan-rao
Copy link
Contributor

@Chethan-rao Chethan-rao commented May 15, 2024

Type of Change

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

Description

This PR enforces following validations on the card number -

  • non-digit characters in card number
  • invalid card number length
  • invalid card number (luhn failure)

If any of the above validation fails, appropriate error is raised.
This PR also fixes the failing CI check.

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?

  1. Unit tests -

image

  1. Invalid card number length -
curl --location 'http://localhost:8080/payment_methods' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_ekfmmqSYoY0bvjOGGO0Pe5CQdP9oS0ycImpRG78tjNTrgp03HGxvDAhHCrmHrYoO' \
--data '{
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_issuer": "Visa",
  "card": {
    "card_number": "1234567",
    "card_exp_month": "10",
    "card_exp_year": "26",
    "card_holder_name": "Chethan"
  },
  "customer_id": "cus_Cbszk87dvhH7EuBp2ZoB",
  "metadata": {
    "city": "NY",
    "unit": "245"
  }
}'

image

  1. Non-digit character in card number
curl --location 'http://localhost:8080/payment_methods' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_ekfmmqSYoY0bvjOGGO0Pe5CQdP9oS0ycImpRG78tjNTrgp03HGxvDAhHCrmHrYoO' \
--data '{
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_issuer": "Visa",
  "card": {
    "card_number": "411111111111111🦀",
    "card_exp_month": "10",
    "card_exp_year": "26",
    "card_holder_name": "Chethan"
  },
  "customer_id": "cus_Cbszk87dvhH7EuBp2ZoB",
  "metadata": {
    "city": "NY",
    "unit": "245"
  }
}'

image

  1. Invalid card number (Failing luhn check):
curl --location 'http://localhost:8080/payment_methods' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_ekfmmqSYoY0bvjOGGO0Pe5CQdP9oS0ycImpRG78tjNTrgp03HGxvDAhHCrmHrYoO' \
--data '{
  "payment_method": "card",
  "payment_method_type": "credit",
  "payment_method_issuer": "Visa",
  "card": {
    "card_number": "411111111111112",
    "card_exp_month": "10",
    "card_exp_year": "26",
    "card_holder_name": "Chethan"
  },
  "customer_id": "cus_Cbszk87dvhH7EuBp2ZoB",
  "metadata": {
    "city": "NY",
    "unit": "245"
  }
}'

image

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

@Chethan-rao Chethan-rao added the C-bug Category: Bug label May 15, 2024
@Chethan-rao Chethan-rao added this to the May 2024 Release milestone May 15, 2024
@Chethan-rao Chethan-rao self-assigned this May 15, 2024
@Chethan-rao Chethan-rao requested a review from a team as a code owner May 15, 2024 09:49
@Chethan-rao Chethan-rao linked an issue May 15, 2024 that may be closed by this pull request
SanchithHegde
SanchithHegde previously approved these changes May 15, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes May 15, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 16, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes May 16, 2024
SanchithHegde
SanchithHegde previously approved these changes May 16, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 17, 2024
Merged via the queue into main with commit 8c0d72e May 17, 2024
10 checks passed
@likhinbopanna likhinbopanna deleted the add-card-number-val branch May 17, 2024 07:32
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.

[FIX] address non-digit character cases in card number validation
4 participants