Issue:
[FEATURE] Validate card numbers when accepting payment method information

### Feature Description

As of now, we just pass the card information to the payment processor without performing any form of validation on the provided card number. It'd be great if the card number could have been validated on our end whenever a payment is being created or payment method is being created, instead of invalid card numbers being caught by the payment processor.

It'd be preferable if the card number validation logic is included in a new crate called `cards` which would contain this validation of card numbers and card brand identification logic (taken up on #379). This must check that the card number provided is of correct length, and also handle whitespaces being included in the card number input. Please also include unit tests in your PR.

_For external contributors, clarify any questions you may have, and let us know that you're interested in picking this up. We'll assign this issue to you to reduce duplication of effort on the same task._

### Possible Implementation

For validating card numbers, you can use the [Luhn Algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm). I'm thinking of an API like so (refer to [the newtype pattern](https://rust-unofficial.github.io/patterns/patterns/behavioural/newtype.html)):

```rust
use masking::StrongSecret;

struct CardNumber(StrongSecret<String>);

let card_number = CardNumber::from_str("..."); // You can use the `FromStr` trait for this purpose
```

This would ensure that a `CardNumber` once constructed is always valid and no further validation is necessary. You can also implement `Serialize` and `Deserialize` traits on `CardNumber`.

### Have you spent some time to check if this feature request has been raised before?

- [X] I checked and didn't find similar issue

### Have you read the Contributing Guidelines?

- [X] I have read the [Contributing Guidelines](https://github.com/juspay/hyperswitch/blob/main/docs/CONTRIBUTING.md)

### Are you willing to submit a PR?

None

Resolution:
<think>
PR Context:
- Title: feat(cards): add credit card number validation
- Merged: 2023-05-09T15:06:39Z
- Files changed: 30 files
- Commits: 6 commits

Implementation approach:
Fixes #606

## Type of Change
<!-- Put an `x` in the boxes that apply -->

- [ ] Bugfix
- [x] New feature
- [ ] Enhancement
- [ ] Refactoring
- [ ] Dependency updates

## Description
<!-- Describe your changes in detail -->
The PR adds a new crate called `cards`. Which currently just has a single module named validate which exposes the `CardNumber` struct as well as a `CCValError`.

The validation of a correct CC number is done via the Luhn Algorithm implemented in the `luhn` crat
</think>

To implement this, you'll need to modify:


**Detailed Implementation:**


**Commit 1:** feat(cards): add credit card number validation (#889)
Co-authored-by: Sanchith Hegde <sanchith.hegde
Files to modify:


**connector-template/test.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**connector-template/transformers.rs**
  Modify existing code

**crates/api_models/src/payment_methods.rs**
  Modify existing code

**crates/api_models/src/payments.rs**
  Modify existing code

**crates/cards/src/lib.rs**
  Add:
    - mod: pub::validate

**crates/cards/src/validate.rs**
  Add:
    - function: private::from
    - function: private::from_str
    - function: private::try_from
    - function: private::deref
    - function: private::deserialize
    - function: private::fmt
    - function: private::valid_card_number
    - function: private::invalid_card_number
    - function: private::card_number_no_whitespace
    - function: private::test_valid_card_number_masking
    - function: private::test_invalid_card_number_masking
    - function: private::test_valid_card_number_strong_secret_masking
    - function: private::test_valid_card_number_deserialization
    - function: private::test_invalid_card_number_deserialization
    - struct: pub::CCValError
    - struct: pub::CardNumber
    - struct: pub::CardNumberStrategy
    - impl: impl From<core::convert::Infallible> for CCValError
    - impl: impl FromStr for CardNumber
    - impl: impl TryFrom<String> for CardNumber
    - impl: impl Deref for CardNumber
    - impl: impl Deserialize<'de> for CardNumber
    - impl: impl Strategy<T> for CardNumberStrategy
    - mod: private::tests

**crates/common_utils/src/pii.rs**
  Remove:
    - function: private::fmt
    - function: private::test_valid_card_number_masking
    - function: private::test_invalid_card_number_masking
    - struct: pub::CardNumber
    - impl: impl Strategy<T> for CardNumber

**crates/router/src/compatibility/stripe/payment_intents/types.rs**
  Modify existing code

**crates/router/src/compatibility/stripe/setup_intents/types.rs**
  Modify existing code

**crates/router/src/connector/aci/transformers.rs**
  Modify existing code

**crates/router/src/connector/adyen/transformers.rs**
  Modify existing code

**crates/router/src/connector/airwallex/transformers.rs**
  Modify existing code

**crates/router/src/connector/authorizedotnet/transformers.rs**
  Modify existing code

**crates/router/src/connector/bambora/transformers.rs**
  Modify existing code

**crates/router/src/connector/bluesnap/transformers.rs**
  Modify existing code

**crates/router/src/connector/braintree/transformers.rs**
  Modify existing code

**crates/router/src/connector/checkout/transformers.rs**
  Modify existing code

**crates/router/src/connector/cybersource/transformers.rs**
  Modify existing code

**crates/router/src/connector/dlocal/transformers.rs**
  Modify existing code

**crates/router/src/connector/dummyconnector/transformers.rs**
  Modify existing code

**crates/router/src/connector/fiserv/transformers.rs**
  Modify existing code

**crates/router/src/connector/forte/transformers.rs**
  Modify existing code

**crates/router/src/connector/globalpay/requests.rs**
  Modify existing code

**crates/router/src/connector/multisafepay/transformers.rs**
  Modify existing code

**crates/router/src/connector/nexinets/transformers.rs**
  Modify existing code

**crates/router/src/connector/nuvei/transformers.rs**
  Modify existing code

**crates/router/src/connector/payeezy/transformers.rs**
  Modify existing code

**crates/router/src/connector/paypal/transformers.rs**
  Modify existing code

**crates/router/src/connector/payu/transformers.rs**
  Modify existing code

**crates/router/src/connector/rapyd/transformers.rs**
  Modify existing code

**crates/router/src/connector/shift4/transformers.rs**
  Modify existing code

**crates/router/src/connector/stripe/transformers.rs**
  Modify existing code

**crates/router/src/connector/trustpay/transformers.rs**
  Modify existing code

**crates/router/src/connector/utils.rs**
  Modify existing code

**crates/router/src/connector/worldline/transformers.rs**
  Modify existing code

**crates/router/src/connector/worldpay/requests.rs**
  Modify existing code

**crates/router/src/connector/zen/transformers.rs**
  Modify existing code

**crates/router/src/core/payment_methods/cards.rs**
  Modify existing code

**crates/router/src/core/payment_methods/transformers.rs**
  Modify existing code

**crates/router/src/core/payment_methods/vault.rs**
  Modify existing code

**crates/router/src/lib.rs**
  Modify existing code

**crates/router/src/routes/dummy_connector/types.rs**
  Modify existing code

**crates/router/src/routes/dummy_connector/utils.rs**
  Modify existing code

**crates/router/src/services/api.rs**
  Modify existing code

**crates/router/src/types/api/payments.rs**
  Modify existing code

**crates/router/tests/connectors/aci.rs**
  Modify existing code

**crates/router/tests/connectors/adyen.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/airwallex.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/authorizedotnet.rs**
  Modify existing code

**crates/router/tests/connectors/bambora.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/bluesnap.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/checkout.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/coinbase.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/cybersource.rs**
  Remove:
    - function: private::should_fail_payment_for_no_card_number

**crates/router/tests/connectors/dlocal.rs**
  Modify existing code

**crates/router/tests/connectors/dummyconnector.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/fiserv.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/forte.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/globalpay.rs**
  Modify existing code

**crates/router/tests/connectors/main.rs**
  Modify existing code

**crates/router/tests/connectors/multisafepay.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/nexinets.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/nuvei.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/opennode.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/payeezy.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/paypal.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/rapyd.rs**
  Modify existing code

**crates/router/tests/connectors/shift4.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/stripe.rs**
  Remove:
    - function: private::should_fail_payment_for_no_card_number

**crates/router/tests/connectors/trustpay.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/connectors/utils.rs**
  Modify existing code

**crates/router/tests/connectors/worldline.rs**
  Modify existing code

**crates/router/tests/connectors/zen.rs**
  Remove:
    - function: private::should_fail_payment_for_empty_card_number

**crates/router/tests/payments.rs**
  Modify existing code

**crates/router/tests/payments2.rs**
  Modify existing code