Fix column name mismatch after copier template update
The subscriptions table still had paddle_subscription_id but the new code references provider_subscription_id. Renamed the DB column and updated all queries in billing/routes.py to match. Also removed unused get_subscription import from dashboard/routes.py. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,8 +53,8 @@ async def upsert_subscription(
|
|||||||
"""Create or update subscription."""
|
"""Create or update subscription."""
|
||||||
now = datetime.utcnow().isoformat()
|
now = datetime.utcnow().isoformat()
|
||||||
|
|
||||||
customer_col = "paddle_customer_id"
|
customer_col = "paddle_customer_id" # legacy column, kept for existing rows
|
||||||
subscription_col = "paddle_subscription_id"
|
subscription_col = "provider_subscription_id"
|
||||||
|
|
||||||
|
|
||||||
existing = await fetch_one("SELECT id FROM subscriptions WHERE user_id = ?", (user_id,))
|
existing = await fetch_one("SELECT id FROM subscriptions WHERE user_id = ?", (user_id,))
|
||||||
@@ -83,7 +83,7 @@ async def upsert_subscription(
|
|||||||
|
|
||||||
async def get_subscription_by_provider_id(subscription_id: str) -> dict | None:
|
async def get_subscription_by_provider_id(subscription_id: str) -> dict | None:
|
||||||
return await fetch_one(
|
return await fetch_one(
|
||||||
"SELECT * FROM subscriptions WHERE paddle_subscription_id = ?",
|
"SELECT * FROM subscriptions WHERE provider_subscription_id = ?",
|
||||||
(subscription_id,)
|
(subscription_id,)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ async def update_subscription_status(provider_subscription_id: str, status: str,
|
|||||||
values = list(extra.values())
|
values = list(extra.values())
|
||||||
|
|
||||||
values.append(provider_subscription_id)
|
values.append(provider_subscription_id)
|
||||||
await execute(f"UPDATE subscriptions SET {sets} WHERE paddle_subscription_id = ?", tuple(values))
|
await execute(f"UPDATE subscriptions SET {sets} WHERE provider_subscription_id = ?", tuple(values))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -197,13 +197,13 @@ async def checkout(plan: str):
|
|||||||
async def manage():
|
async def manage():
|
||||||
"""Redirect to Paddle customer portal."""
|
"""Redirect to Paddle customer portal."""
|
||||||
sub = await get_subscription(g.user["id"])
|
sub = await get_subscription(g.user["id"])
|
||||||
if not sub or not sub.get("paddle_subscription_id"):
|
if not sub or not sub.get("provider_subscription_id"):
|
||||||
await flash("No active subscription found.", "error")
|
await flash("No active subscription found.", "error")
|
||||||
return redirect(url_for("dashboard.settings"))
|
return redirect(url_for("dashboard.settings"))
|
||||||
|
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(
|
response = await client.get(
|
||||||
f"https://api.paddle.com/subscriptions/{sub['paddle_subscription_id']}",
|
f"https://api.paddle.com/subscriptions/{sub['provider_subscription_id']}",
|
||||||
headers={"Authorization": f"Bearer {config.PADDLE_API_KEY}"},
|
headers={"Authorization": f"Bearer {config.PADDLE_API_KEY}"},
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
@@ -217,10 +217,10 @@ async def manage():
|
|||||||
async def cancel():
|
async def cancel():
|
||||||
"""Cancel subscription via Paddle API."""
|
"""Cancel subscription via Paddle API."""
|
||||||
sub = await get_subscription(g.user["id"])
|
sub = await get_subscription(g.user["id"])
|
||||||
if sub and sub.get("paddle_subscription_id"):
|
if sub and sub.get("provider_subscription_id"):
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
await client.post(
|
await client.post(
|
||||||
f"https://api.paddle.com/subscriptions/{sub['paddle_subscription_id']}/cancel",
|
f"https://api.paddle.com/subscriptions/{sub['provider_subscription_id']}/cancel",
|
||||||
headers={
|
headers={
|
||||||
"Authorization": f"Bearer {config.PADDLE_API_KEY}",
|
"Authorization": f"Bearer {config.PADDLE_API_KEY}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from quart import Blueprint, flash, g, jsonify, redirect, render_template, reque
|
|||||||
|
|
||||||
from .. import analytics
|
from .. import analytics
|
||||||
from ..auth.routes import login_required, update_user
|
from ..auth.routes import login_required, update_user
|
||||||
from ..billing.routes import get_subscription
|
|
||||||
from ..core import csrf_protect, execute, fetch_all, fetch_one, soft_delete
|
from ..core import csrf_protect, execute, fetch_all, fetch_one, soft_delete
|
||||||
|
|
||||||
# Blueprint with its own template folder
|
# Blueprint with its own template folder
|
||||||
|
|||||||
Reference in New Issue
Block a user