← 返回 capitalone 的题目列表Validate Virtual Credit Card Transaction
类型:online_judge
You're tasked with designing a function to validate a virtual credit card transaction. Each transaction has the following information:
Card Number: 16-digit number
Transaction ID: 8-digit number
Amount: Integer
Online/Offline: String ('online' or 'offline')
Transaction Type: String ('charge' or 'authorization')
Merchant Bound: Boolean
Payment Type: String ('visa' or 'master')
You need to determine the validity of a transaction based on the following rules:
Transaction ID: 7th digit is 1 for valid online, 0 for valid offline. 6th digit is 1 for charge, 0 for authorization.
Card Number: 15th digit is 1 if merchant bound, 0 if not. 14th digit is 1 for MasterCard, 0 for Visa. 13th digit is 1 for multi-use, 0 for one-time use.
Valid transaction rules vary for payment types:
Visa: (merchant-bound and multi-use) or (online, amount<$100, not authorization)
Master: (amount<$100, online or in-person, not merchant-bound) or (bounded, amount>$100)
Implement a function is_valid_transaction(card_number: str, transaction_id: str, amount: int, online_offline: str, transaction_type: str, merchant_bound: bool, payment: str) -> bool.
Example:
Input:
card_number: "1234567891011011" transaction_id: "50781210" amount: 150 online_offline: "offline" transaction_type: "charge" merchant_bound: True payment: "master"
Output:
True
Explanation: Based on the rules, the transaction is valid.
Example
Input
card_number: "1234567891011011"
transaction_id: "50781210"
amount: 150
online_offline: "offline"
transaction_type: "charge"
merchant_bound: True
payment: "master"