Katkat

Validate virtual credit card transactions from encoded IDs

Capital OneMachine Learning Engineer · Onsite

Last updated

This question evaluates understanding of virtual credit card product trade-offs and the ability to design data models and deterministic validation logic for encoded transaction attributes, testing competencies in payment systems, data encoding/decoding, and rule-based validation.

You are designing logic for a virtual credit card product.

Part 1: Product reasoning

Explain key benefits and drawbacks of virtual credit cards for:

  • end users,
  • the issuer (e.g., a bank).

Part 2: Transaction validation rules

A transaction is described by:

  • card_number: a 16-digit string
  • transaction_id: an 8-digit string
  • amount: integer dollars

Certain attributes are encoded in the digits:

Transaction ID (8 digits, positions counted from left starting at 1)

  • If the 7th digit is 1 ⇒ transaction is online; if 0 ⇒ offline/in-person.
  • If the 6th digit is 1 ⇒ type is charge; if 0 ⇒ type is authorization.

Card number (16 digits, positions counted from left starting at 1)

  • If the 15th digit is 1 ⇒ merchant-bound; if 0 ⇒ not merchant-bound.
  • If the 14th digit is 1 ⇒ network is Master; if 0 ⇒ Visa.
  • If the 13th digit is 1 ⇒ multi-use; if 0 ⇒ one-time-use.

Validity rules by network

A transaction is valid if it satisfies the rules for its network:

Visa: valid iff

  • (merchant_bound AND multi_use) OR
  • (online AND amount < 100 AND type is NOT authorization)

Master: valid iff

  • (amount < 100 AND (online OR offline) AND NOT merchant_bound) OR
  • (merchant_bound AND amount > 100)

Tasks

  1. Describe an approach (data model + validation flow) to determine whether a transaction is valid.
  2. For the following example, determine whether it is valid:
  • card_number = "1234567891011111"
  • transaction_id = "50781100"
  • amount = 150
  1. Explain how you would test this logic (unit tests and edge cases).