def __init__(self, request, paymentmodule, *args, **kwargs): super(SimplePayShipForm, self).__init__(*args, **kwargs) self.tempCart = Cart.objects.get(id=request.session['cart']) self.tempContact = Contact.from_request(request) shipping_choices, shipping_dict = _get_shipping_choices(paymentmodule, self.tempCart, self.tempContact) self.fields['shipping'].choices = shipping_choices self.shipping_dict = shipping_dict
def google_track_signup(context): """ Output a a new user signup in the format that Google Analytics needs. """ request = context['request'] contact = Contact.from_request(request, create=False) return({'contact' : contact})
def google_track_signup(context): """ Output a a new user signup in the format that Google Analytics needs. """ request = context['request'] contact = Contact.from_request(request, create=False) return ({'contact': contact})
def update(request): """Update contact info""" init_data = {} areas, countries, only_country = get_area_country_options(request) contact = Contact.from_request(request, create=False) if request.POST: new_data = request.POST.copy() form = ExtendedContactInfoForm(countries, areas, new_data, initial=init_data) if form.is_valid(): if contact is None and request.user: contact = Contact(user=request.user) custID = form.save(contact=contact) request.session['custID'] = custID url = urlresolvers.reverse('satchmo_account_info') return http.HttpResponseRedirect(url) else: if config_get_group('NEWSLETTER'): show_newsletter = True else: show_newsletter = False else: if contact: #If a person has their contact info, make sure we populate it in the form for item in contact.__dict__.keys(): init_data[item] = getattr(contact,item) if contact.shipping_address: for item in contact.shipping_address.__dict__.keys(): init_data["ship_"+item] = getattr(contact.shipping_address,item) if contact.billing_address: for item in contact.billing_address.__dict__.keys(): init_data[item] = getattr(contact.billing_address,item) if contact.primary_phone: init_data['phone'] = contact.primary_phone.phone show_newsletter = False current_subscriber = False if config_get_group('NEWSLETTER'): show_newsletter = True if contact: from satchmo.newsletter import is_subscribed current_subscriber = is_subscribed(contact) init_data['newsletter'] = current_subscriber form = ExtendedContactInfoForm(countries, areas, initial=init_data) context = RequestContext(request, { 'form': form, 'country': only_country, 'show_newsletter': show_newsletter}) return render_to_response('contact/update_form.html', context)
def __init__(self, request, paymentmodule, *args, **kwargs): super(SimplePayShipForm, self).__init__(*args, **kwargs) self.tempCart = Cart.objects.get(id=request.session['cart']) self.tempContact = Contact.from_request(request) shipping_choices, shipping_dict = _get_shipping_choices( paymentmodule, self.tempCart, self.tempContact) self.fields['shipping'].choices = shipping_choices self.shipping_dict = shipping_dict
def contact_info(request): """View which collects demographic information from customer.""" #First verify that the cart exists and has items if request.session.get('cart'): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: return render_to_response('checkout/empty_cart.html', RequestContext(request)) else: return render_to_response('checkout/empty_cart.html', RequestContext(request)) init_data = {} areas, countries, only_country = get_area_country_options(request) contact = Contact.from_request(request, create=False) if request.POST: new_data = request.POST.copy() if not tempCart.is_shippable: new_data['copy_address'] = True form = PaymentContactInfoForm(countries, areas, new_data, initial=init_data) if form.is_valid(): if contact is None and request.user: contact = Contact(user=request.user) custID = form.save(contact=contact, update_newsletter=False) request.session['custID'] = custID #TODO - Create an order here and associate it with a session modulename = 'PAYMENT_' + new_data['paymentmethod'] paymentmodule = config_get_group(modulename) url = lookup_url(paymentmodule, 'satchmo_checkout-step2') return http.HttpResponseRedirect(url) else: if contact: #If a person has their contact info, make sure we populate it in the form for item in contact.__dict__.keys(): init_data[item] = getattr(contact,item) if contact.shipping_address: for item in contact.shipping_address.__dict__.keys(): init_data["ship_"+item] = getattr(contact.shipping_address,item) if contact.billing_address: for item in contact.billing_address.__dict__.keys(): init_data[item] = getattr(contact.billing_address,item) if contact.primary_phone: init_data['phone'] = contact.primary_phone.phone else: # Allow them to login from this page. request.session.set_test_cookie() form = PaymentContactInfoForm(countries, areas, initial=init_data) context = RequestContext(request, { 'form': form, 'country': only_country, 'paymentmethod_ct': len(config_value('PAYMENT', 'MODULES')) }) return render_to_response('checkout/form.html', context)
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="") request.session['orderID'] = newOrder.id newOrder.add_status(status='Pending', notes="Order successfully submitted") orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=payment_module.KEY.value) orderpayment.save() #Now, send a confirmation email if payment_module['EMAIL'].value: shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': newOrder, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn( 'Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError( 'Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.' )
def contact_info(request): """View which collects demographic information from customer.""" # First verify that the cart exists and has items if request.session.get("cart"): tempCart = Cart.objects.get(id=request.session["cart"]) if tempCart.numItems == 0: return render_to_response("checkout/empty_cart.html", RequestContext(request)) else: return render_to_response("checkout/empty_cart.html", RequestContext(request)) init_data = {} areas, countries, only_country = get_area_country_options(request) contact = Contact.from_request(request, create=False) if request.POST: new_data = request.POST.copy() if not tempCart.is_shippable: new_data["copy_address"] = True form = PaymentContactInfoForm(countries, areas, new_data, initial=init_data) if form.is_valid(): if contact is None and request.user: contact = Contact(user=request.user) custID = form.save(contact=contact, update_newsletter=False) request.session["custID"] = custID # TODO - Create an order here and associate it with a session modulename = "PAYMENT_" + new_data["paymentmethod"] paymentmodule = config_get_group(modulename) url = lookup_url(paymentmodule, "satchmo_checkout-step2") return http.HttpResponseRedirect(url) else: if contact: # If a person has their contact info, make sure we populate it in the form for item in contact.__dict__.keys(): init_data[item] = getattr(contact, item) if contact.shipping_address: for item in contact.shipping_address.__dict__.keys(): init_data["ship_" + item] = getattr(contact.shipping_address, item) if contact.billing_address: for item in contact.billing_address.__dict__.keys(): init_data[item] = getattr(contact.billing_address, item) if contact.primary_phone: init_data["phone"] = contact.primary_phone.phone else: # Allow them to login from this page. request.session.set_test_cookie() form = PaymentContactInfoForm(countries, areas, initial=init_data) context = RequestContext( request, {"form": form, "country": only_country, "paymentmethod_ct": len(config_value("PAYMENT", "MODULES"))} ) return render_to_response("checkout/form.html", context)
def order_history(request): orders = None contact = Contact.from_request(request, create=False) if contact is not None: orders = Order.objects.filter(contact=contact).order_by('-timestamp') ctx = RequestContext(request, { 'contact' : contact, 'orders' : orders}) return render_to_response('contact/order_history.html', ctx)
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping="", discount="") request.session['orderID'] = newOrder.id newOrder.add_status(status='Pending', notes = "Order successfully submitted") orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=payment_module.KEY.value) orderpayment.save() #Now, send a confirmation email if payment_module['EMAIL'].value: shop_config = Config.get_shop_config() shop_email = shop_config.store_email shop_name = shop_config.store_name t = loader.get_template('email/order_complete.txt') c = Context({'order': newOrder, 'shop_name': shop_name}) subject = "Thank you for your order from %s" % shop_name try: email = orderToProcess.contact.email body = t.render(c) send_mail(subject, body, shop_email, [email], fail_silently=False) except SocketError, e: if settings.DEBUG: log.error('Error sending mail: %s' % e) log.warn('Ignoring email error, since you are running in DEBUG mode. Email was:\nTo:%s\nSubject: %s\n---\n%s', email, subject, body) else: log.fatal('Error sending mail: %s' % e) raise IOError('Could not send email, please check to make sure your email settings are correct, and that you are not being blocked by your ISP.')
def credit_pay_ship_info(request, payment_module): #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: return render_to_response('checkout/empty_cart.html', RequestContext(request)) #Verify order info is here if request.POST: new_data = request.POST.copy() form = CreditPayShipForm(request, payment_module, new_data) if form.is_valid(): data = form.cleaned_data # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping=data['shipping'], discount=data['discount']) request.session['orderID'] = newOrder.id #TODO: allow partial-pay here, which will mean that not all payments are on new orders. orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=unicode(payment_module.KEY.value)) orderpayment.save() # Save the credit card information cc = CreditCardDetail(orderpayment=orderpayment, ccv=data['ccv'], expireMonth=data['month_expires'], expireYear=data['year_expires'], creditType=data['credit_type']) cc.storeCC(data['credit_number']) cc.save() url = lookup_url(payment_module, 'satchmo_checkout-step3') return http.HttpResponseRedirect(url) else: form = CreditPayShipForm(request, payment_module) template = lookup_template(payment_module, 'checkout/pay_ship.html') ctx = { 'form' : form, 'PAYMENT_LIVE' : payment_live(payment_module) } return render_to_response(template, ctx, RequestContext(request))
def __init__(self, request, paymentmodule, *args, **kwargs): creditchoices = paymentmodule.CREDITCHOICES.choice_values super(CreditPayShipForm, self).__init__(*args, **kwargs) self.fields['credit_type'].choices = creditchoices year_now = datetime.date.today().year self.fields['year_expires'].choices = [(year, year) for year in range(year_now, year_now+6)] self.tempCart = Cart.objects.get(id=request.session['cart']) self.tempContact = Contact.from_request(request) shipping_choices, shipping_dict = _get_shipping_choices(paymentmodule, self.tempCart, self.tempContact) self.fields['shipping'].choices = shipping_choices self.shipping_dict = shipping_dict
def order_tracking(request, order_id): order = None contact = Contact.from_request(request, create=False) if contact is not None: try: order = Order.objects.get(id__exact=order_id, contact=contact) except Order.DoesNotExist: pass if order is None: return bad_or_missing(request, _("The order you have requested doesn't exist, or you don't have access to it.")) ctx = RequestContext(request, { 'contact' : contact, 'order' : order}) return render_to_response('contact/order_tracking.html', ctx)
def simple_pay_ship_info(request, payment_module, template): """A pay_ship view which doesn't require a credit card""" #First verify that the customer exists contact = Contact.from_request(request, create=False) if contact is None: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) #Verify we still have items in the cart if request.session.get('cart', False): tempCart = Cart.objects.get(id=request.session['cart']) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) else: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) #Verify order info is here if request.POST: new_data = request.POST.copy() form = SimplePayShipForm(request, payment_module, new_data) if form.is_valid(): data = form.cleaned_data # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, tempCart, contact, shipping=data['shipping'], discount=data['discount']) request.session['orderID'] = newOrder.id #TODO: allow partial-pay here, which will mean that not all payments are on new orders. orderpayment = OrderPayment(order=newOrder, amount=newOrder.balance, payment=payment_module.KEY.value) orderpayment.save() url = lookup_url(payment_module, 'satchmo_checkout-step3') return http.HttpResponseRedirect(url) else: form = SimplePayShipForm(request, payment_module) template = lookup_template(payment_module, template) ctx = { 'form' : form, 'PAYMENT_LIVE' : payment_live(payment_module) } return render_to_response(template, ctx, RequestContext(request))
def __init__(self, request, paymentmodule, *args, **kwargs): creditchoices = paymentmodule.CREDITCHOICES.choice_values super(CreditPayShipForm, self).__init__(*args, **kwargs) self.fields['credit_type'].choices = creditchoices year_now = datetime.date.today().year self.fields['year_expires'].choices = [ (year, year) for year in range(year_now, year_now + 6) ] self.tempCart = Cart.objects.get(id=request.session['cart']) self.tempContact = Contact.from_request(request) shipping_choices, shipping_dict = _get_shipping_choices( paymentmodule, self.tempCart, self.tempContact) self.fields['shipping'].choices = shipping_choices self.shipping_dict = shipping_dict
def register_handle_form(request, redirect=None): """ Handle all registration logic. This is broken out from "register" to allow easy overriding/hooks such as a combined login/register page. Returns: - Success flag - HTTPResponseRedirect (success) or form (fail) """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): data = form.cleaned_data password = data['password'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = generate_id(first_name, last_name) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. contact = Contact.from_request(request, create=False) if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.save() if config_get_group('NEWSLETTER'): from satchmo.newsletter import update_subscription if 'newsletter' not in data: subscribed = False else: subscribed = data['newsletter'] update_subscription(contact, subscribed) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) if not redirect: redirect = urlresolvers.reverse('registration_complete') return (True, http.HttpResponseRedirect(redirect)) else: initial_data = {} contact = Contact.from_request(request, create=False) if contact is not None: initial_data = { 'email': contact.email, 'first_name': contact.first_name, 'last_name': contact.last_name } if contact and config_get_group('NEWSLETTER'): from satchmo.newsletter import is_subscribed current_subscriber = is_subscribed(contact) else: current_subscriber = False initial_data['newsletter'] = current_subscriber form = RegistrationForm(initial=initial_data) return (False, form)
def register_handle_form(request, redirect=None): """ Handle all registration logic. This is broken out from "register" to allow easy overriding/hooks such as a combined login/register page. Returns: - Success flag - HTTPResponseRedirect (success) or form (fail) """ if request.method == 'POST': form = RegistrationForm(request.POST) if form.is_valid(): data = form.cleaned_data password = data['password'] email = data['email'] first_name = data['first_name'] last_name = data['last_name'] username = generate_id(first_name, last_name) verify = (config_value('SHOP', 'ACCOUNT_VERIFICATION') == 'EMAIL') if verify: from registration.models import RegistrationProfile user = RegistrationProfile.objects.create_inactive_user( username, password, email, send_email=True) else: user = User.objects.create_user(username, email, password) user.first_name = first_name user.last_name = last_name user.save() # If the user already has a contact, retrieve it. # Otherwise, create a new one. contact = Contact.from_request(request, create=False) if contact is None: contact = Contact() contact.user = user contact.first_name = first_name contact.last_name = last_name contact.email = email contact.role = 'Customer' contact.save() if config_get_group('NEWSLETTER'): from satchmo.newsletter import update_subscription if 'newsletter' not in data: subscribed = False else: subscribed = data['newsletter'] update_subscription(contact, subscribed) if not verify: user = authenticate(username=username, password=password) login(request, user) send_welcome_email(email, first_name, last_name) if not redirect: redirect = urlresolvers.reverse('registration_complete') return (True, http.HttpResponseRedirect(redirect)) else: initial_data = {} contact = Contact.from_request(request, create=False) if contact is not None: initial_data = { 'email': contact.email, 'first_name': contact.first_name, 'last_name': contact.last_name} if contact and config_get_group('NEWSLETTER'): from satchmo.newsletter import is_subscribed current_subscriber = is_subscribed(contact) else: current_subscriber = False initial_data['newsletter'] = current_subscriber form = RegistrationForm(initial=initial_data) return (False, form)