-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpayment.py
40 lines (30 loc) · 1.24 KB
/
payment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import random
import uuid
from typing import Self
class PaymentProcessor:
def __init__(self: Self, api_key: str):
self.api_key = api_key
def initiate_payment(self: Self, amount: int) -> str:
payment_id = str(uuid.uuid4())
print(f"Initiating payment with ID: {payment_id} and amount {amount}")
return payment_id
def verify_payment(self: Self, payment_id: str) -> bool:
print(f"Verifying payment with ID: {payment_id}")
return True
def check_payment_status(self: Self, payment_id: str) -> bool:
print(f"Checking payment status for ID: {payment_id}")
return random.randint(1, 10) < 3 # 20% chance of returning True
class PaymentProcessorFacade:
def __init__(self: Self, api_key: str):
self.api_key = api_key
self._payment_processor = PaymentProcessor(api_key)
def pay(self: Self, amount: int) -> bool:
payment_id = self._payment_processor.initiate_payment(amount)
if not self._payment_processor.verify_payment(payment_id):
return False
count = 0
while count < 10:
if self._payment_processor.check_payment_status(payment_id):
return True
count += 1
return False