Skip to main content
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.
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)")
    }
}

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.