diff options
author | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-01 21:28:44 +0530 |
---|---|---|
committer | shivam kohli <kohlishivam5522@gmail.com> | 2018-07-01 21:28:44 +0530 |
commit | cd3fdd5d00fe2ce4b49a5cf3577fc7886e2fbf31 (patch) | |
tree | 39468c764c3588ac97db9181b835241136b36285 /inventory | |
parent | 088a3edd1582004cdf1fe791df40041a36f20e0e (diff) | |
download | codeless-cd3fdd5d00fe2ce4b49a5cf3577fc7886e2fbf31.tar.gz codeless-cd3fdd5d00fe2ce4b49a5cf3577fc7886e2fbf31.tar.bz2 codeless-cd3fdd5d00fe2ce4b49a5cf3577fc7886e2fbf31.zip |
added GNU style build and payment button
Diffstat (limited to 'inventory')
-rw-r--r-- | inventory/views.py | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/inventory/views.py b/inventory/views.py index e050a1a..a5919fc 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -19,8 +19,8 @@ import json from django.http import JsonResponse -def test(request): - return render(request, 'inventory/test.html') +def fulfillment(request): + return render(request, 'inventory/fulfillment.html') @csrf_exempt @@ -35,18 +35,40 @@ def pay(request): headers={"Authorization": "ApiKey sandbox"}) if r.status_code != 200: return HttpResponse(r.status_code) + contract_terms = r.json()["contract_terms"] + print(contract_terms['products']) + for i in contract_terms['products']: + update_inventory(i["description"],i["quantity"]) return JsonResponse(r.json()) def payment(request): session_id = request.session.session_key + # merchant_instance = User.objects.get(username=uid) + name = request.GET.get('name') + price = request.GET.get('price') + merchant = request.GET.get('merchant') + summary = name+' purchased from '+merchant + base_url = request.build_absolute_uri().rsplit('/', 1)[0] # Creating an Order for a Payment - order = dict(order=dict(amount="KUDOS:0.1", - summary="codeless", - instance="default", - extra=dict(article_name="test"), - fulfillment_url="https://example.com/thanks.html", - pay_url="http://localhost:8000/payment/pay/", + order = dict(order=dict(amount="KUDOS:"+price, + summary=summary, + products=[ + dict( + description=name, + quantity=1, + product_id=1, + price="KUDOS:"+price, + ), + ], + fulfillment_url=base_url+"/fulfillment/", + pay_url=base_url+"/pay/", + merchant=dict( + address="test", + name=merchant, + jurisdiction="none", + instance="default", + ), ) ) order_resp = backend_post("order", order) @@ -96,6 +118,7 @@ def update_inventory(name, quantity): product_instance = Product.objects.get(name=name) inventory_on_hand = product_instance.inventory_on_hand - quantity product_instance.inventory_on_hand = inventory_on_hand + product_instance.save() @login_required @@ -165,14 +188,18 @@ def add_product(request): @login_required def product(request, uid): - product_instance = Product.objects.get_or_create(product_id=uid)[0] + product = Product.objects.get_or_create(product_id=uid)[0] 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 - url_update_inventory = str('/update_stock/') + product_instance.name + context_dict['name'] = product.name + context_dict['description'] = product.description + context_dict['price'] = product.price + context_dict['inventory_on_hand'] = product.inventory_on_hand + url_update_inventory = str('/update_stock/') + product.name context_dict['url_update_inventory'] = url_update_inventory + base_url = request.build_absolute_uri().rsplit('/', 3)[0] + merchant = request.user.username + parameters = "name="+product.name+'&price='+product.price+'&merchant='+merchant + context_dict['href'] = base_url + "/payment?"+parameters return render(request, 'inventory/product.html', context_dict) |