diff --git a/SMS/settings.py b/SMS/settings.py
index 8e28336..a955754 100644
--- a/SMS/settings.py
+++ b/SMS/settings.py
@@ -50,7 +50,10 @@ INSTALLED_APPS = [
'result.apps.ResultConfig',
'search.apps.SearchConfig',
'quiz.apps.QuizConfig',
- 'crispy_forms'
+ 'payments',
+
+ 'crispy_forms',
+ 'rest_framework',
]
MIDDLEWARE = [
@@ -157,3 +160,21 @@ CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
+
+REST_FRAMEWORK = {
+ # 'DEFAULT_RENDERER_CLASSES': [
+ # 'rest_framework.renderers.JSONRenderer',
+ # ],
+ # 'DEFAULT_PARSER_CLASSES': [
+ # 'rest_framework.parsers.JSONParser',
+ # ]
+ 'DEFAULT_PERMISSION_CLASSES': [
+ 'rest_framework.permissions.IsAuthenticated',
+ ],
+ 'DEFAULT_AUTHENTICATION_CLASSES': [
+ 'rest_framework.authentication.SessionAuthentication',
+ 'rest_framework.authentication.BasicAuthentication'
+ ]
+}
+STRIPE_SECRET_KEY = "sk_test_51IcEVZHbzY4cUA9T3BZdDayN4gmbJyXuaLCzpLT15HZoOmC17G7CxeEdXeIHSWyhYfxpljsclzzjsFukYNqJTbrW00tv3qIbN2"
+STRIPE_PUBLISHABLE_KEY = "pk_test_51IcEVZHbzY4cUA9TrKHqyHkUQqQRRMoilwYgwSJaMjfis6rN6KZPmjcbGX6LUHpIkUV2i06JBnplberIbHtYcdfv00Tu8eMXHj"
diff --git a/SMS/urls.py b/SMS/urls.py
index 563f383..04e39bd 100644
--- a/SMS/urls.py
+++ b/SMS/urls.py
@@ -15,6 +15,10 @@ urlpatterns = [
url(r'^search/', include('search.urls')),
url(r'^quiz/', include('quiz.urls')),
+ url(r'^payments/', include('payments.urls')),
+
+ url('accounts/api/', include('accounts.api.urls', namespace='accounts-api')),
+
url(r'^admin/', admin.site.urls),
]
diff --git a/accounts/api/serializers.py b/accounts/api/serializers.py
index e69de29..8f40b38 100644
--- a/accounts/api/serializers.py
+++ b/accounts/api/serializers.py
@@ -0,0 +1,10 @@
+from rest_framework import serializers
+from django.contrib.auth.views import get_user_model
+
+User = get_user_model()
+
+
+class UserSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = User
+ fields = '__all__'
diff --git a/accounts/api/urls.py b/accounts/api/urls.py
index e69de29..fc6a8b0 100644
--- a/accounts/api/urls.py
+++ b/accounts/api/urls.py
@@ -0,0 +1,9 @@
+from . import views
+
+from django.urls import path
+
+app_name = "accounts-api"
+
+urlpatterns = [
+ path('', views.UserListAPIView.as_view(), name="users-api"),
+]
\ No newline at end of file
diff --git a/accounts/api/views.py b/accounts/api/views.py
index e69de29..958d0f5 100644
--- a/accounts/api/views.py
+++ b/accounts/api/views.py
@@ -0,0 +1,24 @@
+from rest_framework import generics
+from django.contrib.auth.views import get_user_model
+
+from .serializers import UserSerializer
+
+User = get_user_model()
+
+
+class UserListAPIView(generics.ListAPIView):
+ lookup_field = 'id'
+ serializer_class = UserSerializer
+
+ def get_queryset(self):
+ qs = User.objects.all()
+ q = self.request.GET.get('q')
+ if q is not None:
+ qs = qs.filter(username__iexact=q)
+ return qs
+
+
+class UserDetailView(generics.RetrieveAPIView):
+ lookup_field = 'id'
+ queryset = User.objects.all()
+ model = User
diff --git a/accounts/migrations/0010_auto_20210401_1718.py b/accounts/migrations/0010_auto_20210401_1718.py
new file mode 100644
index 0000000..db9d022
--- /dev/null
+++ b/accounts/migrations/0010_auto_20210401_1718.py
@@ -0,0 +1,30 @@
+# Generated by Django 3.1.3 on 2021-04-01 14:18
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0009_auto_20200906_1403'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='parent',
+ name='student',
+ field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='accounts.student'),
+ ),
+ migrations.AlterField(
+ model_name='parent',
+ name='user',
+ field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
+ ),
+ migrations.AlterField(
+ model_name='user',
+ name='first_name',
+ field=models.CharField(blank=True, max_length=150, verbose_name='first name'),
+ ),
+ ]
diff --git a/app/api/serializers.py b/app/api/serializers.py
index e69de29..8f3c222 100644
--- a/app/api/serializers.py
+++ b/app/api/serializers.py
@@ -0,0 +1,10 @@
+# from rest_framework import serializers
+# from django.contrib.auth.views import get_user_model
+#
+# User = get_user_model()
+#
+#
+# class UserSerializer(serializers.ModelSerializer):
+# class Meta:
+# model = User
+# fields = '__all__'
diff --git a/payments/__init__.py b/payments/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/payments/admin.py b/payments/admin.py
new file mode 100644
index 0000000..8c38f3f
--- /dev/null
+++ b/payments/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/payments/apps.py b/payments/apps.py
new file mode 100644
index 0000000..58d36ac
--- /dev/null
+++ b/payments/apps.py
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class PaymentsConfig(AppConfig):
+ name = 'payments'
diff --git a/payments/migrations/__init__.py b/payments/migrations/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/payments/models.py b/payments/models.py
new file mode 100644
index 0000000..71a8362
--- /dev/null
+++ b/payments/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/payments/server.py b/payments/server.py
new file mode 100644
index 0000000..1109a56
--- /dev/null
+++ b/payments/server.py
@@ -0,0 +1,8 @@
+# Set your secret key. Remember to switch to your live secret key in production.
+# See your keys here: https://dashboard.stripe.com/account/apikeys
+stripe.api_key = "sk_test_51IcEVZHbzY4cUA9T3BZdDayN4gmbJyXuaLCzpLT15HZoOmC17G7CxeEdXeIHSWyhYfxpljsclzzjsFukYNqJTbrW00tv3qIbN2"
+
+intent = stripe.PaymentIntent.create(
+ amount=1099,
+ currency='usd',
+)
diff --git a/payments/templates/payments/charge.html b/payments/templates/payments/charge.html
new file mode 100644
index 0000000..e43a4f3
--- /dev/null
+++ b/payments/templates/payments/charge.html
@@ -0,0 +1,48 @@
+{% extends 'base.html' %}
+{% block title %}PayPal{% endblock title %}
+{% load static %}
+
+{% block header %}
+
+{% endblock %}
+
+{% block content %}
+
+
+
+ Payment Succeed, You has been make payment successfuly.
+ Redirect to your dashboard in 8
+
+
+
+{% endblock content %}
+
+{% block js %}
+
+
+
+{% endblock %}
diff --git a/payments/templates/payments/coinbase.html b/payments/templates/payments/coinbase.html
new file mode 100644
index 0000000..6cd80f6
--- /dev/null
+++ b/payments/templates/payments/coinbase.html
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block title %}Coinbase{% endblock title %}
+{% load static %}
+
+{% block content %}
+
+
Coinbase
+
+{% endblock content %}
diff --git a/payments/templates/payments/home.html b/payments/templates/payments/home.html
new file mode 100644
index 0000000..f7d0fa8
--- /dev/null
+++ b/payments/templates/payments/home.html
@@ -0,0 +1,9 @@
+Buy for $5.00
+
diff --git a/payments/templates/payments/paylike.html b/payments/templates/payments/paylike.html
new file mode 100644
index 0000000..3e30d0e
--- /dev/null
+++ b/payments/templates/payments/paylike.html
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block title %}PayLike{% endblock title %}
+{% load static %}
+
+{% block content %}
+
+
PayLike
+
+{% endblock content %}
diff --git a/payments/templates/payments/payment_gateways.html b/payments/templates/payments/payment_gateways.html
new file mode 100644
index 0000000..53e3520
--- /dev/null
+++ b/payments/templates/payments/payment_gateways.html
@@ -0,0 +1,153 @@
+{% extends 'base.html' %}
+{% block title %}Choose a gateway{% endblock title %}
+{% load static %}
+
+{% block header %}
+
+{% endblock %}
+
+{% block content %}
+
+
+
Payment GateWays
+
+
+
+
+
Stripe
+
+
+
+ Make payment with stripe and get jobs done.
+
+
+
+
CoinBase
+
C CoinBase
+
+ Make payment with stripe and get jobs done.
+
+
+
+
Paylike
+
Paylike
+
+ Make payment with stripe and get jobs done.
+
+
+
+
+
+
+
+{% endblock content %}
+
+
+{% block js %}
+
+
+
+{% endblock js %}
diff --git a/payments/templates/payments/paypal.html b/payments/templates/payments/paypal.html
new file mode 100644
index 0000000..bb0e0d2
--- /dev/null
+++ b/payments/templates/payments/paypal.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Donate for a great cause. Be a hero.
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/payments/templates/payments/stripe.html b/payments/templates/payments/stripe.html
new file mode 100644
index 0000000..0cab5a5
--- /dev/null
+++ b/payments/templates/payments/stripe.html
@@ -0,0 +1,16 @@
+{% extends 'base.html' %}
+{% block title %}Stripe{% endblock title %}
+{% load static %}
+
+{% block header %}
+
+{% endblock %}
+
+{% block content %}
+
+
+ Stripe
+
+
+
+{% endblock content %}
diff --git a/payments/templates/payments/thank_you.html b/payments/templates/payments/thank_you.html
new file mode 100644
index 0000000..3e7a242
--- /dev/null
+++ b/payments/templates/payments/thank_you.html
@@ -0,0 +1,9 @@
+{% extends 'base.html' %}
+{% block title %}Thank you{% endblock title %}
+{% load static %}
+
+{% block content %}
+
+
Thank you
+
+{% endblock content %}
diff --git a/payments/tests.py b/payments/tests.py
new file mode 100644
index 0000000..7ce503c
--- /dev/null
+++ b/payments/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/payments/urls.py b/payments/urls.py
new file mode 100644
index 0000000..1011296
--- /dev/null
+++ b/payments/urls.py
@@ -0,0 +1,18 @@
+from django.urls import path
+from . import views
+
+urlpatterns = [
+ # path('gateways/', views.payment_gateways, name="gateways"),
+
+ path('paypal/', views.payment_paypal, name="paypal"),
+ path('stripe/', views.payment_stripe, name="stripe"),
+ path('coinbase/', views.payment_coinbase, name="coinbase"),
+ path('paylike/', views.payment_paylike, name="paylike"),
+
+ # path('charge/', views.charge, name="charge"),
+ path('thank_you/', views.thank_you, name="thank_you"),
+
+
+ path('charge/', views.charge, name='charge'), # new
+ path('', views.PaymentGetwaysView.as_view(), name='home_'),
+]
diff --git a/payments/views.py b/payments/views.py
new file mode 100644
index 0000000..ac32b33
--- /dev/null
+++ b/payments/views.py
@@ -0,0 +1,74 @@
+from django.shortcuts import render
+from django.conf import settings
+import stripe
+
+stripe.api_key = settings.STRIPE_SECRET_KEY
+# stripe.ApplePayDomain.create(
+# domain_name='example.com',
+# )
+
+# def payment_gateways(request):
+# print(settings.STRIPE_PUBLISHABLE_KEY)
+# context = {
+# 'key': settings.STRIPE_PUBLISHABLE_KEY
+# }
+# return render(request, 'payments/payment_gateways.html', context)
+
+
+def payment_paypal(request):
+ return render(request, 'payments/paypal.html', context={})
+
+
+def payment_stripe(request):
+ return render(request, 'payments/stripe.html', context={})
+
+
+def payment_coinbase(request):
+ return render(request, 'payments/coinbase.html', context={})
+
+
+def payment_paylike(request):
+ return render(request, 'payments/paylike.html', context={})
+
+
+def thank_you(request):
+ return render(request, 'payments/thank_you.html', context={})
+
+
+# def charge(request):
+# if request.method == 'POST':
+# charge = stripe.Charge.create(
+# amount=500,
+# currency='eur',
+# description='Payment GetWays',
+# source=request.POST['stripeToken']
+# )
+# return render(request, 'payments/charge.html')
+
+
+
+
+
+from django.views.generic.base import TemplateView
+
+class PaymentGetwaysView(TemplateView):
+ template_name = 'payments/payment_gateways.html'
+
+ def get_context_data(self, **kwargs): # new
+ context = super().get_context_data(**kwargs)
+ context['key'] = settings.STRIPE_PUBLISHABLE_KEY
+ context['amount'] = 500
+ context['description'] = "Stripe Payment"
+ return context
+
+
+
+def charge(request): # new
+ if request.method == 'POST':
+ charge = stripe.Charge.create(
+ amount=500,
+ currency='usd',
+ description='A Django charge',
+ source=request.POST['stripeToken']
+ )
+ return render(request, 'payments/charge.html')
diff --git a/payments/views_stripe.py b/payments/views_stripe.py
new file mode 100644
index 0000000..b482cdd
--- /dev/null
+++ b/payments/views_stripe.py
@@ -0,0 +1,88 @@
+# #! /usr/bin/env python3.6
+
+# """
+# server.py
+# Stripe Sample.
+# Python 3.6 or newer required.
+# """
+
+# import stripe
+# import json
+# import os
+
+# from flask import Flask, render_template, jsonify, request, send_from_directory
+# from dotenv import load_dotenv, find_dotenv
+
+# # Setup Stripe python client library
+# load_dotenv(find_dotenv())
+# stripe.api_key = os.getenv('STRIPE_SECRET_KEY')
+# stripe.api_version = os.getenv('STRIPE_API_VERSION')
+
+# static_dir = str(os.path.abspath(os.path.join(__file__ , "..", os.getenv("STATIC_DIR"))))
+# app = Flask(__name__, static_folder=static_dir,
+# static_url_path="", template_folder=static_dir)
+
+
+# @app.route('/checkout', methods=['GET'])
+# def get_checkout_page():
+# # Display checkout page
+# return render_template('index.html')
+
+
+# def calculate_order_amount(items):
+# # Replace this constant with a calculation of the order's amount
+# # Calculate the order total on the server to prevent
+# # people from directly manipulating the amount on the client
+# return 1400
+
+
+# @app.route('/create-payment-intent', methods=['POST'])
+# def create_payment():
+# data = json.loads(request.data)
+# # Create a PaymentIntent with the order amount and currency
+# intent = stripe.PaymentIntent.create(
+# amount=calculate_order_amount(data['items']),
+# currency=data['currency']
+# )
+
+# try:
+# # Send publishable key and PaymentIntent details to client
+# return jsonify({'publishableKey': os.getenv('STRIPE_PUBLISHABLE_KEY'), 'clientSecret': intent.client_secret})
+# except Exception as e:
+# return jsonify(error=str(e)), 403
+
+
+# @app.route('/webhook', methods=['POST'])
+# def webhook_received():
+# # You can use webhooks to receive information about asynchronous payment events.
+# # For more about our webhook events check out https://stripe.com/docs/webhooks.
+# webhook_secret = os.getenv('STRIPE_WEBHOOK_SECRET')
+# request_data = json.loads(request.data)
+
+# if webhook_secret:
+# # Retrieve the event by verifying the signature using the raw body and secret if webhook signing is configured.
+# signature = request.headers.get('stripe-signature')
+# try:
+# event = stripe.Webhook.construct_event(
+# payload=request.data, sig_header=signature, secret=webhook_secret)
+# data = event['data']
+# except Exception as e:
+# return e
+# # Get the type of webhook event sent - used to check the status of PaymentIntents.
+# event_type = event['type']
+# else:
+# data = request_data['data']
+# event_type = request_data['type']
+# data_object = data['object']
+
+# if event_type == 'payment_intent.succeeded':
+# print('💰 Payment received!')
+# # Fulfill any orders, e-mail receipts, etc
+# # To cancel the payment you will need to issue a Refund (https://stripe.com/docs/api/refunds)
+# elif event_type == 'payment_intent.payment_failed':
+# print('❌ Payment failed.')
+# return jsonify({'status': 'success'})
+
+
+# if __name__ == '__main__':
+# app.run()
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
index 080b53d..83be0e0 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -18,6 +18,8 @@
+
+ {% block header %}{% endblock %}