diff --git a/litecord/blueprints/user/billing.py b/litecord/blueprints/user/billing.py index 56ff7cc..7f79551 100644 --- a/litecord/blueprints/user/billing.py +++ b/litecord/blueprints/user/billing.py @@ -220,15 +220,18 @@ async def get_payment(payment_id: int, db=None): return drow -async def create_payment(subscription_id, app): +async def create_payment(subscription_id, db=None): """Create a payment.""" - sub = await get_subscription(subscription_id, app.db) + if not db: + db = app.db + + sub = await get_subscription(subscription_id, db) new_id = get_snowflake() amount = AMOUNTS[sub['payment_gateway_plan_id']] - await app.db.execute( + await db.execute( """ INSERT INTO user_payments ( id, source_id, subscription_id, user_id, diff --git a/litecord/blueprints/user/billing_job.py b/litecord/blueprints/user/billing_job.py index 6dce986..66bd902 100644 --- a/litecord/blueprints/user/billing_job.py +++ b/litecord/blueprints/user/billing_job.py @@ -54,18 +54,24 @@ async def _process_user_payments(app, user_id: int): subscription = await get_subscription( sub_id, app.db) + # if the max payment is X days old, we create another. + # X is 30 for monthly subscriptions of nitro, + # X is 365 for yearly subscriptions of nitro threshold = THRESHOLDS[subscription['payment_gateway_plan_id']] log.debug('delta {} delta days {} threshold {}', delta, delta.days, threshold) if delta.days > threshold: - # insert new payment, for free !!!!!! log.info('creating payment for sid={}', sub_id) + + # create_payment does not call any Stripe + # or BrainTree APIs at all, since we'll just + # give it as free. await create_payment(sub_id, app) else: - log.debug('not there yet for sid={}', sub_id) + log.debug('sid={}, missing {threshold - delta.days} days', sub_id) async def payment_job(app): @@ -74,7 +80,7 @@ async def payment_job(app): This function will check through users' payments and add a new one once a month / year. """ - log.info('payment job start!') + log.debug('payment job start!') user_ids = await app.db.fetch(""" SELECT DISTINCT user_id @@ -82,7 +88,6 @@ async def payment_job(app): """) log.debug('working {} users', len(user_ids)) - print(user_ids) # go through each user's payments for row in user_ids: