Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client property #11

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from datetime import datetime, timezone, timedelta
import requests
from django.conf import settings
from bitcamp import settings as bitcamp_settings
import logging

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -124,6 +125,19 @@ def post(self, request, **kwargs):

logger.info("SERIALIZER CREATED")

if request.data.get("client"):
client = request.data.get("client")
if client in bitcamp_settings.PAYMENT_HOOK_CLIENTS:
client = bitcamp_settings.PAYMENT_HOOK_CLIENTS[client]
else:
logger.info("Client not found")
# We can set the default here
client = "https://www.bitcamp.ge/dashboard?payment=success"
logger.info(f"Client: {client}")
else:
logger.info("Client not found")
# We can also set the default here
client = "https://www.bitcamp.ge/dashboard?payment=success"

if serializer.is_valid():
logger.info("SERIALIZER IS VALID")
Expand Down Expand Up @@ -281,9 +295,9 @@ def post(self, request, **kwargs):
"tokenizeCard": True
},
"hooks": {
"webhookGateway": "https://platform.bitcamp.ge/payments/payze_hook",
"successRedirectGateway": f"https://platform.bitcamp.ge/enrollments/{newEnrollment.id}/check-payze-subscription-status",
"errorRedirectGateway": f"https://platform.bitcamp.ge/enrollments/{newEnrollment.id}/check-payze-subscription-status"
"webhookGateway": f"https://platform.bitcamp.ge/payments/payze_hook?client={client}",
"successRedirectGateway": f"https://platform.bitcamp.ge/enrollments/{newEnrollment.id}/check-payze-subscription-status?client={client}",
"errorRedirectGateway": f"https://platform.bitcamp.ge/enrollments/{newEnrollment.id}/check-payze-subscription-status?client={client}"
},
"metadata": {
"extraAttributes": [
Expand Down Expand Up @@ -440,7 +454,17 @@ def get(self, request, id, **kwargs):
serializer = serializers.PaymentSerializer(updated_payments, many=True)

# Here I need to redirect user to a frontend URL with a different domain.
return HttpResponseRedirect('https://www.bitcamp.ge/dashboard?payment=success')

# Yeah yeah, whatever ChatGPT. Shut up

if request.query_params.get("client"):
client = request.query_params.get("client")
if client in bitcamp_settings.PAYMENT_HOOK_CLIENTS or client in bitcamp_settings.PAYMENT_HOOK_CLIENTS.values():
client = bitcamp_settings.PAYMENT_HOOK_CLIENTS[client]
else:
client = "https://www.bitcamp.ge/dashboard?payment=success"

return HttpResponseRedirect(client)
except models.Enrollment.DoesNotExist:
return Response({"error": "Enrollment not found"}, status=status.HTTP_404_NOT_FOUND)

Expand Down
6 changes: 6 additions & 0 deletions bitcamp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

PAYMENT_HOOK_CLIENTS = {
"bitcamp.ge": "https://dashboard.bitcamp.ge/?payment=success",
"universiteti.ge": "https://dashboard.universiteti.ge/?payment=success",
"cs50x.ge": "https://dashboard.cs50x.ge/?payment=success",
}

# Application definition

INSTALLED_APPS = [
Expand Down