def confirm_info(request): # Check that items are in stock cart = Cart.objects.from_request(request) if cart.not_enough_stock(): return HttpResponseRedirect(urlresolvers.reverse("satchmo_cart")) payment_module = config_get_group('PAYMENT_GOOGLE') if not 'orderID' in request.session: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) try: order = Order.objects.from_request(request) except Order.DoesNotExist: order = None if not (order and order.validate(request)): context = RequestContext( request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) live = payment_live(payment_module) gcart = GoogleCart(order, payment_module, live) log.debug("CART:\n%s", gcart.cart_xml) template = lookup_template(payment_module, 'checkout/google/confirm.html') if live: merchant_id = payment_module.MERCHANT_ID.value url_template = payment_module.POST_URL.value else: merchant_id = payment_module.MERCHANT_TEST_ID.value url_template = payment_module.POST_TEST_URL.value post_url = url_template % {'MERCHANT_ID': merchant_id} default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') ctx = RequestContext( request, { 'order': order, 'post_url': post_url, 'default_view_tax': default_view_tax, 'google_cart': gcart.encoded_cart(), 'google_signature': gcart.encoded_signature(), 'PAYMENT_LIVE': live }) return render_to_response(template, ctx)
def pay_ship_render_form(request, form, template, payment_module, cart): template = lookup_template(payment_module, template) if cart.numItems > 0: products = [item.product for item in cart.cartitem_set.all()] sale = find_best_auto_discount(products) else: sale = None ctx = {"form": form, "sale": sale, "PAYMENT_LIVE": payment_live(payment_module)} return render(request, template, ctx)
def confirm_info(request): # Check that items are in stock cart = Cart.objects.from_request(request) if cart.not_enough_stock(): return HttpResponseRedirect(urlresolvers.reverse("satchmo_cart")) payment_module = config_get_group('PAYMENT_GOOGLE') if not 'orderID' in request.session: url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) try: order = Order.objects.from_request(request) except Order.DoesNotExist: order = None if not (order and order.validate(request)): context = RequestContext(request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) live = payment_live(payment_module) gcart = GoogleCart(order, payment_module, live) log.debug("CART:\n%s", gcart.cart_xml) template = lookup_template(payment_module, 'checkout/google/confirm.html') if live: merchant_id = payment_module.MERCHANT_ID.value url_template = payment_module.POST_URL.value else: merchant_id = payment_module.MERCHANT_TEST_ID.value url_template = payment_module.POST_TEST_URL.value post_url = url_template % {'MERCHANT_ID' : merchant_id} default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') ctx = RequestContext(request, { 'order': order, 'post_url': post_url, 'default_view_tax': default_view_tax, 'google_cart' : gcart.encoded_cart(), 'google_signature' : gcart.encoded_signature(), 'PAYMENT_LIVE' : live }) return render_to_response(template, ctx)
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 pay_ship_render_form(request, form, template, payment_module, cart): template = lookup_template(payment_module, template) if cart.numItems > 0: products = [item.product for item in cart.cartitem_set.all()] sale = find_best_auto_discount(products) else: sale = None ctx = RequestContext(request, { 'form': form, 'sale' : sale, 'PAYMENT_LIVE': payment_live(payment_module)}) return render_to_response(template, ctx)
def confirm_info(request): payment_module = config_get_group('PAYMENT_GOOGLE') if not request.session.get('orderID'): url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) if request.session.get('cart'): 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)) order = Order.objects.get(id=request.session['orderID']) # Check if the order is still valid if not order.validate(request): context = RequestContext( request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) live = payment_live(payment_module) gcart = GoogleCart(order, payment_module, live) log.debug("CART:\n%s", gcart.cart_xml) template = lookup_template(payment_module, 'checkout/google/confirm.html') if live: merchant_id = payment_module.MERCHANT_ID.value url_template = payment_module.POST_URL.value else: merchant_id = payment_module.MERCHANT_TEST_ID.value url_template = payment_module.POST_TEST_URL.value post_url = url_template % {'MERCHANT_ID': merchant_id} ctx = RequestContext( request, { 'order': order, 'post_url': post_url, 'google_cart': gcart.encoded_cart(), 'google_signature': gcart.encoded_signature(), 'PAYMENT_LIVE': live }) return render_to_response(template, ctx)
def pay_ship_render_form(request, form, template, payment_module, cart): template = lookup_template(payment_module, template) if cart.numItems > 0: products = [item.product for item in cart.cartitem_set.all()] sale = find_best_auto_discount(products) else: sale = None ctx = RequestContext(request, { 'form': form, 'sale': sale, 'PAYMENT_LIVE': payment_live(payment_module) }) return render_to_response(template, ctx)
def pay_ship_render_form(request, form, template, payment_module, cart): template = lookup_template(payment_module, template) if cart.numItems > 0: products = [item.product for item in cart.cartitem_set.all()] sale = find_best_auto_discount(products) else: sale = None ctx = { "form": form, "sale": sale, "PAYMENT_LIVE": payment_live(payment_module) } return render(request, template, ctx)
def confirm_info(request): payment_module = config_get_group('PAYMENT_GOOGLE') if not request.session.get('orderID'): url = lookup_url(payment_module, 'satchmo_checkout-step1') return http.HttpResponseRedirect(url) if request.session.get('cart'): 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)) order = Order.objects.get(id=request.session['orderID']) # Check if the order is still valid if not order.validate(request): context = RequestContext(request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) live = payment_live(payment_module) gcart = GoogleCart(order, payment_module, live) log.debug("CART:\n%s", gcart.cart_xml) template = lookup_template(payment_module, 'checkout/google/confirm.html') if live: merchant_id = payment_module.MERCHANT_ID.value url_template = payment_module.POST_URL.value else: merchant_id = payment_module.MERCHANT_TEST_ID.value url_template = payment_module.POST_TEST_URL.value post_url = url_template % {'MERCHANT_ID' : merchant_id} ctx = RequestContext(request, { 'order': order, 'post_url': post_url, 'google_cart' : gcart.encoded_cart(), 'google_signature' : gcart.encoded_signature(), 'PAYMENT_LIVE' : live }) return render_to_response(template, ctx)
def confirm_info(request): payment_module = config_get_group('PAYMENT_PAYPAL') if not request.session.get('orderID'): url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) if request.session.get('cart'): 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)) order = Order.objects.get(id=request.session['orderID']) # Check if the order is still valid if not order.validate(request): context = RequestContext(request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) template = lookup_template(payment_module, 'checkout/paypal/confirm.html') if payment_module.LIVE.value: log.debug("live order on %s", payment_module.KEY.value) url = payment_module.POST_URL.value account = payment_module.BUSINESS.value else: url = payment_module.POST_TEST_URL.value account = payment_module.BUSINESS_TEST.value try: address = lookup_url(payment_module, payment_module.RETURN_ADDRESS.value, include_server=True) except urlresolvers.NoReverseMatch: address = payment_module.RETURN_ADDRESS.value ctx = RequestContext(request, {'order': order, 'post_url': url, 'business': account, 'currency_code': payment_module.CURRENCY_CODE.value, 'return_address': address, 'PAYMENT_LIVE' : payment_live(payment_module) }) return render_to_response(template, 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 _onForm(self, controller): """Show the confirmation page for the order. Looks up the proper template for the payment_module. """ template = controller.lookup_template('CONFIRM') controller.order.recalculate_total() base_env = { 'PAYMENT_LIVE' : payment_live(controller.paymentModule), 'default_view_tax' : controller.viewTax, 'order': controller.order, 'errors': controller.processorMessage, 'checkout_step2': controller.lookup_url('satchmo_checkout-step2')} if controller.extra_context: base_env.update(controller.extra_context) context = RequestContext(self.request, base_env) return render_to_response(template, context)
def _onForm(self, controller): """Show the confirmation page for the order. Looks up the proper template for the payment_module. """ template = controller.lookup_template("CONFIRM") controller.order.recalculate_total() context = { "PAYMENT_LIVE": payment_live(controller.paymentModule), "default_view_tax": controller.viewTax, "order": controller.order, "errors": controller.processorMessage, "checkout_step2": controller.lookup_url("satchmo_checkout-step2"), } if controller.extra_context: context.update(controller.extra_context) return render(request, template, context)
def _onForm(self, controller): """Show the confirmation page for the order. Looks up the proper template for the payment_module. """ template = controller.lookup_template('CONFIRM') controller.order.recalculate_total() base_env = { 'PAYMENT_LIVE': payment_live(controller.paymentModule), 'default_view_tax': controller.viewTax, 'order': controller.order, 'errors': controller.processorMessage, 'checkout_step2': controller.lookup_url('satchmo_checkout-step2') } if controller.extra_context: base_env.update(controller.extra_context) context = RequestContext(self.request, base_env) return render_to_response(template, context)
def confirm_info(request): # Check that items are in stock cart = Cart.objects.from_request(request) if cart.not_enough_stock(): return HttpResponseRedirect(reverse("satchmo_cart")) payment_module = config_get_group("PAYMENT_PAYPAL") # Get the order, # if there is no order, return to checkout step 1 try: order = Order.objects.from_request(request) except Order.DoesNotExist: url = lookup_url(payment_module, "satchmo_checkout-step1") return HttpResponseRedirect(url) # Check that the cart has items in it. if cart.numItems == 0: template = lookup_template(payment_module, "checkout/empty_cart.html") return render(request, template) # Check if the order is still valid if not order.validate(request): context = {"message": _("Your order is no longer valid.")} return render(request, "shop_404.html", context) # Set environment if payment_module.LIVE.value: environment = "production" else: environment = "sandbox" context = { "order": order, "environment": environment, "PAYMENT_LIVE": payment_live(payment_module), } template = lookup_template(payment_module, "checkout/paypal/confirm.html") return render(request, template, context)
def confirm_info(request): # Check that items are in stock cart = Cart.objects.from_request(request) if cart.not_enough_stock(): return HttpResponseRedirect(urlresolvers.reverse("satchmo_cart")) payment_module = config_get_group('PAYMENT_PAYPAL') # Get the order, # if there is no order, return to checkout step 1 try: order = Order.objects.from_request(request) except Order.DoesNotExist: url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) # Check that the cart has items in it. if cart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Check if the order is still valid if not order.validate(request): context = RequestContext( request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) # Set URL and accounts based on whether the site is LIVE or not if payment_module.LIVE.value: log.debug("live order on %s", payment_module.KEY.value) url = payment_module.POST_URL.value account = payment_module.BUSINESS.value else: url = payment_module.POST_TEST_URL.value account = payment_module.BUSINESS_TEST.value # Is there a custom return URL # Or will we use the default one? try: address = lookup_url(payment_module, payment_module.RETURN_ADDRESS.value, include_server=True) except urlresolvers.NoReverseMatch: address = payment_module.RETURN_ADDRESS.value # Create a pending payment create_pending_payment(order, payment_module) default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') recurring = None order_items = order.orderitem_set.all() for item in order_items: if item.product.is_subscription: recurring = { 'product': item.product, 'price': item.product.price_set.all()[0].price } trial0 = recurring['product'].subscriptionproduct.get_trial_terms( 0) if len(order_items) > 1 or trial0 is not None or recurring[ 'price'] < order.balance: recurring['trial1'] = {'price': order.balance} if trial0 is not None: recurring['trial1']['expire_length'] = trial0.expire_length recurring['trial1']['expire_unit'] = trial0.expire_unit[0] # else: # recurring['trial1']['expire_length'] = recurring['product'].subscriptionproduct.get_trial_terms(0).expire_length trial1 = recurring[ 'product'].subscriptionproduct.get_trial_terms(1) if trial1 is not None: recurring['trial2']['expire_length'] = trial1.expire_length recurring['trial2']['expire_unit'] = trial1.expire_unit[0] recurring['trial2']['price'] = trial1.price ctx = RequestContext( request, { 'order': order, 'post_url': url, 'default_view_tax': default_view_tax, 'business': account, 'currency_code': payment_module.CURRENCY_CODE.value, 'return_address': address, 'invoice': order.id, 'subscription': recurring, 'PAYMENT_LIVE': payment_live(payment_module) }) template = lookup_template(payment_module, 'checkout/paypal/confirm.html') return render_to_response(template, ctx)
def confirm_info(request): payment_module = config_get_group('PAYMENT_PAYPAL') try: order = Order.objects.from_request(request) except Order.DoesNotExist: url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: template = lookup_template(payment_module, 'checkout/empty_cart.html') return render_to_response(template, RequestContext(request)) # Check if the order is still valid if not order.validate(request): context = RequestContext(request, {'message': _('Your order is no longer valid.')}) return render_to_response('shop_404.html', context) template = lookup_template(payment_module, 'checkout/paypal/confirm.html') if payment_module.LIVE.value: log.debug("live order on %s", payment_module.KEY.value) url = payment_module.POST_URL.value account = payment_module.BUSINESS.value else: url = payment_module.POST_TEST_URL.value account = payment_module.BUSINESS_TEST.value try: address = lookup_url(payment_module, payment_module.RETURN_ADDRESS.value, include_server=True) except urlresolvers.NoReverseMatch: address = payment_module.RETURN_ADDRESS.value create_pending_payment(order, payment_module) default_view_tax = config_value('TAX', 'DEFAULT_VIEW_TAX') recurring = None order_items = order.orderitem_set.all() for item in order_items: if item.product.is_subscription: recurring = {'product':item.product, 'price':item.product.price_set.all()[0].price,} trial0 = recurring['product'].subscriptionproduct.get_trial_terms(0) if len(order_items) > 1 or trial0 is not None or recurring['price'] < order.balance: recurring['trial1'] = {'price': order.balance,} if trial0 is not None: recurring['trial1']['expire_length'] = trial0.expire_length recurring['trial1']['expire_unit'] = trial0.expire_unit[0] # else: # recurring['trial1']['expire_length'] = recurring['product'].subscriptionproduct.get_trial_terms(0).expire_length trial1 = recurring['product'].subscriptionproduct.get_trial_terms(1) if trial1 is not None: recurring['trial2']['expire_length'] = trial1.expire_length recurring['trial2']['expire_unit'] = trial1.expire_unit[0] recurring['trial2']['price'] = trial1.price ctx = RequestContext(request, {'order': order, 'post_url': url, 'default_view_tax': default_view_tax, 'business': account, 'currency_code': payment_module.CURRENCY_CODE.value, 'return_address': address, 'invoice': order.id, 'subscription': recurring, 'PAYMENT_LIVE' : payment_live(payment_module) }) return render_to_response(template, ctx)