diff --git a/uncloud/urls.py b/uncloud/urls.py index 169be7f..9097b4c 100644 --- a/uncloud/urls.py +++ b/uncloud/urls.py @@ -86,9 +86,11 @@ urlpatterns = [ # web/ = stuff to view in the browser # path('web/vpn/create/', netviews.WireGuardVPNCreateView.as_view(), name="vpncreate"), + path('login/', authviews.LoginView.as_view(), name="login"), path('logout/', authviews.LogoutView.as_view(), name="logout"), path('admin/', admin.site.urls), path('cc/reg/', payviews.RegisterCard.as_view(), name="cc_register"), + path('cc/submit/', payviews.RegisterCard.as_view(), name="cc_register"), path('', uncloudviews.UncloudIndex.as_view(), name="uncloudindex"), ] diff --git a/uncloud_pay/serializers.py b/uncloud_pay/serializers.py index 9214105..94f833e 100644 --- a/uncloud_pay/serializers.py +++ b/uncloud_pay/serializers.py @@ -5,6 +5,14 @@ from django.utils.translation import gettext_lazy as _ from .models import * +### +# Checked code + + +################################################################################ +# Unchecked code + + ### # Payments and Payment Methods. @@ -18,7 +26,7 @@ class PaymentMethodSerializer(serializers.ModelSerializer): class Meta: model = PaymentMethod - fields = ['uuid', 'source', 'description', 'primary', 'stripe_card_last4', 'active'] + fields = [ 'source', 'description', 'primary', 'stripe_card_last4', 'active'] class UpdatePaymentMethodSerializer(serializers.ModelSerializer): class Meta: @@ -30,10 +38,12 @@ class ChargePaymentMethodSerializer(serializers.Serializer): class CreatePaymentMethodSerializer(serializers.ModelSerializer): please_visit = serializers.CharField(read_only=True) + class Meta: model = PaymentMethod fields = ['source', 'description', 'primary', 'please_visit'] + ### # Orders & Products. diff --git a/uncloud_pay/stripe.py b/uncloud_pay/stripe.py index 2ed4ef2..f4c467a 100644 --- a/uncloud_pay/stripe.py +++ b/uncloud_pay/stripe.py @@ -7,17 +7,10 @@ from django.conf import settings import uncloud_pay.models -# Static stripe configuration used below. CURRENCY = 'chf' -# README: We use the Payment Intent API as described on -# https://stripe.com/docs/payments/save-and-reuse - -# For internal use only. stripe.api_key = settings.STRIPE_KEY -# Helper (decorator) used to catch errors raised by stripe logic. -# Catch errors that should not be displayed to the end user, raise again. def handle_stripe_error(f): def handle_problems(*args, **kwargs): response = { @@ -61,8 +54,6 @@ def handle_stripe_error(f): return handle_problems -# Actual Stripe logic. - def public_api_key(): return settings.STRIPE_PUBLIC_KEY diff --git a/uncloud_pay/templates/uncloud_pay/stripe.html b/uncloud_pay/templates/uncloud_pay/stripe.html index 3051bf0..775ed53 100644 --- a/uncloud_pay/templates/uncloud_pay/stripe.html +++ b/uncloud_pay/templates/uncloud_pay/stripe.html @@ -1,7 +1,9 @@ + {% extends 'uncloud/base.html' %} {% block header %} + + + {% endblock %} {% block body %}
-

Registering Stripe Credit Card

+

Registering Credit Card with Stripe

+

+ By submitting I authorise to send instructions to + the financial institution that issued my card to take + payments from my card account in accordance with the + terms of my agreement with you. +

-
-
- -
- -
+
+ + +
The card will be registered with stripe.
+
- - - - {% endblock %} diff --git a/uncloud_pay/views.py b/uncloud_pay/views.py index 53d6ef4..78a1a15 100644 --- a/uncloud_pay/views.py +++ b/uncloud_pay/views.py @@ -51,12 +51,12 @@ class OrderViewSet(viewsets.ReadOnlyModelViewSet): class RegisterCard(LoginRequiredMixin, TemplateView): login_url = '/login/' - # This is not supposed to be "static" -- - # the idea is to be able to switch the provider when needed template_name = "uncloud_pay/stripe.html" def get_context_data(self, **kwargs): + customer_id = uncloud_stripe.get_customer_id_for(self.request.user) + setup_intent = uncloud_stripe.create_setup_intent(customer_id) context = super().get_context_data(**kwargs) @@ -159,7 +159,7 @@ class PaymentMethodViewSet(viewsets.ModelViewSet): # TODO: find a way to use reverse properly: # https://www.django-rest-framework.org/api-guide/reverse/ callback_path= "payment-method/{}/activate-stripe-cc/".format( - payment_method.uuid) + payment_method.id) callback = reverse('api-root', request=request) + callback_path # Render stripe card registration form.