diff --git a/remarkbox/routes.py b/remarkbox/routes.py index 725032b..0436014 100644 --- a/remarkbox/routes.py +++ b/remarkbox/routes.py @@ -9,7 +9,6 @@ def includeme(config): # stripe: payment processing via Stripe Checkout config.add_route("billing", "/billing") - config.add_route("pay-what-you-can", "/pay-what-you-can") config.add_route("create-checkout", "/billing/checkout") config.add_route("billing-success", "/billing/success") config.add_route("stripe-webhook", "/webhook/stripe") diff --git a/remarkbox/templates/billing.j2 b/remarkbox/templates/billing.j2 index d681167..7f31989 100644 --- a/remarkbox/templates/billing.j2 +++ b/remarkbox/templates/billing.j2 @@ -1,5 +1,4 @@ {% extends request.base_funnel_template -%} -{% import 'snippets/forms.j2' as forms with context %} {% block title %}{{ the_title }} | {{ request.domain }}{%- endblock -%} {% block content -%} @@ -8,92 +7,37 @@

{{ the_title }}

-

Support Remarkbox with a contribution. Set your preferences below, then pay when you're ready.

+

Support Remarkbox with a contribution. Choose an amount and pay securely with Stripe.


-{# Pay What You Can Preferences #} -{{ forms.pay_what_you_can() }} - -
- -{# Pay Now Button - uses saved preferences or custom amount #}
- Pay Now - {% if request.user.pay_what_you_can and request.user.pay_what_you_can.amount %} -

Pay your configured amount of ${{ request.user.pay_what_you_can.amount }} now.

- - - - {% include 'snippets/csrf.j2' %} - - {% else %} -

Set your contribution amount above first, or enter a custom amount:

- - - - -

- {% include 'snippets/csrf.j2' %} - - {% endif %} -
-
+ Make a Payment -
- -{# Annual Subscription #} -
-
- Annual Subscription -

Support Remarkbox with a yearly contribution.

- - - - - - + + +

- {% include 'snippets/csrf.j2' %} - -
-
-
- -{# Top Up #} -
-
- Top Up -

Make an additional contribution anytime.

- - - - - + + style="width: 100%; max-width: 300px;">

+ + {% include 'snippets/csrf.j2' %} - +
diff --git a/remarkbox/templates/setup-namespace.j2 b/remarkbox/templates/setup-namespace.j2 index ab63268..48c6903 100644 --- a/remarkbox/templates/setup-namespace.j2 +++ b/remarkbox/templates/setup-namespace.j2 @@ -111,10 +111,6 @@ There's no obligation to pay anything. : )

-{{ forms.pay_what_you_can() }} - -
- Go to Billing
@@ -122,15 +118,11 @@ There's no obligation to pay anything. : ) Or PayPal @russellbal -

Thank you so much! -
- - diff --git a/remarkbox/templates/snippets/forms.j2 b/remarkbox/templates/snippets/forms.j2 index 555f6ad..27b717d 100644 --- a/remarkbox/templates/snippets/forms.j2 +++ b/remarkbox/templates/snippets/forms.j2 @@ -73,29 +73,3 @@ {% endmacro %} -{% macro pay_what_you_can() %} -
-
- Pay What You Can - Safely adjust frequency or amount anytime. -
-
- Once
- Yearly
-
- -
-
- We charge cards on the 1st of each month to prevent double charges. -
-
- Once is cumulative, for example let's say you configured amount to $15 and months later adjust to $25, on the 1st of the next month you will be charged $10. -
-
- Yearly acts similar but also reoccurs each anniversary. -
- {% include 'snippets/csrf.j2' %} - -
-
-{% endmacro %} diff --git a/remarkbox/tests/test_stripe.py b/remarkbox/tests/test_stripe.py index 025ba49..8e7bcdd 100644 --- a/remarkbox/tests/test_stripe.py +++ b/remarkbox/tests/test_stripe.py @@ -251,36 +251,3 @@ class TestPaymentModel(unittest.TestCase): payment.mark_failed() self.assertEqual(payment.status, "failed") - - -class TestPayWhatYouCanModel(unittest.TestCase): - """Unit tests for PayWhatYouCan model.""" - - @patch("remarkbox.models.user.is_user_name_available", MagicMock(return_value=True)) - def setUp(self): - self.user = User("test@example.com") - - def test_pay_what_you_can_creation(self): - """Test creating a PayWhatYouCan preference.""" - from remarkbox.models import PayWhatYouCan - - pwc = PayWhatYouCan(self.user, "yearly", 100) - - self.assertEqual(pwc.frequency, "yearly") - self.assertEqual(pwc.amount, 100) - # contributions defaults to 0 in DB but may be None before flush - self.assertIn(pwc.contributions, [0, None]) - self.assertIsNotNone(pwc.created_timestamp) - - def test_pay_what_you_can_update(self): - """Test updating PayWhatYouCan preferences.""" - from remarkbox.models import PayWhatYouCan - - pwc = PayWhatYouCan(self.user, "once", 50) - original_timestamp = pwc.updated_timestamp - - pwc.update("yearly", 100) - - self.assertEqual(pwc.frequency, "yearly") - self.assertEqual(pwc.amount, 100) - self.assertGreaterEqual(pwc.updated_timestamp, original_timestamp) diff --git a/remarkbox/tests/test_views.py b/remarkbox/tests/test_views.py index 49c2cfb..5c1524a 100644 --- a/remarkbox/tests/test_views.py +++ b/remarkbox/tests/test_views.py @@ -409,73 +409,8 @@ class AuthenticatedFunctionalTests(FunctionalTests): """Test that the billing page loads for authenticated users.""" self._log_in_test_user(self.test_creds1) res = self.testapp.get("/billing", status=200) - self.assertIn(b"Pay What You Can", res.body) - self.assertIn(b"Annual Subscription", res.body) - self.assertIn(b"Top Up", res.body) - - def test_pay_what_you_can_preference(self): - """Test saving pay-what-you-can preferences.""" - self._log_in_test_user(self.test_creds1) - - # Save preferences - redirect_res = self.testapp.post( - "/pay-what-you-can", - { - "frequency": "yearly", - "amount": "50", - "csrf_token": self.csrf, - }, - status=302, - ) - res = redirect_res.follow() - self.assertIn(b"Your contribution preferences have been saved", res.body) - - # Verify billing page loads successfully - billing_res = self.testapp.get("/billing", status=200) - self.assertIn(b"Pay What You Can", billing_res.body) - - def test_pay_what_you_can_update_preference(self): - """Test updating pay-what-you-can preferences.""" - self._log_in_test_user(self.test_creds1) - - # Set initial preferences - self.testapp.post( - "/pay-what-you-can", - { - "frequency": "once", - "amount": "25", - "csrf_token": self.csrf, - }, - ) - - # Update preferences - redirect_res = self.testapp.post( - "/pay-what-you-can", - { - "frequency": "yearly", - "amount": "100", - "csrf_token": self.csrf, - }, - status=302, - ) - res = redirect_res.follow() - self.assertIn(b"Your contribution preferences have been saved", res.body) - - def test_pay_what_you_can_missing_fields(self): - """Test pay-what-you-can with missing fields.""" - self._log_in_test_user(self.test_creds1) - - # Missing amount - redirect_res = self.testapp.post( - "/pay-what-you-can", - { - "frequency": "yearly", - "csrf_token": self.csrf, - }, - status=302, - ) - res = redirect_res.follow() - self.assertIn(b"You must set both frequency and amount", res.body) + self.assertIn(b"Make a Payment", res.body) + self.assertIn(b"Pay with Stripe", res.body) @patch("remarkbox.stripe.checkout.stripe.checkout.Session.create") def test_create_checkout_redirects_to_stripe(self, mock_create): diff --git a/remarkbox/views/authenticated/stripe.py b/remarkbox/views/authenticated/stripe.py index fe7c799..89ad005 100644 --- a/remarkbox/views/authenticated/stripe.py +++ b/remarkbox/views/authenticated/stripe.py @@ -19,7 +19,7 @@ from remarkbox.stripe.checkout import ( retrieve_checkout_session, verify_webhook_signature, ) -from remarkbox.models import Payment, PayWhatYouCan, get_payment_by_session_id, create_payment +from remarkbox.models import Payment, get_payment_by_session_id, create_payment import logging @@ -43,25 +43,6 @@ def billing(request): } -@view_config(route_name="pay-what-you-can", request_method="POST") -@user_required() -def pay_what_you_can(request): - """Save user's pay-what-you-can preferences (frequency and amount).""" - frequency = request.params.get("frequency", None) - amount = request.params.get("amount", None) - - if frequency is None or amount is None: - request.session.flash(("You must set both frequency and amount.", "error")) - elif request.user.pay_what_you_can: - request.user.pay_what_you_can.update(frequency, amount) - request.session.flash(("Your contribution preferences have been saved.", "success")) - else: - request.user.pay_what_you_can = PayWhatYouCan(request.user, frequency, amount) - request.session.flash(("Your contribution preferences have been saved.", "success")) - - return HTTPFound("/billing") - - @view_config(route_name="create-checkout", request_method="POST") @user_required() def create_checkout(request):