Skip to content

Commit

Permalink
add basic payment settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Re-Krass committed Jun 20, 2018
1 parent 0127e65 commit 4b2a691
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 35 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ django-cors-headers = "*"
gunicorn = "*"
django-rest-swagger = "*"
"django-sendgrid-v5" = "*"
django-payments = "*"

[dev-packages]
pylint = "*"
Expand Down
112 changes: 111 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions ydl_api/api/migrations/0005_auto_20180621_0005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 2.0.6 on 2018-06-20 22:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0004_auto_20180620_1443'),
]

operations = [
migrations.CreateModel(
name='Payment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('variant', models.CharField(max_length=255)),
('status', models.CharField(choices=[('waiting', 'Waiting for confirmation'), ('preauth', 'Pre-authorized'), ('confirmed', 'Confirmed'), ('rejected', 'Rejected'), ('refunded', 'Refunded'), ('error', 'Error'), ('input', 'Input')], default='waiting', max_length=10)),
('fraud_status', models.CharField(choices=[('unknown', 'Unknown'), ('accept', 'Passed'), ('reject', 'Rejected'), ('review', 'Review')], default='unknown', max_length=10, verbose_name='fraud check')),
('fraud_message', models.TextField(blank=True, default='')),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('transaction_id', models.CharField(blank=True, max_length=255)),
('currency', models.CharField(max_length=10)),
('total', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('delivery', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('tax', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('description', models.TextField(blank=True, default='')),
('billing_first_name', models.CharField(blank=True, max_length=256)),
('billing_last_name', models.CharField(blank=True, max_length=256)),
('billing_address_1', models.CharField(blank=True, max_length=256)),
('billing_address_2', models.CharField(blank=True, max_length=256)),
('billing_city', models.CharField(blank=True, max_length=256)),
('billing_postcode', models.CharField(blank=True, max_length=256)),
('billing_country_code', models.CharField(blank=True, max_length=2)),
('billing_country_area', models.CharField(blank=True, max_length=256)),
('billing_email', models.EmailField(blank=True, max_length=254)),
('customer_ip_address', models.GenericIPAddressField(blank=True, null=True)),
('extra_data', models.TextField(blank=True, default='')),
('message', models.TextField(blank=True, default='')),
('token', models.CharField(blank=True, default='', max_length=36)),
('captured_amount', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
],
options={
'abstract': False,
},
),
migrations.AddField(
model_name='user',
name='credit',
field=models.DecimalField(decimal_places=2, default=0, max_digits=19),
),
migrations.AlterField(
model_name='calendarentry',
name='date',
field=models.DateTimeField(),
),
]
23 changes: 21 additions & 2 deletions ydl_api/api/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.validators import MinValueValidator
from decimal import Decimal

from payments import PurchasedItem
from payments.models import BasePayment

class Language(models.Model):
name = models.CharField(max_length=100)
Expand All @@ -17,6 +21,7 @@ def upload_to(self, filename):
isEmailActivated = models.BooleanField(default=False)
profile_picture = models.ImageField(upload_to = upload_to, blank=True)
languages = models.ForeignKey(Language, on_delete=models.CASCADE, blank=True, null=True)
credit = models.DecimalField(max_digits=19, decimal_places=2, default=0)

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand All @@ -33,6 +38,7 @@ def __str__(self):
class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
courses = models.ManyToManyField('Course', blank = True)
# paid_courses = models.ManyToManyField('Course', blank = True)

def __str__(self):
return str(self.user)
Expand All @@ -41,7 +47,6 @@ class Meta:
verbose_name = ('student')
verbose_name_plural = ('students')


class Teacher(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)

Expand All @@ -67,7 +72,6 @@ class Meta:
class Course(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=512)
# students = models.ManyToManyField(Student)
teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE)
deadline = models.DateTimeField()
student_count = models.IntegerField(validators=[MinValueValidator(0)], default=0)
Expand All @@ -82,6 +86,8 @@ class Meta:
verbose_name = ('course')
verbose_name_plural = ('courses')

#class PaidCourse(models.Model):


class Announcement(models.Model):
title = models.CharField(max_length=100)
Expand Down Expand Up @@ -140,3 +146,16 @@ class Meta:

def __str__(self):
return self.matter

class Payment(BasePayment):

def get_failure_url(self):
return 'https://ydlearning.com/failure/'

def get_success_url(self):
return 'https://ydlearning.com/success/'

def get_purchased_items(self):
# you'll probably want to retrieve these from an associated order
yield PurchasedItem(name='The Hound of the Baskervilles', sku='BSKV',
quantity=9, price=Decimal(10), currency='USD')
Loading

0 comments on commit 4b2a691

Please sign in to comment.