def cart_detail(request): cart = Cart(request) if request.method == 'POST': form = CheckoutForm(request.POST) if form.is_valid(): stripe.api_key = settings.STRIPE_SECRET_KEY stripe_token = form.cleaned_data['stripe_token'] try: charge = stripe.Charge.create(amount=int( cart.get_total_cost() * 100), currency='USD', description='Charge from Event', source=stripe_token) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] address = form.cleaned_data['address'] zipcode = form.cleaned_data['zipcode'] place = form.cleaned_data['place'] order = checkout(request, first_name, last_name, email, address, zipcode, place, phone, cart.get_total_cost()) cart.clear() notify_customer(order) notify_coordinator(order) return redirect('success') except Exception: messages.error(request, 'There was something wrong with the payment') else: form = CheckoutForm() remove_from_cart = request.GET.get('remove_from_cart', '') change_quantity = request.GET.get('change_quantity', '') quantity = request.GET.get('quantity', 0) if remove_from_cart: cart.remove(remove_from_cart) return redirect('cart') if change_quantity: cart.add(change_quantity, quantity, True) return redirect('cart') return render(request, 'cart/cart.html', { 'form': form, 'stripe_pub_key': settings.STRIPE_PUB_KEY })
def cart_detail(request): cart = Cart(request) if request.method == 'POST': form = CheckoutForm(request.POST) if form.is_valid(): stripe_token = form.cleaned_data['stripe_token'] try: stripe_charge.delay(int(cart.get_total_cost() * 100), stripe_token) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] address = form.cleaned_data['address'] zipcode = form.cleaned_data['zipcode'] place = form.cleaned_data['place'] order = checkout(request, first_name, last_name, email, address, zipcode, place, phone, cart.get_total_cost()) cart.clear() notify_vendor_and_customer.delay(order.id) except Exception: messages.error(request, 'There was something wrong with payment') return redirect('success') else: form = CheckoutForm() remove_from_cart = request.GET.get('remove_from_cart', '') change_quantity = request.GET.get('change_quantity', '') quantity = request.GET.get('quantity', '') if remove_from_cart: cart.remove(remove_from_cart) return redirect('cart') if change_quantity: cart.add(change_quantity, quantity, True) return redirect('cart') if remove_from_cart: cart.remove(remove_from_cart) return redirect('cart') return render(request, 'cart/cart.html', {'form': form, 'stripe_pub_key': settings.STRIPE_PUB_KEY})
def cart_detail(request): cart = Cart(request) if request.method == 'POST': try: order = Order.objects.get(vendor=request.user.vendor) form = CheckoutForm(request.POST) if form.is_valid(): stripe.api_key = settings.STRIPE_SECRET_KEY stripe_token = form.cleaned_data['stripe_token'] charge = stripe.Charge.create( amount=int(cart.get_total_price() * 100), currency='USD', description='Charge from Ecohub Electronics', source=stripe_token) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] address = form.cleaned_data['address'] city = form.cleaned_data['city'] postal_code = form.cleaned_data['postal_code'] same_billing_addres = form.cleaned_data['same_billing_addres'] save_info = form.cleaned_data['save_info'] billing_addres = BillingAdress( user=request.user, email=email, address=address, city=city, postal_code=postal_code) billing_addres.save() order = checkout(request, first_name, last_name, email, phone, address, city, postal_code, cart.get_total_price) order.billing_addres = billing_addres order.save() print(form.cleaned_data) cart.clear() return redirect('success') messages.info(request, 'Your do not have any active orders') except ObjectDoesNotExist: messages.warning(request, 'Checkout Failed') return redirect('cart') else: form = CheckoutForm() cupon_apply_form = CuponApllyForm() return render(request, 'cart/checkout-page.html', {'form': form, 'stripe_pub_key': settings.STRIPE_PUB_KEY})
def cart_detail(request): cart = Cart(request) if request.method == 'POST': form = CheckoutForm(request.POST) if form.is_valid(): stripe.api_key = settings.STRIPE_SECRET_KEY stripe_token = form.cleaned_data['stripe_token'] try: charge = stripe.Charge.create( amount=int(cart.get_total_cost() * 100), currency='USD', description='Charge from Interiorshop', source=stripe_token) first_name = form.cleaned_data['first_name'] last_name = form.cleaned_data['last_name'] email = form.cleaned_data['email'] phone = form.cleaned_data['phone'] address = form.cleaned_data['address'] postal_code = form.cleaned_data['postal_code'] city = form.cleaned_data['city'] order = checkout(request, first_name, last_name, email, address, postal_code, city, phone, cart.get_total_cost()) cart.clear() notify_customer(order) notify_vendor(order) return redirect('success') except Exception: messages.error(request, 'There was something wrong with the payment') else: form = CheckoutForm() return render(request, 'cart/checkout-page.html', { 'form': form, 'stripe_pub_key': settings.STRIPE_PUB_KEY })