Browse Source

Delete old Stripe donation view

I'm in the process of replacing this with the new version of Stripe
Checkout, so I'm just going to delete it for now until that's done.
merge-requests/85/head
Deimos 5 years ago
parent
commit
741c169a2f
  1. 3
      tildes/tildes/routes.py
  2. 60
      tildes/tildes/views/donate.py

3
tildes/tildes/routes.py

@ -106,9 +106,6 @@ def includeme(config: Configurator) -> None:
# Route to expose metrics to Prometheus
config.add_route("metrics", "/metrics")
# Route for Stripe donation processing page (POSTed to from docs site)
config.add_route("donate_stripe", "/donate_stripe")
# Add all intercooler routes under the /api/web path
with config.route_prefix_context("/api/web"):
add_intercooler_routes(config)

60
tildes/tildes/views/donate.py

@ -1,60 +0,0 @@
# Copyright (c) 2018 Tildes contributors <code@tildes.net>
# SPDX-License-Identifier: AGPL-3.0-or-later
"""The view for donating via Stripe."""
import stripe
from marshmallow.fields import Email, Float, String
from marshmallow.validate import OneOf, Range
from pyramid.httpexceptions import HTTPInternalServerError
from pyramid.request import Request
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
@view_config(
route_name="donate_stripe",
request_method="POST",
renderer="donate_stripe.jinja2",
permission=NO_PERMISSION_REQUIRED,
require_csrf=False,
)
@use_kwargs(
{
"stripe_token": String(required=True),
"donator_email": Email(required=True),
"amount": Float(required=True, validate=Range(min=1.0)),
"currency": String(required=True, validate=OneOf(("CAD", "USD"))),
}
)
@rate_limit_view("donate")
def post_donate_stripe(
request: Request, stripe_token: str, donator_email: str, amount: int, currency: str
) -> dict:
"""Process a Stripe donation."""
try:
stripe.api_key = request.registry.settings["api_keys.stripe"]
except KeyError:
raise HTTPInternalServerError
incr_counter("donations", type="stripe")
payment_successful = True
try:
stripe.Charge.create(
source=stripe_token,
amount=int(amount * 100),
currency=currency,
receipt_email=donator_email,
description="One-time donation",
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