def purchase(request, product_id): if request.method == 'POST': form = PurchaseForm(request.POST) if form.is_valid(): url = "https://careers.undercovertourist.com/assignment/1/products/" + product_id + "/purchase" data = { "customer_email": form.cleaned_data['customer_email'], "customer_name": form.cleaned_data['customer_name'], "customer_phone": form.cleaned_data['customer_phone'], "quantity": form.cleaned_data['quantity'] } fail_context = { 'quantity': form.cleaned_data['quantity'], 'inventory': get_quantity(product_id) } if form.cleaned_data['quantity'] > get_quantity(product_id): return render(request, 'undercovertourist_app/Fail.html', fail_context) result = requests.post(url, data=data, headers=headers) print result.json() product = get_productdetails(product_id) customerpurchase = Customer_purchasedata( customer_email=form.cleaned_data['customer_email'], customer_name=form.cleaned_data['customer_name'], customer_phone=form.cleaned_data['customer_phone'], product_name=product['name'], product_price=product['price'], quantity=form.cleaned_data['quantity'], confirmation_code=result.json()['confirmation_code'], product_id=product_id) customerpurchase.save() success_result = result.json() print success_result['confirmation_code'] print success_result['product']['name'] success_context = { 'confirmation_code': success_result['confirmation_code'], 'product': success_result['product']['name'] } return render(request, 'undercovertourist_app/success.html', success_context) else: form = PurchaseForm(initial={'item_id': product_id}) return render(request, 'undercovertourist_app/purchase.html', {'form': form})
def product(request, product_id): prod = get_object_or_404(Product, pk=product_id) if request.method == 'POST': form = PurchaseForm(request.POST) if form.is_valid(): Purchase.objects.create(cart=Cart.get(request), product=prod, quantity=form.cleaned_data['quantity']) messages.success(request, _('Your purchase was successfully added to the Cart')) else: form = PurchaseForm(initial={'quantity': 1}) return render(request, 'shopping_cart/product.html', { 'product': prod, 'form': form })
def order_submit(): purchase_form = PurchaseForm() #TODO: save cc form if purchase_form.submit.data == True: return redirect('https://www.paypal.com/cgi-bin/webscr') content = render_template('order.html', purchase_form=purchase_form) return content
def purchase(): form = PurchaseForm() oracle_connection_string = 'oracle+cx_oracle://{username}:{password}@{host}:{port}/{sid}' engine = create_engine(oracle_connection_string.format( username="******", password="******", sid="XE", host="localhost", port="1521", database="XE", ), echo=True) with engine.connect() as conn: global event_name event_name = re.search(r"[a-zA-z0-9]+", event_name).group(0) price = conn.execute( "SELECT PRICE FROM EVENTS WHERE EVENT_NAME = '" + event_name + "'").fetchone() form.price.label = "price: " + str(price[0]) tickets_left = conn.execute( "SELECT QUANTITY_TIC FROM EVENTS WHERE EVENT_NAME = '" + event_name + "'").fetchone() form.tickets_left.label = "tickets left: " + str(tickets_left[0]) global event_time event_time = conn.execute( "SELECT EVENT_TIME FROM EVENTS WHERE EVENT_NAME = '" + event_name + "'").fetchone() form.event_time.label = "event time: " + str(event_time[0]) if form.is_submitted(): try: int_tickets_left = tickets_left[0] - 1 with engine.connect() as conn: global client_phone conn.execute( "INSERT INTO GUESTS(client_phone, event_name, event_time) VALUES('" + str( client_phone) + "', '" + str( event_name) + "', " + "TO_DATE('" + str(event_time[0]) + "', 'YYYY-MM-DD HH24:MI:SS'))") conn.execute("UPDATE events SET quantity_tic = " + str(int_tickets_left) + " WHERE event_name = '" + event_name + "'") global candidate global chats chats.append(candidate) return redirect(url_for('success')) except Exception: return redirect(url_for("select_event")) return render_template('purchase.html', form=form)
def return_product_details(product_id): """This isnt actually purchasing a product. This is just notifying the website owner that a customer wants to purchase a product or has questions about a product.""" form = PurchaseForm() if form.validate_on_submit(): request = Request.form_to_model(form) email = [] email.append(request.email) result = '' try: send_email(request.message) except: print( 'GOOGLE ACCOUNT SETTINGS FOR LESS SECURE APP SHOULD BE ENABLED' ) print('GOOGLE ACCOUNT SETTINGS THE DEVICE SHOULD VERIFIED FOR USE') result = send_confirmation(email) print(result) if result == 535: print( 'GOOGLE ACCOUNT SETTINGS FOR LESS SECURE APP SHOULD BE ENABLED' ) print('GOOGLE ACCOUNT SETTINGS THE DEVICE SHOULD VERIFIED FOR USE') elif result == False: flash('Error. Invalid email address.', 'danger') return redirect(f'/products/{product_id}') #request = Request(email=form.email.data, message=message, firstname=firstname, lastname=lastname, product=product_id) db.session.add(request) db.session.commit() return redirect(f'/request/{product_id}') product = Product.query.get(product_id) #need to convert an image for html to display product.prepare_to_show() product.available = 'Available' form.product_id.data = product.id return render_template('product.html', product=product, form=form)
def order(): purchase_form = PurchaseForm() content = render_template('order.html', purchase_form=purchase_form) return content
if purchase_form.submit.data == True: return redirect('https://www.paypal.com/cgi-bin/webscr') content = render_template('order.html', purchase_form=purchase_form) return content @app.route('/payment') @app.route('/payment') def payment(): <<<<<<< Updated upstream content = index() content += " payment page" ======= #content = index() #content += " payment page" purchase_form = PurchaseForm() content = render_template('payment.html', purchase_form=purchase_form) <<<<<<< Updated upstream <<<<<<< Updated upstream <<<<<<< Updated upstream >>>>>>> Stashed changes ======= >>>>>>> Stashed changes ======= >>>>>>> Stashed changes ======= >>>>>>> Stashed changes return content @app.route('/payment/<method>', defaults={'method': 'paypal'})