From 5f3a82bc1fd50102d6f6456b61022f0f883c67ae Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:13:16 +0530 Subject: [PATCH 1/6] Update main.py --- dynamic-not-editable-pricing/main.py | 36 +++++++++++----------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/dynamic-not-editable-pricing/main.py b/dynamic-not-editable-pricing/main.py index 0129a30..bf653bb 100644 --- a/dynamic-not-editable-pricing/main.py +++ b/dynamic-not-editable-pricing/main.py @@ -3,33 +3,25 @@ from fastapi import FastAPI from polar_sdk import Polar from dotenv import load_dotenv -from upstash_redis import Redis from fastapi.responses import RedirectResponse load_dotenv() app = FastAPI() - @app.get("/{amount}") -def read_item(amount: int): - polar = Polar(access_token=getenv("POLAR_API_KEY")) # Organization Access Token - redis = Redis.from_env() - product_id = redis.get(f"dynamic_price_{amount}_product_id") - if not product_id: - res = polar.products.create( - request={ - "recurring_interval": None, - "name": "Dynamic Product Name", - "description": "Dynamic Product Description", - "prices": [ - polar_sdk.ProductPriceFixedCreate( - amount_type="fixed", price_amount=amount * 100 - ) - ], - } - ) - product_id = res.id - redis.set(f"dynamic_price_{amount}_product_id", product_id) - checkoutSession = polar.checkouts.create(request={"products": [product_id]}) +def open_checkout(amount: int): + polar = Polar(access_token=getenv("POLAR_API_KEY")) + checkoutSession = polar.checkouts.create(request={ + "products": [product_id], + "prices": { + [product_id]: [ + { + "price_amount": amount, + "amount_type": "fixed", + "price_currency": "usd", + } + ] + } + }) return RedirectResponse(url=checkoutSession.url) From 58471d3e86a91652569602bd9ac25f0ed36a4281 Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:14:30 +0530 Subject: [PATCH 2/6] Update README.md --- dynamic-not-editable-pricing/README.md | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/dynamic-not-editable-pricing/README.md b/dynamic-not-editable-pricing/README.md index 48b6765..7a2f9c1 100644 --- a/dynamic-not-editable-pricing/README.md +++ b/dynamic-not-editable-pricing/README.md @@ -2,13 +2,12 @@ # Dynamic Not Editable Pricing -This FastAPI application creates dynamic pricing products with Polar integration. It generates products on-demand with custom amounts and caches them using Redis for performance. +This FastAPI application creates dynamic pricing products with Polar integration. It uses [ad-hoc prices](https://polar.sh/docs/features/checkout/session#ad-hoc-prices). ## Prerequisites - Python 3+ installed on your system - Your Polar API key (Organization Access Token) -- Upstash Redis instance ## Setup @@ -43,8 +42,6 @@ Add your credentials to the `.env` file: ``` POLAR_API_KEY=your_polar_oat_here -UPSTASH_REDIS_REST_URL=your_upstash_redis_url_here -UPSTASH_REDIS_REST_TOKEN=your_upstash_redis_token_here ``` You can find your API key in your Polar's Organization settings. @@ -58,23 +55,3 @@ fastapi dev main.py ``` The application will be available at `http://localhost:8000`. - -## API Endpoints - -### GET `/{amount}` - -Creates a dynamic product with the specified amount and redirects to the Polar checkout page. - -**Parameters:** -- `amount` (integer): The price amount in dollars (e.g., 10 for $10.00) - -**Example:** -``` -GET /10 -``` - -This will: -1. Check if a Product ID with amount $10 already exists in Redis cache -2. If not cached, create a new product in Polar with the specified amount -3. Cache the Product ID in Redis for future requests -4. Create a checkout session and redirect to the Polar checkout page From 89f7c860f2edfc08127f814891e93204e7ddc4a8 Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:15:04 +0530 Subject: [PATCH 3/6] Update main.py --- dynamic-not-editable-pricing/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dynamic-not-editable-pricing/main.py b/dynamic-not-editable-pricing/main.py index bf653bb..15a6235 100644 --- a/dynamic-not-editable-pricing/main.py +++ b/dynamic-not-editable-pricing/main.py @@ -9,6 +9,8 @@ app = FastAPI() +product_id = "a-b-c-d" + @app.get("/{amount}") def open_checkout(amount: int): polar = Polar(access_token=getenv("POLAR_API_KEY")) From 7af321f1946cec462a3f7a0422733c310e5fe27e Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:22:40 +0530 Subject: [PATCH 4/6] Update main.py --- dynamic-not-editable-pricing/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dynamic-not-editable-pricing/main.py b/dynamic-not-editable-pricing/main.py index 15a6235..d2c2ba0 100644 --- a/dynamic-not-editable-pricing/main.py +++ b/dynamic-not-editable-pricing/main.py @@ -1,4 +1,3 @@ -import polar_sdk from os import getenv from fastapi import FastAPI from polar_sdk import Polar @@ -17,7 +16,7 @@ def open_checkout(amount: int): checkoutSession = polar.checkouts.create(request={ "products": [product_id], "prices": { - [product_id]: [ + product_id: [ { "price_amount": amount, "amount_type": "fixed", From 5ba789e506e2e6707f3cb22b11545ad169b063fc Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:22:49 +0530 Subject: [PATCH 5/6] Update requirements.txt --- dynamic-not-editable-pricing/requirements.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dynamic-not-editable-pricing/requirements.txt b/dynamic-not-editable-pricing/requirements.txt index 65e8ecb..e9ccf2c 100644 --- a/dynamic-not-editable-pricing/requirements.txt +++ b/dynamic-not-editable-pricing/requirements.txt @@ -1,4 +1,3 @@ python-dotenv polar-sdk -upstash-redis -fastapi[standard] \ No newline at end of file +fastapi[standard] From 434fd5e13c3a2d989e3a34a0b5c286c94236d2cf Mon Sep 17 00:00:00 2001 From: Kakashi Date: Mon, 22 Dec 2025 12:22:57 +0530 Subject: [PATCH 6/6] Update .env.example --- dynamic-not-editable-pricing/.env.example | 3 --- 1 file changed, 3 deletions(-) diff --git a/dynamic-not-editable-pricing/.env.example b/dynamic-not-editable-pricing/.env.example index 26e7ac2..0cdc895 100644 --- a/dynamic-not-editable-pricing/.env.example +++ b/dynamic-not-editable-pricing/.env.example @@ -1,5 +1,2 @@ # Polar Organization Access Token POLAR_API_KEY="polar_oat_..." -# Upstash Environment Variables -UPSTASH_REDIS_REST_URL="https://....upstash.io" -UPSTASH_REDIS_REST_TOKEN="...=" \ No newline at end of file