From b958cc77ead642c7cac2665a2d64e8771293bd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 5 Mar 2020 11:45:37 +0100 Subject: [PATCH] Fix duplicates in payment method creation --- uncloud/uncloud_pay/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uncloud/uncloud_pay/views.py b/uncloud/uncloud_pay/views.py index 6b54214..32350ff 100644 --- a/uncloud/uncloud_pay/views.py +++ b/uncloud/uncloud_pay/views.py @@ -56,7 +56,6 @@ class PaymentMethodViewSet(viewsets.ModelViewSet): def create(self, request): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) - payment_method = PaymentMethod.objects.create(owner=request.user, **serializer.validated_data) if serializer.validated_data['source'] == "stripe": # Retrieve Stripe customer ID for user. @@ -83,8 +82,9 @@ class PaymentMethodViewSet(viewsets.ModelViewSet): payment_method.uuid) stripe_registration_url = reverse('api-root', request=request) + path return Response({'please_visit': stripe_registration_url}) - - return Response(serializer.data) + else: + serializer.save(owner=request.user, **serializer.validated_data) + return Response(serializer.data) @action(detail=True, methods=['post']) def charge(self, request, pk=None):