-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(core): implement NameType
for name validation
#6734
base: main
Are you sure you want to change the base?
Conversation
@@ -710,6 +712,17 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa | |||
payment_method_data_billing.get_billing_address() | |||
}); | |||
|
|||
// validate billing name for card holder name | |||
helpers::validate_billing_name( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a domain type which will have these validations, use the domain type wherever validations are required
NameType
for name validation
NameType
for name validationNameType
for name validation
crates/cards/src/validate.rs
Outdated
// pub struct NameTypeValidationErr(&'static str); | ||
|
||
#[derive(Clone, Default, Debug, Eq, PartialEq, Serialize)] | ||
pub struct NameType(Secret<LengthString<256, 1>>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to common_utils or common_types, since this is not specific to cards as you have used this in all the other payment methods as well
crates/api_models/src/payments.rs
Outdated
@@ -1785,13 +1785,13 @@ impl GetAddressFromPaymentMethodData for Card { | |||
let first_name = card_holder_name_iter | |||
.next() | |||
.map(ToOwned::to_owned) | |||
.map(Secret::new); | |||
.and_then(|name| NameType::try_from(name).ok()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not use .ok(), log the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace all instances of .ok() with logging the error, and if possible qualify the imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wherever possible try to use the nametype, and if the domain is expanding too much convert the type, and raise errors when the conversion might fail
Type of Change
Description
for card holder name in cards, validation is added before creation of request to flag invalid data in case it is present.
Reference is taken from Visa Documetation
Additional Changes
Motivation and Context
How did you test it?
Tested through Postman:
Case 1: Create a Payment with valid name:
Case 2: Create a Payment with invalid name:
Response should contain 400 error with below response:
Checklist
cargo +nightly fmt --all
cargo clippy