def pay_order(order: Order): if order.total == 0: raise ValueError("Can't pay an order with total 0.") card = input("Please enter your card number: ") month = int(input("Please enter the card expiry month: ")) year = int(input("Please enter the card expiry year: ")) payment_processor = PaymentProcessor( "6cfb67f3-6281-4031-b893-ea85db0dce20") payment_processor.charge(card, month, year, amount=order.total) order.pay()
def test_invalid_api_key() -> None: with pytest.raises(ValueError): payment_processor = PaymentProcessor("") payment_processor.charge("1249190007575069", 12, 2024, 100)
def test_charge_card_invalid(): with pytest.raises(ValueError): payment_processor = PaymentProcessor(API_KEY) payment_processor.charge("1249190007575068", 12, 2024, 100)
def test_charge_card_valid(): payment_processor = PaymentProcessor(API_KEY) payment_processor.charge("1249190007575069", 12, 2024, 100)
def test_card_number_valid_luhn(): payment_processor = PaymentProcessor(API_KEY) assert payment_processor.luhn_checksum("1249190007575069")
def test_card_number_invalid_date(): payment_processor = PaymentProcessor(API_KEY) assert not payment_processor.validate_card("1249190007575069", 12, 1900)