Handle case where subscription_payment_succeeded arrives BEFORE subscription_created
This commit is contained in:
parent
9b91f4a4a4
commit
b845e2a8eb
13
server.py
13
server.py
|
@ -385,12 +385,15 @@ def setup_paddle_callback(app: Flask):
|
||||||
LOG.debug("Update subscription %s", subscription_id)
|
LOG.debug("Update subscription %s", subscription_id)
|
||||||
|
|
||||||
sub: Subscription = Subscription.get_by(subscription_id=subscription_id)
|
sub: Subscription = Subscription.get_by(subscription_id=subscription_id)
|
||||||
sub.event_time = arrow.now()
|
# when user subscribes, the "subscription_payment_succeeded" can arrive BEFORE "subscription_created"
|
||||||
sub.next_bill_date = arrow.get(
|
# at that time, subscription object does not exist yet
|
||||||
request.form.get("next_bill_date"), "YYYY-MM-DD"
|
if sub:
|
||||||
).date()
|
sub.event_time = arrow.now()
|
||||||
|
sub.next_bill_date = arrow.get(
|
||||||
|
request.form.get("next_bill_date"), "YYYY-MM-DD"
|
||||||
|
).date()
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
elif request.form.get("alert_name") == "subscription_cancelled":
|
elif request.form.get("alert_name") == "subscription_cancelled":
|
||||||
subscription_id = request.form.get("subscription_id")
|
subscription_id = request.form.get("subscription_id")
|
||||||
|
|
Loading…
Reference in a new issue