mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 17:35:27 +08:00
handle subscription_payment_refunded event (#1075)
This commit is contained in:
parent
3d3d408a8f
commit
715ce33b09
1 changed files with 34 additions and 0 deletions
34
server.py
34
server.py
|
@ -8,6 +8,7 @@ import flask_profiler
|
|||
import sentry_sdk
|
||||
from coinbase_commerce.error import WebhookInvalidPayload, SignatureVerificationError
|
||||
from coinbase_commerce.webhook import Webhook
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from flask import (
|
||||
Flask,
|
||||
redirect,
|
||||
|
@ -567,6 +568,39 @@ def setup_paddle_callback(app: Flask):
|
|||
Session.commit()
|
||||
LOG.e("%s requests a refund", user)
|
||||
|
||||
elif request.form.get("alert_name") == "subscription_payment_refunded":
|
||||
subscription_id = request.form.get("subscription_id")
|
||||
sub: Subscription = Subscription.get_by(subscription_id=subscription_id)
|
||||
LOG.d(
|
||||
"Handle subscription_payment_refunded for subscription %s",
|
||||
subscription_id,
|
||||
)
|
||||
|
||||
if not sub:
|
||||
LOG.w(
|
||||
"No such subscription for %s, payload %s",
|
||||
subscription_id,
|
||||
request.form,
|
||||
)
|
||||
return "No such subscription"
|
||||
|
||||
plan_id = request.form["subscription_plan_id"]
|
||||
if request.form["refund_type"] == "full":
|
||||
if plan_id == PADDLE_MONTHLY_PRODUCT_ID:
|
||||
LOG.d("subtract 1 month from next_bill_date %s", sub.next_bill_date)
|
||||
sub.next_bill_date = sub.next_bill_date - relativedelta(months=1)
|
||||
LOG.d("next_bill_date is %s", sub.next_bill_date)
|
||||
Session.commit()
|
||||
elif plan_id == PADDLE_YEARLY_PRODUCT_IDS:
|
||||
LOG.d("subtract 1 year from next_bill_date %s", sub.next_bill_date)
|
||||
sub.next_bill_date = sub.next_bill_date - relativedelta(years=1)
|
||||
LOG.d("next_bill_date is %s", sub.next_bill_date)
|
||||
Session.commit()
|
||||
else:
|
||||
LOG.e("Unknown plan_id %s", plan_id)
|
||||
else:
|
||||
LOG.w("partial subscription_payment_refunded, not handled")
|
||||
|
||||
return "OK"
|
||||
|
||||
@app.route("/paddle_coupon", methods=["GET", "POST"])
|
||||
|
|
Loading…
Reference in a new issue