Skip to content

Instantly share code, notes, and snippets.

@vndee
Created May 30, 2024 03:44
Show Gist options
  • Save vndee/259a381cbc0d27e3475f37279ebed4a9 to your computer and use it in GitHub Desktop.
Save vndee/259a381cbc0d27e3475f37279ebed4a9 to your computer and use it in GitHub Desktop.
import uuid
class PaymentProcessor:
def __init__(self):
self.processed_requests = set()
def process_payment(self, payment_id, amount):
if payment_id in self.processed_requests:
return {"status": "already_processed"}
else:
self.processed_requests.add(payment_id)
# Process the payment (pseudo-code)
# charge_credit_card(amount)
return {"status": "success"}
# Example usage
processor = PaymentProcessor()
payment_id = str(uuid.uuid4())
result1 = processor.process_payment(payment_id, 100)
result2 = processor.process_payment(payment_id, 100)
print(result1) # {"status": "success"}
print(result2) # {"status": "already_processed"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment