Browse Source

Add metrics for donations and failures

merge-requests/82/merge
Deimos 5 years ago
parent
commit
e9a193d698
  1. 6
      tildes/tildes/metrics.py
  2. 4
      tildes/tildes/views/donate.py

6
tildes/tildes/metrics.py

@ -18,6 +18,12 @@ _COUNTERS = {
"comment_labels": Counter(
"tildes_comment_labels_total", "Comment Labels", labelnames=["label"]
),
"donations": Counter(
"tildes_donations_total", "Donation Attempts", labelnames=["type"]
),
"donation_failures": Counter(
"tildes_donation_failures_total", "Donation Failures", labelnames=["type"]
),
"invite_code_failures": Counter(
"tildes_invite_code_failures_total", "Invite Code Failures"
),

4
tildes/tildes/views/donate.py

@ -12,6 +12,7 @@ from pyramid.security import NO_PERMISSION_REQUIRED
from pyramid.view import view_config
from webargs.pyramidparser import use_kwargs
from tildes.metrics import incr_counter
from tildes.views.decorators import rate_limit_view
@ -40,6 +41,8 @@ def post_donate_stripe(
except KeyError:
raise HTTPInternalServerError
incr_counter("donations", type="stripe")
payment_successful = True
try:
stripe.Charge.create(
@ -51,6 +54,7 @@ def post_donate_stripe(
statement_descriptor="Donation - tildes.net",
)
except stripe.error.StripeError:
incr_counter("donation_failures", type="stripe")
payment_successful = False
return {"payment_successful": payment_successful}
Loading…
Cancel
Save