Skip to content

Commit

Permalink
server/checkout: add Stripe limits when validating PWYW price update
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Dec 20, 2024
1 parent 16f9bc2 commit 0d38ff3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions server/polar/checkout/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import Annotated, Any, Literal

from annotated_types import Ge, Le
from pydantic import (
UUID4,
AliasChoices,
Expand Down Expand Up @@ -51,6 +52,10 @@
ProductPriceList,
)

# Ref: https://stripe.com/docs/api/payment_intents/object#payment_intent_object-amount
MAXIMUM_PRICE_AMOUNT = 99999999
MINIMUM_PRICE_AMOUNT = 50

Amount = Annotated[
int,
Field(
Expand All @@ -59,6 +64,8 @@
"Only useful for custom prices, it'll be ignored for fixed and free prices."
)
),
Ge(MINIMUM_PRICE_AMOUNT),
Le(MAXIMUM_PRICE_AMOUNT),
]
CustomerName = Annotated[
str,
Expand Down
15 changes: 14 additions & 1 deletion server/tests/checkout/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
import pytest_asyncio
import stripe as stripe_lib
from pydantic import HttpUrl
from pydantic import HttpUrl, ValidationError
from pytest_mock import MockerFixture
from sqlalchemy.orm import joinedload

Expand Down Expand Up @@ -1398,6 +1398,19 @@ async def test_price_from_different_product(
),
)

@pytest.mark.parametrize("amount", [10, 20_000_000_000])
async def test_amount_update_max_limits(
self, amount: int, session: AsyncSession, checkout_one_time_custom: Checkout
) -> None:
with pytest.raises(ValidationError):
await checkout_service.update(
session,
checkout_one_time_custom,
CheckoutUpdate(
amount=amount,
),
)

@pytest.mark.parametrize("amount", [500, 10000])
async def test_amount_update_invalid_limits(
self,
Expand Down

0 comments on commit 0d38ff3

Please sign in to comment.