> ## Documentation Index
> Fetch the complete documentation index at: https://developers.orchestrasolutions.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Luhn Validation

> Validate a card number using the Luhn algorithm and optionally retrieve card metadata.

The Luhn Validation endpoint checks whether a card number is valid according to the [Luhn algorithm](https://en.wikipedia.org/wiki/Luhn_algorithm) - the standard checksum formula used by all major card schemes. Optionally, you can request the card's metadata in the same call.

**Endpoint:** `GET /Tools/luhn`

## When to Use This

Use Luhn Validation as an early check before submitting a payment. A card number that fails the Luhn check is guaranteed to be invalid. Catching it here avoids an unnecessary API call to the PSP, saves processing time, and gives the customer immediate feedback to correct their input.

By setting `metaData=true`, you can combine validation and metadata lookup in a single call. This is useful when you need both the validity check and card details (e.g., for form validation plus BIN-based routing in one step).

## How It Works

Pass the full card number as the `number` query parameter. Set `metaData` to `true` if you also want the card's BIN metadata in the response.

| Parameter  | Type            | Required | Description                                              |
| ---------- | --------------- | -------- | -------------------------------------------------------- |
| `number`   | string (query)  | Yes      | The full card number to validate                         |
| `metaData` | boolean (query) | No       | Include card metadata in the response (default: `false`) |

## Example: Validate Before Payment Submission

Check the card number on your server before sending it to the PSP. If validation fails, return an error to the customer immediately.

<CodeGroup>
  ```javascript Node.js theme={null}
  async function validateCard(cardNumber, apiKey) {
    const response = await fetch(
      `https://api.orchestrasolutions.com/Tools/luhn?number=${cardNumber}&metaData=true`,
      { headers: { 'X-Api-Key': apiKey } }
    );
    const result = await response.json();

    if (!result.luhnValid) {
      return { valid: false, error: result.error || 'Invalid card number' };
    }

    return {
      valid: true,
      brand: result.iinData?.cardBrand,
      type: result.iinData?.cardType,
      issuerCountry: result.iinData?.countryCode
    };
  }

  const check = await validateCard('4111111111111111', 'YOUR_API_KEY');
  if (!check.valid) {
    console.error(check.error);
  } else {
    console.log(`Valid ${check.brand} ${check.type} card from ${check.issuerCountry}`);
  }
  ```

  ```python Python theme={null}
  import requests

  def validate_card(card_number, api_key):
      """Validate card number and return metadata if valid."""
      response = requests.get(
          'https://api.orchestrasolutions.com/Tools/luhn',
          params={'number': card_number, 'metaData': 'true'},
          headers={'X-Api-Key': api_key}
      )
      response.raise_for_status()
      result = response.json()

      if not result['luhnValid']:
          raise ValueError(result.get('error', 'Invalid card number'))

      iin = result.get('iinData', {})
      return {
          'brand': iin.get('cardBrand'),
          'type': iin.get('cardType'),
          'country': iin.get('countryCode'),
      }

  try:
      info = validate_card('4111111111111111', 'YOUR_API_KEY')
      print(f"Valid {info['brand']} {info['type']} card from {info['country']}")
  except ValueError as e:
      print(f"Invalid card: {e}")
  ```

  ```bash cURL theme={null}
  # Validate with metadata
  curl "https://api.orchestrasolutions.com/Tools/luhn?number=4111111111111111&metaData=true" \
    -H "X-Api-Key: YOUR_API_KEY"

  # Validate only (no metadata)
  curl "https://api.orchestrasolutions.com/Tools/luhn?number=4111111111111111" \
    -H "X-Api-Key: YOUR_API_KEY"
  ```
</CodeGroup>

## Related

<CardGroup cols={2}>
  <Card title="Metadata Lookup" icon="magnifying-glass" href="/guides/rest-api/utilities/card-tools/metadata-lookup">
    Already know the card is valid? Look up metadata from just the BIN.
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/tools/luhn-validation">
    Full endpoint specification and response schema
  </Card>
</CardGroup>
