gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-codeless] branch master updated: basic payment using


From: gnunet
Subject: [GNUnet-SVN] [taler-codeless] branch master updated: basic payment using taler implemented
Date: Mon, 11 Jun 2018 19:36:34 +0200

This is an automated email from the git hooks/post-receive script.

shivam-kohli pushed a commit to branch master
in repository codeless.

The following commit(s) were added to refs/heads/master by this push:
     new 8a0092f  basic payment using taler implemented
8a0092f is described below

commit 8a0092f6d68dc8f1ad5b27db46e060b9d48b5371
Author: shivam kohli <address@hidden>
AuthorDate: Mon Jun 11 23:06:03 2018 +0530

    basic payment using taler implemented
---
 codeless/urls.py                                |  7 +++
 inventory/migrations/0002_auto_20180607_1714.py | 29 +++++++++++++
 inventory/models.py                             |  1 +
 inventory/views.py                              | 58 +++++++++++++++++++++++--
 templates/inventory/product.html                | 10 ++++-
 templates/inventory/test.html                   | 13 ++++++
 6 files changed, 113 insertions(+), 5 deletions(-)

diff --git a/codeless/urls.py b/codeless/urls.py
index 8b25655..ed84a5d 100644
--- a/codeless/urls.py
+++ b/codeless/urls.py
@@ -8,12 +8,19 @@ urlpatterns = [
     # url(r'^blog/', include('blog.urls')),
 
     url(r'^admin/', include(admin.site.urls)),
+    url(r'^test/$', 'inventory.views.test', name='test'),
+    url(r'^payment/$', 'inventory.views.payment', name='payment'),
     url(r'^signup/$', 'inventory.views.signup', name='signup'),
     url(r'^new_product/$', 'inventory.views.new_product', name='new_product'),
     url(r'^add_product/$', 'inventory.views.add_product', name='add_product'),
+    url(r'^update_stock/(?P<uid>[\*\w\-]+)$',
+        'inventory.views.update_stock', name='update_stock'),
     url(r'^home/product/(?P<uid>[\*\w\-]+)$',
         'inventory.views.product', name='product'),
     url(r'^home/$', 'inventory.views.home', name='home'),
+    url(r'^customize_payment_button/$',
+        'inventory.views.customize_payment_button',
+        name='customize_payment_button'),
     url(r'^accounts/login/$', 'inventory.views.login', name='login'),
     url(r'^logout/$', 'inventory.views.logout', name='logout'),
     url(r'^password_reset/$', auth_views.password_reset,
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)
+
+
address@hidden
 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')
+
+
address@hidden
 def new_product(request):
     return render(request, 'inventory/new_product.html')
 
diff --git a/templates/inventory/product.html b/templates/inventory/product.html
index 18fb381..a665876 100644
--- a/templates/inventory/product.html
+++ b/templates/inventory/product.html
@@ -64,12 +64,18 @@
 
 <div class="main">
     <center>
-        <h1 style="text-transform: uppercase;">{{ name }}</h1>
+        <h1 style="text-transform: uppercase;" id="name">{{ name }}</h1>
     </center>
 
     <h5 color="black">Description:</h5><h6>{{ description }}</h6><br>
     <h5 color="black">Price:</h5><h6>{{ price }}</h6><br>
-    <h5 color="black">Inventory on Hand:</h5><h6>{{ inventory_on_hand 
}}</h6><br>
+    <h5 color="black">The Cuurent Inventory on Hand is:- {{ inventory_on_hand 
}}</h5>
+
+    <form name="update_stock" action="{{ url_update_inventory }}" 
method="post" enctype="multipart/form-data">
+        {% csrf_token %}
+        <input type="number" name="stock_updated" id="stock_updated" 
placeholder="Update Stock" required>
+        <button name="update_stock" type="submit" 
class="submit">Update</button>
+    </form>
 
 </div>
 
diff --git a/templates/inventory/test.html b/templates/inventory/test.html
new file mode 100644
index 0000000..d9db3b0
--- /dev/null
+++ b/templates/inventory/test.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+<head>
+       <title></title>
+</head>
+<body>
+make payment
+<form name="Payment" action="/payment/" method="post" 
enctype="multipart/form-data">
+    {% csrf_token %}
+    <button name="Payment" type="submit" class="submit">Payment</button>
+</form>
+</body>
+</html>
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]