diff options
author | shivam kohli <kohlishivam5522@gmail.com> | 2018-06-11 23:06:03 +0530 |
---|---|---|
committer | shivam kohli <kohlishivam5522@gmail.com> | 2018-06-11 23:06:03 +0530 |
commit | 8a0092f6d68dc8f1ad5b27db46e060b9d48b5371 (patch) | |
tree | bbe0446572086133a2cc3e76ec2e1897a397be71 /inventory | |
parent | abafd12b235e4c10c410e0bf3a981d969ab3fd94 (diff) | |
download | codeless-8a0092f6d68dc8f1ad5b27db46e060b9d48b5371.tar.gz codeless-8a0092f6d68dc8f1ad5b27db46e060b9d48b5371.tar.bz2 codeless-8a0092f6d68dc8f1ad5b27db46e060b9d48b5371.zip |
basic payment using taler implemented
Diffstat (limited to 'inventory')
-rw-r--r-- | inventory/migrations/0002_auto_20180607_1714.py | 29 | ||||
-rw-r--r-- | inventory/models.py | 1 | ||||
-rw-r--r-- | inventory/views.py | 58 |
3 files changed, 85 insertions, 3 deletions
diff --git a/inventory/migrations/0002_auto_20180607_1714.py b/inventory/migrations/0002_auto_20180607_1714.py new file mode 100644 index 0000000..600d07c --- /dev/null +++ b/inventory/migrations/0002_auto_20180607_1714.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('inventory', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='paymentbutton', + name='product', + field=models.ForeignKey(null=True, to='inventory.Product'), + ), + migrations.AlterField( + model_name='merchant', + name='pay_url', + field=models.URLField(max_length=250, default='NULL'), + ), + migrations.AlterField( + model_name='order', + name='fulfillment_url', + field=models.URLField(default='NULL'), + ), + ] diff --git a/inventory/models.py b/inventory/models.py index 21ba7fa..aa8b848 100644 --- a/inventory/models.py +++ b/inventory/models.py @@ -90,6 +90,7 @@ class Purchase(models.Model): class PaymentButton(models.Model): """ Design pattern for the payment button are stored in this table. """ + product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True) text = models.CharField(max_length=100, blank=True, null=True) font_size = models.CharField(max_length=50, blank=True, null=True) color = models.CharField(max_length=50, blank=True, null=True) diff --git a/inventory/views.py b/inventory/views.py index 157bf35..a03bf8e 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -11,6 +11,36 @@ from django.shortcuts import get_object_or_404 from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect from django.core.urlresolvers import resolve +import requests + + +def test(request): + return render(request, 'inventory/test.html') + + +def payment(request): + # Creating an Order for a Payment + order = dict(order=dict(amount="KUDOS:1", + summary="test for codeless", + instance="default", + extra=dict(article_name="test article"), + fulfillment_url="https://example.com/thanks.html")) + order_resp = requests.post("https://backend.demo.taler.net/order", + json=order, + headers={"Authorization": "ApiKey sandbox"}) + order_resp = order_resp.json() + order_id = order_resp["order_id"] + # Checking Payment Status and Prompting for Payment + r = requests.get("https://backend.demo.taler.net/check-payment", + params=dict(order_id=order_resp["order_id"]), + headers={"Authorization": "ApiKey sandbox"}) + pay_url = r.json()["payment_redirect_url"] + return redirect(pay_url) + + +def update_inventory(name, quantity): + product_instance = Product.objects.get(name=name) + product_instance.inventory_on_hand = product_instance.inventory_on_hand - quantity @login_required @@ -24,7 +54,7 @@ def home(request): data['name'] = i.name data['description'] = i.description data['price'] = i.price - data['inventory_on_hand'] = i.starting_inventory + data['inventory_on_hand'] = i.inventory_on_hand data['url'] = '/home/product/' + str(i.product_id) array.append(data) context_dict['data'] = array @@ -32,6 +62,21 @@ def home(request): @login_required +def update_stock(request, uid): + product_instance = Product.objects.get(name=uid) + product_instance.inventory_on_hand = request.POST.get('stock_updated') + product_instance.save() + product_instance = Product.objects.get(name=uid) + context_dict = {} + context_dict['name'] = product_instance.name + context_dict['description'] = product_instance.description + context_dict['price'] = product_instance.price + context_dict['inventory_on_hand'] = product_instance.inventory_on_hand + context_dict['url_update_inventory'] = str('/update_stock/') + product_instance.name + return render(request, 'inventory/product.html', context_dict) + + +@login_required def add_product(request): name = request.POST.get('name') product_instance = Product.objects.get_or_create(name=name)[0] @@ -41,6 +86,7 @@ def add_product(request): product_instance.price = price starting_inventory = request.POST.get('starting_inventory') product_instance.starting_inventory = starting_inventory + product_instance.inventory_on_hand = starting_inventory minimum_required = request.POST.get('minimum_required') product_instance.minimum_required = minimum_required user_instance = User.objects.get(username=request.user.username) @@ -54,7 +100,7 @@ def add_product(request): data['name'] = i.name data['description'] = i.description data['price'] = i.price - data['inventory_on_hand'] = i.starting_inventory + data['inventory_on_hand'] = i.inventory_on_hand data['url'] = '/home/product/' + str(i.product_id) array.append(data) context_dict['data'] = array @@ -68,11 +114,17 @@ def product(request, uid): context_dict['name'] = product_instance.name context_dict['description'] = product_instance.description context_dict['price'] = product_instance.price - context_dict['inventory_on_hand'] = product_instance.starting_inventory + context_dict['inventory_on_hand'] = product_instance.inventory_on_hand + context_dict['url_update_inventory'] = str('/update_stock/') + product_instance.name return render(request, 'inventory/product.html', context_dict) @login_required +def customize_payment_button(request): + return render(request, 'inventory/new_product.html') + + +@login_required def new_product(request): return render(request, 'inventory/new_product.html') |