Skip to content

Commit

Permalink
integation: repeat payment with the current amount
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Mar 5, 2024
1 parent a8d6a18 commit 807f85f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions wlhosted/integrations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def notify_paid_removal(billing_id):
@app.task
def recurring_payments():
cutoff = timezone.now().date() + timedelta(days=1)
for billing in Billing.objects.filter(state=Billing.STATE_ACTIVE):
for billing in Billing.objects.filter(state=Billing.STATE_ACTIVE).select_related(
"plan"
):
if "recurring" not in billing.payment:
continue
last_invoice = billing.invoice_set.order_by("-start")[0]
Expand All @@ -69,7 +71,12 @@ def recurring_payments():

original = Payment.objects.get(pk=billing.payment["recurring"])

repeated = original.repeat_payment(billing=billing.pk)
repeated = original.repeat_payment(
amount=billing.plan.price
if original.extra["period"] == "m"
else billing.plan.yearly_price,
billing=billing.pk,
)
if not repeated:
# Remove recurring flag
del billing.payment["recurring"]
Expand Down

0 comments on commit 807f85f

Please sign in to comment.