diff --git a/payments/views.py b/payments/views.py index 1538ef4..c298455 100644 --- a/payments/views.py +++ b/payments/views.py @@ -1,5 +1,7 @@ from django.http import JsonResponse, HttpResponse, Http404 from django.views.decorators.http import require_POST +from messaging.views import send_bulk_message +from messaging.serializers import MessageData from oauth2_provider.decorators import protected_resource from utils.rest_framework import ClientProtectedResourceAuth from rest_framework.decorators import api_view @@ -60,12 +62,32 @@ class ValidatePhoneNumber(APIView): def post(self, request, *args, **kwargs): username = request.data["username"] phone_number = request.data["phone_number"] + is_valid = request.data["is_valid"] user = ConnectUser.objects.get(username=username) profile = getattr(user, "payment_profile") if not profile or profile.phone_number != phone_number: raise Http404("Payment number not found") - profile.is_validated = True + profile.is_validated = is_valid profile.save() + if is_valid: + message = MessageData( + usernames=["username"], + title="Your Payment Phonenumber is approved", + body="Your payment phone number is approved and future payments will be made to this number", + data={ + "action": "ccc_payment_info_confirmation", + "confirmation_status": True + }) + else: + message = MessageData( + usernames=["username"], + title="Your Payment Phonenumber did not work", + body="Your payment number did not work. Please try to change to a different payment phone number", + data={ + "action": "ccc_payment_info_confirmation", + "confirmation_status": True + }) + send_bulk_message(message) return HttpResponse()