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
-
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).