mirror of
https://github.com/simple-login/app.git
synced 2026-04-07 19:27:34 +00:00
Update for all paddle
This commit is contained in:
+16
-8
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
import arrow
|
||||
from dateutil.relativedelta import relativedelta
|
||||
@@ -32,6 +33,8 @@ def setup_paddle_callback(app: Flask):
|
||||
LOG.e("request not coming from paddle. Request data:%s", dict(request.form))
|
||||
return "KO", 400
|
||||
|
||||
sub: Optional[Subscription] = None
|
||||
|
||||
if (
|
||||
request.form.get("alert_name") == "subscription_created"
|
||||
): # new user subscribes
|
||||
@@ -70,14 +73,6 @@ def setup_paddle_callback(app: Flask):
|
||||
).date(),
|
||||
plan=plan,
|
||||
)
|
||||
EventDispatcher.send_event(
|
||||
user=user,
|
||||
content=EventContent(
|
||||
user_plan_change=UserPlanChanged(
|
||||
plan_end_time=arrow.get(sub.next_bill_date).timestamp
|
||||
)
|
||||
),
|
||||
)
|
||||
emit_user_audit_log(
|
||||
user=user,
|
||||
action=UserAuditLogAction.Upgrade,
|
||||
@@ -264,6 +259,19 @@ def setup_paddle_callback(app: Flask):
|
||||
LOG.w("partial subscription_payment_refunded, not handled")
|
||||
execute_subscription_webhook(sub.user)
|
||||
|
||||
if sub:
|
||||
if sub.cancelled:
|
||||
plan_end_time = None
|
||||
else:
|
||||
plan_end_time = arrow.get(sub.next_bill_date).timestamp
|
||||
|
||||
EventDispatcher.send_event(
|
||||
user=sub.user,
|
||||
content=EventContent(
|
||||
user_plan_change=UserPlanChanged(plan_end_time=plan_end_time)
|
||||
),
|
||||
)
|
||||
|
||||
return "OK"
|
||||
|
||||
@app.route("/paddle_coupon", methods=["GET", "POST"])
|
||||
|
||||
Reference in New Issue
Block a user