the file under review

src/payments.py

This is the intentionally buggy module the Code Review Crew demo reviews. Each BUG comment marks one of the four issues the reviewer agent finds.

src/payments.py
# A tiny payments module — intentionally buggy, for the review demo.

from dataclasses import dataclass


@dataclass
class Money:
    amount: float
    currency: str


class Result:
    def __init__(self, status, currency):
        self.status = status
        self.currency = currency


def charge(money: Money, card: str) -> Result:
    # BUG: no check that amount is positive — a negative amount credits the customer
    gateway_charge(card, money.amount)

    # BUG: currency compared as a raw string, so "USD" != "usd" fails silently
    if money.currency == "USD":
        settle(money)

    # BUG: no idempotency key — a network retry can double-charge
    return Result(status="succeeded", currency=money.currency)


def retry_payment(money: Money, card: str, attempts: int = 3) -> Result:
    for i in range(attempts):
        try:
            return charge(money, card)
        except Exception:
            # BUG: retries on every exception, including non-transient auth failures
            continue
    raise RuntimeError("payment failed")


def gateway_charge(card: str, amount: float) -> None:
    ...


def settle(money: Money) -> None:
    ...
← Back to the demo