Skip to content

Commit

Permalink
added django payment checkout using stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Wembo committed Oct 15, 2023
1 parent 285157c commit 2b76761
Show file tree
Hide file tree
Showing 53 changed files with 2,281 additions and 54 deletions.
26 changes: 16 additions & 10 deletions .env
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
SERVER=
DEBUG=True
SECRET_KEY=
DJANGO_SECRET_KEY=
DJANGO_SUPERUSER_PASSWORD=abcde@12345
DJANGO_SUPERUSER_EMAIL=[email protected]
DJANGO_SUPERUSER_USERNAME=joelwembo

DEBUG=True
SECRET_KEY=S3cr3t_K#Key77666345001
SERVER=https://prodxengine.com
DJANGO_SECRET_KEY=%jjnu7=54g6s%qjfnhbpw0zeoei=$!her*y(p%!&84rs$4l85io
ALLOWED_PORTS=0.0.0.0
POSTGRES_NAME=fintech_enterpriseDB
ALLOWED_PORTS=localhost
POSTGRES_NAME=CloudAppDB
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_PORT=5432
# POSTGRES_HOST=localhost
POSTGRES_HOST=host.docker.internal
# POSTGRES_HOST=3.0.55.190
POSTGRES_HOST=localhost
# POSTGRES_HOST=host.docker.internal
# POSTGRES_HOST=3.0.55.190

STRIPE_PUBLISHABLE_KEY=
STRIPE_SECRET_KEY=
BACKEND_DOMAIN=http://127.0.0.1:8585/
PAYMENT_SUCCESS_URL=http://127.0.0.1:8585/api/v1/products/success/
PAYMENT_CANCEL_URL=http://127.0.0.1:8585/api/v1/products/cancel/
STRIPE_WEBHOOK_SECRET=
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- Ansible

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers
python3 -m venv env
python3 -m venv venv

# create a new virtual environemnt
source env/bin/activate # For Windows use env\Scripts\activate
Expand Down
2 changes: 1 addition & 1 deletion apps/finances/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

admin.site.register(Account)
admin.site.register(Transaction)
admin.site.register(Category)
admin.site.register(Category)
28 changes: 28 additions & 0 deletions apps/finances/migrations/0002_restaurant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.4 on 2023-10-05 11:42

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("finances", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Restaurant",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=100)),
("address", models.CharField(max_length=200)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.6 on 2023-10-15 14:14

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("finances", "0002_restaurant"),
]

operations = [
migrations.DeleteModel(
name="Restaurant",
),
migrations.AlterField(
model_name="account",
name="initial_balance",
field=models.DecimalField(decimal_places=2, default=1, max_digits=10),
),
]
53 changes: 51 additions & 2 deletions apps/finances/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
"""
References : https://www.dataquest.io/blog/documenting-in-python-with-docstrings/#:~:text=Docstrings%20explain%20what%20a%20function,want%20to%20use%20the%20code.
Author : Joel Wembo
This is a pure Python implementation of Dynamic Programming solution to the longest
increasing subsequence of a given sequence.
The problem is :
Given an array, to find the longest and increasing sub-array in that given array and
return it.
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return
[10, 22, 33, 41, 60, 80] as output
"""

from datetime import datetime
import uuid
from django.db import models
Expand All @@ -9,8 +23,34 @@
("transfer", "Transfer"),
]

# Coding Documentation standards
# def add_binary(a, b):
# '''
# Returns the sum of two decimal numbers in binary digits.

# Parameters:
# a (int): A decimal integer
# b (int): Another decimal integer

# Returns:
# binary_sum (str): Binary string of the sum of a and b
# '''
# binary_sum = bin(a+b)[2:]
# return binary_sum

# print(add_binary.__doc__)

class Transaction(models.Model):

"""
some explaination of the function
>>> LongestIncreasingSubsequenceLength([2, 5, 3, 7, 11, 8, 10, 13, 6])
6
>>> LongestIncreasingSubsequenceLength([])
0
"""

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
date = models.DateField(default=datetime.now)
amount = models.DecimalField(max_digits=10, decimal_places=2)
Expand All @@ -22,8 +62,16 @@ class Transaction(models.Model):
account = models.ForeignKey(
"Account", on_delete=models.CASCADE, related_name="transactions"
)

"""
Get Timestamps from the user
Return date & time
"""
createdAt = models.DateTimeField(auto_now_add=True)
updatedAt = models.DateTimeField(auto_now_add=True)

# transaction meta
# meta class

class Meta:
db_table = "Transactions"
Expand Down Expand Up @@ -57,7 +105,7 @@ def __str__(self):
class Account(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255)
initial_balance = models.DecimalField(max_digits=10, decimal_places=2, default=0)
initial_balance = models.DecimalField(max_digits=10, decimal_places=2, default=1)
active = models.BooleanField(default=True)
createdAt = models.DateTimeField(auto_now_add=True)
updatedAt = models.DateTimeField(auto_now_add=True)
Expand All @@ -66,4 +114,5 @@ class Meta:
db_table = "Accounts"
ordering = ['-createdAt']
def __str__(self):
return self.name
return self.name

73 changes: 73 additions & 0 deletions apps/finances/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import graphene
from graphene_django import DjangoObjectType
from .models import Account


class AccountType(DjangoObjectType):
class Meta:
model = Account
fields = ("id", "name", "initial_balance", "active")


class Query(graphene.ObjectType):
"""
Queries for the Account model
"""
accounts = graphene.List(AccountType)

def resolve_accounts(self, info, **kwargs):
return Account.objects.all()


class CreateAccount(graphene.Mutation):
class Arguments:
name = graphene.String()
initial_balance = graphene.Float()
active = graphene.Boolean()

ok = graphene.Boolean()
account = graphene.Field(AccountType)

def mutate(self, info, name, initial_balance, active):
account = Account(name=name, initial_balance=initial_balance, active=active)
account.save()
return CreateAccount(ok=True, account=account)

class DeleteAccount(graphene.Mutation):
class Arguments:
id = graphene.Int()

ok = graphene.Boolean()

def mutate(self, info, id):
account = Account.objects.get(id=id)
account.delete()
return DeleteAccount(ok=True)


class UpdateAccount(graphene.Mutation):
class Arguments:
id = graphene.Int()
name = graphene.String()
initial_balance = graphene.Float()
active = graphene.Boolean()

ok = graphene.Boolean()
account = graphene.Field(AccountType)

def mutate(self, info, id, name, initial_balance, active):
account = Account.objects.get(id=id)
account.name = name
account.initial_balance = initial_balance
account.active = active
account.save()
return UpdateAccount(ok=True, account=account)


class Mutation(graphene.ObjectType):
create_Account = CreateAccount.Field()
delete_Account = DeleteAccount.Field()
update_Account = UpdateAccount.Field()


schema = graphene.Schema(query=Query, mutation=Mutation)
74 changes: 74 additions & 0 deletions apps/finances/transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import graphene
from graphene_django import DjangoObjectType
from .models import Transaction


class TransactionType(DjangoObjectType):
class Meta:
model = Transaction
fields = ("id", "date", "amount", "description", "type", "category", "account")



class Query(graphene.ObjectType):
"""
Queries for the Account model
"""
transactions = graphene.List(TransactionType)

def resolve_accounts(self, info, **kwargs):
return Transaction.objects.all()


# class CreateAccount(graphene.Mutation):
# class Arguments:
# name = graphene.String()
# initial_balance = graphene.Float()
# active = graphene.Boolean()

# ok = graphene.Boolean()
# account = graphene.Field(AccountType)

# def mutate(self, info, name, initial_balance, active):
# account = Account(name=name, initial_balance=initial_balance, active=active)
# account.save()
# return CreateAccount(ok=True, account=account)

# class DeleteAccount(graphene.Mutation):
# class Arguments:
# id = graphene.Int()

# ok = graphene.Boolean()

# def mutate(self, info, id):
# account = Account.objects.get(id=id)
# account.delete()
# return DeleteAccount(ok=True)


# class UpdateAccount(graphene.Mutation):
# class Arguments:
# id = graphene.Int()
# name = graphene.String()
# initial_balance = graphene.Float()
# active = graphene.Boolean()

# ok = graphene.Boolean()
# account = graphene.Field(AccountType)

# def mutate(self, info, id, name, initial_balance, active):
# account = Account.objects.get(id=id)
# account.name = name
# account.initial_balance = initial_balance
# account.active = active
# account.save()
# return UpdateAccount(ok=True, account=account)


# class Mutation(graphene.ObjectType):
# create_Account = CreateAccount.Field()
# delete_Account = DeleteAccount.Field()
# update_Account = UpdateAccount.Field()


schema = graphene.Schema(query=Query)
3 changes: 2 additions & 1 deletion apps/finances/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.urls import path
from .views import Accounts , Transactions , Categories , AccountDetail
from . import views


urlpatterns = [
path('apiview', Accounts.as_view()),
path('accounts', Accounts.as_view()),
Expand Down
1 change: 1 addition & 0 deletions apps/finances/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from django.shortcuts import render
import math
from rest_framework import status, viewsets, generics
Expand Down
Empty file added apps/home/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions apps/home/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions apps/home/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class PaymentsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "apps.home"
Empty file.
3 changes: 3 additions & 0 deletions apps/home/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions apps/home/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
5 changes: 5 additions & 0 deletions apps/home/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name = 'home'),
]
8 changes: 8 additions & 0 deletions apps/home/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.shortcuts import render
from django.http import HttpResponse
import requests

# display users
def home(request):
return render(request, "home/index.html")

3 changes: 0 additions & 3 deletions apps/payments/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.db import models

# Create your models here.
Loading

0 comments on commit 2b76761

Please sign in to comment.