Validate virtual credit card transactions from encoded IDs
Capital OneMachine Learning Engineer · OnsiteLast 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 stringtransaction_id: an 8-digit stringamount: 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; if0⇒ offline/in-person. - If the 6th digit is
1⇒ type is charge; if0⇒ type is authorization.
Card number (16 digits, positions counted from left starting at 1)
- If the 15th digit is
1⇒ merchant-bound; if0⇒ not merchant-bound. - If the 14th digit is
1⇒ network is Master; if0⇒ Visa. - If the 13th digit is
1⇒ multi-use; if0⇒ one-time-use.
Validity rules by network
A transaction is valid if it satisfies the rules for its network:
Visa: valid iff
- (
merchant_boundANDmulti_use) OR - (
onlineANDamount < 100AND type is NOTauthorization)
Master: valid iff
- (
amount < 100AND (online OR offline) AND NOTmerchant_bound) OR - (
merchant_boundANDamount > 100)
Tasks
- Describe an approach (data model + validation flow) to determine whether a transaction is valid.
- For the following example, determine whether it is valid:
card_number = "1234567891011111"transaction_id = "50781100"amount = 150
- Explain how you would test this logic (unit tests and edge cases).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.