BO 1.35+2 webhook payment
This commit is contained in:
parent
636d505564
commit
a7e0aecf6e
@ -2,7 +2,6 @@ from django.db import models
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from ..models.sports import Sport
|
from ..models.sports import Sport
|
||||||
from ..models.exercises import Exercises
|
|
||||||
|
|
||||||
class Customer(models.Model):
|
class Customer(models.Model):
|
||||||
customer_id = models.BigAutoField(primary_key=True)
|
customer_id = models.BigAutoField(primary_key=True)
|
||||||
|
@ -2,12 +2,12 @@ from django.db import models
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class ProductTypes(models.TextChoices):
|
|
||||||
SUBS = "subscription"
|
|
||||||
IN_APP_CURR = "in-app-currency"
|
|
||||||
|
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model):
|
||||||
|
class ProductTypes(models.TextChoices):
|
||||||
|
SUBS = "subscription"
|
||||||
|
IN_APP_CURR = "in-app-currency"
|
||||||
|
WEB = "web"
|
||||||
|
|
||||||
product_id = models.AutoField(primary_key=True)
|
product_id = models.AutoField(primary_key=True)
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
description = models.TextField(max_length=1000, blank=True, null=True)
|
description = models.TextField(max_length=1000, blank=True, null=True)
|
||||||
@ -18,11 +18,13 @@ class Product(models.Model):
|
|||||||
product_id_android = models.CharField(max_length=50, blank=True, null=True)
|
product_id_android = models.CharField(max_length=50, blank=True, null=True)
|
||||||
price_ios = models.DecimalField(max_length=12, decimal_places=2, max_digits=12, blank=True)
|
price_ios = models.DecimalField(max_length=12, decimal_places=2, max_digits=12, blank=True)
|
||||||
price_android = models.DecimalField(max_length=12, decimal_places=2, max_digits=12, blank=True)
|
price_android = models.DecimalField(max_length=12, decimal_places=2, max_digits=12, blank=True)
|
||||||
|
price_web = models.DecimalField(max_length=12, decimal_places=2, max_digits=12, blank=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'product'
|
db_table = 'product'
|
||||||
verbose_name = _("Product")
|
verbose_name = _("Product")
|
||||||
verbose_name_plural = _("Products")
|
verbose_name_plural = _("Products")
|
||||||
|
app_label = 'controlling'
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@ -35,8 +37,12 @@ class Purchase(models.Model):
|
|||||||
date_add = models.DateField(blank=True, null=True)
|
date_add = models.DateField(blank=True, null=True)
|
||||||
purchase_sum = models.DecimalField(decimal_places=2, max_digits=7)
|
purchase_sum = models.DecimalField(decimal_places=2, max_digits=7)
|
||||||
currency = models.CharField(max_length=3)
|
currency = models.CharField(max_length=3)
|
||||||
|
expiring = models.DateField(blank=True, null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = 'purchase'
|
db_table = 'purchase'
|
||||||
verbose_name = _("Purchase")
|
verbose_name = _("Purchase")
|
||||||
verbose_name_plural = _("Purchases")
|
verbose_name_plural = _("Purchases")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
@ -1,8 +1,55 @@
|
|||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from datetime import date, timedelta, datetime
|
||||||
|
import pytz
|
||||||
|
|
||||||
|
SETTING = os.environ['WORKOUTTEST_SETTING']
|
||||||
|
if SETTING == "PROD":
|
||||||
|
from aitrainer_backoffice.aitrainer_backoffice.models.customer import Customer
|
||||||
|
from aitrainer_backoffice.aitrainer_backoffice.models.product import Product, Purchase
|
||||||
|
else:
|
||||||
|
from aitrainer_backoffice.models.customer import Customer
|
||||||
|
from aitrainer_backoffice.models.product import Product, Purchase
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def webhook(request):
|
def webhook(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
print("Data received from Webhook is: ", request.body)
|
print("Data received from Webhook is: ", request.body)
|
||||||
return HttpResponse("Webhook received!")
|
json_object = json.loads(request.body)
|
||||||
|
|
||||||
|
if ( json_object['status'] == True ):
|
||||||
|
qs_customer = Customer.objects.filter(email = json_object['email'])
|
||||||
|
if ( qs_customer.count() > 0):
|
||||||
|
qs_product = Product.objects.filter(price_web = json_object['price'])
|
||||||
|
|
||||||
|
today = date.today()
|
||||||
|
cet = pytz.timezone('Europe/Budapest')
|
||||||
|
|
||||||
|
customer_id = qs_customer[0].customer_id
|
||||||
|
|
||||||
|
for product in qs_product:
|
||||||
|
|
||||||
|
|
||||||
|
expiring = date.today() + timedelta(days=1095)
|
||||||
|
if ( json_object['price'] == 26970):
|
||||||
|
qs_purchase = Purchase.objects.filter(customer_id = customer_id, product_id =product.pk)
|
||||||
|
if ( qs_purchase.count() < 2 ):
|
||||||
|
expiring = date.today() + timedelta(days=30)
|
||||||
|
|
||||||
|
print("insert purchase: " + product.name + " exp: " + str(expiring))
|
||||||
|
purchase = Purchase(
|
||||||
|
customer_id = qs_customer[0].customer_id,
|
||||||
|
product_id = product.pk,
|
||||||
|
date_add = datetime.now(tz=cet),
|
||||||
|
purchase_sum = product.price_web,
|
||||||
|
currency = "HUF",
|
||||||
|
expiring = expiring
|
||||||
|
)
|
||||||
|
purchase.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return HttpResponse("OK")
|
Loading…
Reference in New Issue
Block a user