Parse and Enrich Imported Card Data
Problem statement
Stripe merchants can import active card data from another payment processor. You are given two valid CSV strings.
cardsCsvhas headercustomer_id,card_id,first_name,last_name,card_number,expiration. The expiration usesMYYorMMYY, with a two-digit year in the 21st century.usersCsvhas headercustomer_id,email.
For each card row, combine the non-empty first and last names with one space, split the expiration into an unpadded month and a four-digit year, and attach the matching user's email.
Return CSV rows beginning with customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year. Preserve card input order.
Function
parseAndEnrichCardData(cardsCsv: String, usersCsv: String) → String[]Examples
Example 1
cardsCsv = "customer_id,card_id,first_name,last_name,card_number,expiration\ncus_100,card_100,John,Doe,4242424242424242,1023\ncus_200,card_200,Jane,Doe,5555555555554444,921\ncus_300,card_300,,Roberts,6011111111111117,820"usersCsv = "customer_id,email\ncus_300,rob@example.com\ncus_100,john@example.com\ncus_200,jane@example.com"return = ["customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year","cus_100,card_100,john@example.com,John Doe,4242424242424242,10,2023","cus_200,card_200,jane@example.com,Jane Doe,5555555555554444,9,2021","cus_300,card_300,rob@example.com,Roberts,6011111111111117,8,2020"]The user rows may arrive in another order. Cards retain their original order, names are combined from non-empty pieces, and each expiration is split into month and four-digit year.
Example 2
cardsCsv = "customer_id,card_id,first_name,last_name,card_number,expiration\nc1,k1,Ada,Lovelace,4000000000000001,125\nc2,k2,Grace,,4000000000000002,1128"usersCsv = "customer_id,email\nc1,ada@pay.test\nc2,grace@pay.test"return = ["customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year","c1,k1,ada@pay.test,Ada Lovelace,4000000000000001,1,2025","c2,k2,grace@pay.test,Grace,4000000000000002,11,2028"]A three-character expiration has a one-digit month. An empty last name contributes no extra space.
Example 3
cardsCsv = "customer_id,card_id,first_name,last_name,card_number,expiration"usersCsv = "customer_id,email"return = ["customer_id,card_id,email,cardholder_name,card_number,exp_month,exp_year"]When there are no card records, return only the output header.
Constraints
- Each CSV contains its exact header followed by between
0and100000data rows. - Fields contain no commas, line breaks, or surrounding whitespace.
- Customer and card IDs are unique in their respective inputs, and every card customer has exactly one user row.
- At least one of first name and last name is non-empty.
- Every expiration has length
3or4, represents a month from1through12, and ends with a two-digit 21st-century year.