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

# Card details

The native SDKs provide a convenient way to retrieve details about a particular card based on its BIN (Bank Identification Number), checkout country, currency, and other parameters. This allows you to identify the card brand, card type, and other relevant information before processing a payment.

## Use cases

Get card details to:

* Identify the card brand (Visa, Mastercard, etc.) as the user types
* Determine the card type (debit, credit, prepaid)
* Display the appropriate card logo in your UI
* Validate card compatibility with your payment processors
* Provide better user experience with card-specific information

### Implementation

Create a request with card details (BIN, country, currency, amount) to retrieve information about the card.

<CodeGroup>
  ```swift Swift (iOS) theme={"system"}
  let gr4vy = try Gr4vy(
      gr4vyId: "example",
      token: "your_jwt_token",
      merchantId: "merchant_123", // Set the default merchant ID
      server: .sandbox,
      debugMode: true
  )

  // Create card details object
  let cardDetails = Gr4vyCardDetails(
      currency: "USD",
      amount: "1299",
      bin: "411111",
      country: "US",
      intent: "capture"
  )

  // Create request
  let request = Gr4vyCardDetailsRequest(
      cardDetails: cardDetails,
      timeout: 30.0
  )

  // Async/await
  do {
      let cardDetailsResponse = try await gr4vy.cardDetails.get(request: request)
      print("Card brand: \(cardDetailsResponse.scheme)")
      print("Card type: \(cardDetailsResponse.cardType)")
  } catch {
      print("Error fetching card details: \(error)")
  }

  // Completion handler
  gr4vy.cardDetails.get(request: request) { result in
      switch result {
      case .success(let cardDetailsResponse):
          print("Card brand: \(cardDetailsResponse.scheme)")
          print("Card type: \(cardDetailsResponse.cardType)")
      case .failure(let error):
          print("Error fetching card details: \(error)")
      }
  }
  ```

  ```kotlin Kotlin (Android) theme={"system"}
  val gr4vy = Gr4vy(
      gr4vyId = "example",
      token = "your_jwt_token",
      merchantId = "merchant_123", // Set the default merchant ID
      server = Gr4vyServer.SANDBOX,
      debugMode = true
  )

  // Create card details object
  val cardDetails = Gr4vyCardDetails(
      currency = "USD",
      amount = "1299",
      bin = "411111",
      country = "US",
      intent = "capture"
  )

  // Create request
  val request = Gr4vyCardDetailsRequest(
      timeout = 30.0,
      cardDetails = cardDetails
  )

  // Suspend function
  lifecycleScope.launch {
      try {
          val cardDetailsResponse = gr4vy.cardDetails.get(request)
          println("Card brand: ${cardDetailsResponse.data.scheme}")
          println("Card type: ${cardDetailsResponse.data.cardType}")
      } catch (error: Gr4vyError) {
          println("Error fetching card details: $error")
      }
  }

  // Callback version
  gr4vy.cardDetails.get(request) { result ->
      when {
          result.isSuccess -> {
              val cardDetailsResponse = result.getOrNull()
              println("Card brand: ${cardDetailsResponse?.data?.scheme}")
              println("Card type: ${cardDetailsResponse?.data?.cardType}")
          }
          result.isFailure -> {
              println("Error fetching card details: ${result.exceptionOrNull()}")
          }
      }
  }
  ```
</CodeGroup>

## Best practices

* **Use BIN lookup early**: Retrieve card details as soon as you have the first 6 digits of the card number to provide instant feedback to users.
* **Error handling**: Always handle network and HTTP errors gracefully and show appropriate messages to users.
* **Timeout configuration**: Use custom timeouts for card details requests if your network conditions require it.
* **Cache wisely**: Consider caching card details for a short period to reduce API calls during the same checkout session.
