Example #1
0
def update_transaction_records(request, token):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)

    # update the placed order
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              token=token,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    # send an email to the customer
    # look at tutorial on how to send emails with sendgrid
    messages.info(request, "Спасибо! Покупка успешно совершена!")
    return redirect(reverse('accounts:my_profile'))
Example #2
0
def update_transaction_records(request, id):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)

    # update the placed order
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_schedules = [item.schedule for item in order_items]
    user_profile.schedules.add(*order_schedules)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              token=id,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    # send an email to the customer
    # look at tutorial on how to send emails with sendgrid
    messages.info(request, "Thank you! Your purchase was successful!")
    return redirect(reverse('shopping_cart:purchase_success'))
Example #3
0
def update_transaction_records(request, token):
    order_to_purchase = get_user_pending_order(request)

    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    order_items = order_to_purchase.items.all()

    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    user_profile = get_object_or_404(Profile, user=request.user)
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              token=token,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    messages.info(request, "Dziękujmy, zakup zakończył się sukcesem!")
    return redirect(reverse('accounts:my_profile'))
def update_transaction_records(request, token):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)

    # update the placed order
    order_to_purchase.is_ordered=True
    order_to_purchase.date_ordered=datetime.datetime.now()
    order_to_purchase.save()
    
    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # add products to user cart
    user_cart = get_object_or_404(Cart, user=request.user)
    # get the products from the items
    order_products = [item.item for item in order_items]
    user_cart.item.add(*order_products)
    user_cart.save()

    # create a transaction
    transaction = Transaction(cart=request.user.cart, token=token, order_id=order_to_purchase.id, amount=order_to_purchase.get_cart_total(), success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    # send an email to the customer
    # look at tutorial on how to send emails with sendgrid
    messages.success(request, "Thank you! Your purchase was successful!")
    return redirect(reverse('orders-history'))
Example #5
0
def update_transaction_records(request, token):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)

    # update the placed order
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              token=token,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transaction
    transaction.save()

    # send an email to the customer
    messages.info(request, "Thank you! Your purchase was successful!")
    return redirect(reverse('accounts:my_profile'))
Example #6
0
def update_transaction_records(request, token):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)

    # update the placed order
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              token=token,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    account_sid = 'AC1279455ea2a384da8534df3da7575fa7'
    auth_token = '9abd9d54605f5096c94fb1d42e9d73ae'
    client = Client(account_sid, auth_token)

    message = client.messages.create(
        from_='whatsapp:+14155238886',
        body='Thank you! Your purchase was successful!',
        to='whatsapp:+919712167265')

    print(message.sid)
    # send an email to the customer
    messages.info(request, "Thank you! Your purchase was successful!")
    return redirect(reverse('accounts:my_profile'))
Example #7
0
def payment_done(request, order_id):  #def payment_done(request, order_id):
    # get the order being processed
    order_to_purchase = get_user_pending_order(
        request
    )  #order_to_purchase = get_user_pending_order(request, id=order_id)

    # update the placed order which calls the UPDATE SQL command in the backend
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items using the update() method
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()
    """ Clear the cart after a successfull transaction """
    order_to_purchase.items.delete(
    )  #Delete the order items after the payment is done form the cart

    # send an email to the customer
    # look at tutorial on how to send emails with sendgrid
    messages.info(request, "Thank you! Your purchase was successful!")
    return render(request, 'shopping_cart/payment_done.html')
Example #8
0
def update_transaction_records(request, order_id):
    # get the order being processed
    order_to_purchase = get_user_pending_order(request)
    print(order_to_purchase)
    # update the placed order which calls the UPDATE SQL command in the backend
    order_to_purchase.is_ordered = True
    order_to_purchase.date_ordered = datetime.datetime.now()
    order_to_purchase.save()

    # get all items in the order - generates a queryset
    order_items = order_to_purchase.items.all()

    # update order items using the update() method
    order_items.update(is_ordered=True, date_ordered=datetime.datetime.now())

    # Add products to user profile
    user_profile = get_object_or_404(Profile, user=request.user)
    # get the products from the items
    order_products = [item.product for item in order_items]
    user_profile.ebooks.add(*order_products)
    user_profile.save()

    # create a transaction
    transaction = Transaction(profile=request.user.profile,
                              order_id=order_to_purchase.id,
                              amount=order_to_purchase.get_cart_total(),
                              success=True)
    # save the transcation (otherwise doesn't exist)
    transaction.save()

    #order_to_purchase.items.clear()

    # send an email to the customer
    # look at tutorial on how to send emails with sendgrid
    messages.info(request, "Thank you! Your purchase was successful!")
    return redirect(
        reverse('products:product_list')
    )  #return a redirect to the users profile with their products they have purchased
Example #9
0
def update_Transaction_history(request):
    list_char = 'abcdefghijklmnopqrstuvxyz1234567890'
    list_char = [letter for letter in list_char]
    ref_code = ''.join([choice(list_char) for i in range(16)])
    user_Profile = get_object_or_404(Profile, user=request.user)
    transaction = Transaction(owner=user_Profile, ref_code=ref_code)
    transaction.save()
    user_items = []
    for item in get_object_or_404(Profile,
                                  user=request.user).inventory.item_set.all():
        f_item = FoodItem.objects.filter(name=item.name).get()
        transaction.items.add(f_item)
        transaction.save()
        update_quanity(quanity=item.quanity, f_item=f_item)
        # id = Transaction.objects.raw('SELECT id FROM shopping_cart_transaction_items where fooditem_id = %s order by id desc limit 1',[f_item.id])[-1].id
        # test = Transaction.objects.raw('update shopping_cart_transaction_items set food_quanity=%s where id=%s',[item.quanity,id])
    transaction.save()
    #print(Transaction.objects.filter(ref_code=ref_code).last().items.all())
    user_Profile.inventory.item_set.all().delete()
    return redirect(reverse('shopping_cart:success'))