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 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 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))