Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sravfeyn committed Nov 14, 2024
1 parent bb30069 commit d9b1316
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 9 additions & 11 deletions payments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def update_payment_profile_phone(request):

@api_view(['POST'])
def confirm_payment_profile_otp(request):
PaymentProfile.objects.get(user=request.user)
payment_profile = request.user.payment_profile
device = PhoneDevice.objects.get(phone_number=payment_profile.phone_number, user=payment_profile.user)
if not device.verify_token(request.data.get('token')):
Expand Down Expand Up @@ -98,19 +97,18 @@ def post(self, request, *args, **kwargs):
"approved": [],
"rejected": [],
}
with transaction.atomic():
for profile in profiles:
key = (profile.user.username, profile.phone_number)
requested_status = status_map.get(key)
for profile in profiles:
key = (profile.user.username, profile.phone_number)
requested_status = status_map.get(key)

if profile.status != requested_status:
profile.status = requested_status
profiles_to_update.append(profile)
if profile.status != requested_status:
profile.status = requested_status
profiles_to_update.append(profile)

usernames_by_states[requested_status].append(profile.user.username)
usernames_by_states[requested_status].append(profile.user.username)

if profiles_to_update:
PaymentProfile.objects.bulk_update(profiles_to_update, ['status'])
if profiles_to_update:
PaymentProfile.objects.bulk_update(profiles_to_update, ['status'])

if usernames_by_states["approved"]:
send_bulk_message(
Expand Down
6 changes: 6 additions & 0 deletions utils/twilio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import logging

from twilio.rest import Client
from django.conf import settings


logger = logging.getLogger(__name__)

# Create the client instance only once
twilio_client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)

Expand All @@ -14,4 +19,5 @@ def lookup_telecom_provider(phone_number):
phone_info = client.lookups.v1.phone_numbers(phone_number).fetch(type="carrier")
return phone_info.carrier.get("name")
except Exception as e:
logger.exception("Error occurred during twilio call: %s", str(e))
return None

0 comments on commit d9b1316

Please sign in to comment.