Skip to content

Commit 21cb538

Browse files
authored
fix(worker): only count successful payments toward total spend (#31)
Failed and refunded charges were being summed into the 'spent on Nitro' total, inflating the figure (sometimes 4x). Filter on Discord's Payment.status enum to keep only status=1 (SUCCESSFUL). Closes dumpus-app/dumpus-app#261.
1 parent 9307f07 commit 21cb538

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ def read_analytics_file(package_status_id, package_id, link, session):
237237
with zip.open(payments_path) as f:
238238
payment_records = orjson.loads(f.read()).get('records', [])
239239

240+
# Only count successful payments. Discord's Payment.status enum:
241+
# 1 = SUCCESSFUL, 2 = FAILED, 3 = REFUNDED, 4 = REFUND_PENDING,
242+
# 5 = PARTIALLY_REFUNDED, 6 = PENDING. Without this filter, failed
243+
# and refunded charges inflate the "spent on Nitro" total.
240244
for payment in payment_records:
245+
if payment.get('status') != 1:
246+
continue
241247
payments.append({
242248
'id': payment['id'],
243249
'amount': payment['amount'],

0 commit comments

Comments
 (0)