hyperswitch
hyperswitch copied to clipboard
fix: address non-digit character cases in card number validation
Type of Change
- [x] 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?
- Unit tests -
- 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"
}
}'
- 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"
}
}'
- 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"
}
}'
Checklist
- [x] I formatted the code
cargo +nightly fmt --all
- [x] I addressed lints thrown by
cargo clippy
- [x] I reviewed the submitted code
- [x] I added unit tests for my changes where possible