def make_test_order(country, state): c = Contact(first_name="Gift", last_name="Tester", role="Customer", email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact = country) ad = AddressBook(contact=c, description="home", street1 = "test", state=state, city="Portland", country = country, is_default_shipping=True, is_default_billing=True) ad.save() site = Site.objects.get_current() o = Order(contact=c, shipping_cost=Decimal('0.00'), site=site) o.save() p = Product.objects.get(slug='GIFT10') price = p.unit_price log.debug("creating with price: %s", price) item1 = OrderItem(order=o, product=p, quantity=2, unit_price=price, line_item_price=price*2) item1.save() detail = OrderItemDetail(name = 'email', value='*****@*****.**', sort_order=0, item=item1) detail.save() detail = OrderItemDetail(name = 'message', value='hello there', sort_order=0, item=item1) detail.save() return o
def one_step(request): payment_module = config_get_group('PAYMENT_AUTOSUCCESS') #First verify that the customer exists try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: url = lookup_url(payment_module, 'satchmo_checkout-step1') return HttpResponseRedirect(url) #Verify we still have items in the cart 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)) # 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") record_payment(newOrder, payment_module, amount=newOrder.balance) tempCart.empty() success = lookup_url(payment_module, 'satchmo_checkout-success') return HttpResponseRedirect(success)
def one_step(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_AUTOSUCCESS") # First verify that the customer exists try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: url = lookup_url(payment_module, "satchmo_checkout-step1") return HttpResponseRedirect(url) # Verify we still have items in the cart if cart.numItems == 0: template = lookup_template(payment_module, "checkout/empty_cart.html") return render(request, template) # Create a new order newOrder = Order(contact=contact) pay_ship_save(newOrder, cart, contact, shipping="", discount="") request.session["orderID"] = newOrder.id newOrder.add_status(status="Pending", notes="Order successfully submitted") record_payment(newOrder, payment_module, amount=newOrder.balance) success = lookup_url(payment_module, "satchmo_checkout-success") return HttpResponseRedirect(success)
def get_or_create_order(request, working_cart, contact, data): """Get the existing order from the session, else create using the working_cart, contact and data""" shipping = data['shipping'] discount = data['discount'] try: newOrder = Order.objects.from_request(request) pay_ship_save(newOrder, working_cart, contact, shipping=shipping, discount=discount, update=True) except Order.DoesNotExist: # Create a new order. newOrder = Order(contact=contact) pay_ship_save(newOrder, working_cart, contact, shipping=shipping, discount=discount) request.session['orderID'] = newOrder.id return newOrder
def make_test_order(country, state, include_non_taxed=False): warnings.warn( "make_test_order is deprecated - Use TestOrderFactory instead", DeprecationWarning, ) c = Contact(first_name="Tax", last_name="Tester", role="Customer", email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook( contact=c, description="home", street1="test", state=state, city="Portland", country=country, is_default_shipping=True, is_default_billing=True, ) ad.save() o = Order(contact=c, shipping_cost=Decimal("10.00")) o.save() p = Product.objects.get(slug="dj-rocks-s-b") price = p.unit_price item1 = OrderItem(order=o, product=p, quantity=5, unit_price=price, line_item_price=price * 5) item1.save() if include_non_taxed: p = Product.objects.get(slug="neat-book-hard") price = p.unit_price item2 = OrderItem(order=o, product=p, quantity=1, unit_price=price, line_item_price=price) item2.save() return o
def make_test_order(country, state, include_non_taxed=False, site=None): warnings.warn( "make_test_order is deprecated - Use TestOrderFactory instead", DeprecationWarning, ) if not site: site = Site.objects.get_current() c = Contact( first_name="Tax", last_name="Tester", role="Customer", email="*****@*****.**" ) c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook( contact=c, description="home", street1="test", state=state, city="Portland", country=country, is_default_shipping=True, is_default_billing=True, ) ad.save() o = Order(contact=c, shipping_cost=Decimal("10.00"), site=site) o.save() p = Product.objects.get(slug="dj-rocks-s-b") price = p.unit_price item1 = OrderItem( order=o, product=p, quantity=5, unit_price=price, line_item_price=price * 5 ) item1.save() if include_non_taxed: p = Product.objects.get(slug="neat-book-hard") price = p.unit_price item2 = OrderItem( order=o, product=p, quantity=1, unit_price=price, line_item_price=price ) item2.save() return o
def make_test_order(country, state): c = Contact(first_name="Gift", last_name="Tester", role="Customer", email="*****@*****.**") c.save() if not isinstance(country, Country): country = Country.objects.get(iso2_code__iexact=country) ad = AddressBook( contact=c, description="home", street1="test", state=state, city="Portland", country=country, is_default_shipping=True, is_default_billing=True, ) ad.save() o = Order(contact=c, shipping_cost=Decimal("0.00")) o.save() p = Product.objects.get(slug="GIFT10") price = p.unit_price log.debug("creating with price: %s", price) item1 = OrderItem(order=o, product=p, quantity=2, unit_price=price, line_item_price=price * 2) item1.save() detail = OrderItemDetail(name="email", value="*****@*****.**", sort_order=0, item=item1) detail.save() detail = OrderItemDetail(name="message", value="hello there", sort_order=0, item=item1) detail.save() return o
def setUp(self): self.US = Country.objects.get(iso2_code__iexact='US') self.site = Site.objects.get_current() tax = config_get('TAX', 'MODULE') tax.update('satchmo.tax.modules.no') c = Contact(first_name="Jim", last_name="Tester", role="Customer", email="*****@*****.**") c.save() ad = AddressBook(contact=c, description="home", street1="test", state="OR", city="Portland", country=self.US, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) o.save() small = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) small.save() p = Product.objects.get(slug='neat-book-soft') price = p.unit_price item1 = OrderItem(order=o, product=p, quantity=1, unit_price=price, line_item_price=price) item1.save() item1s = OrderItem(order=small, product=p, quantity=1, unit_price=price, line_item_price=price) item1s.save() p = Product.objects.get(slug='neat-book-hard') price = p.unit_price item2 = OrderItem(order=o, product=p, quantity=1, unit_price=price, line_item_price=price) item2.save() self.order = o self.small = small
def setUp(self): self.US = Country.objects.get(iso2_code__iexact = 'US') self.site = Site.objects.get_current() tax = config_get('TAX','MODULE') tax.update('satchmo.tax.modules.no') c = Contact(first_name="Jim", last_name="Tester", role="Customer", email="*****@*****.**") c.save() ad = AddressBook(contact=c, description="home", street1 = "test", state="OR", city="Portland", country = self.US, is_default_shipping=True, is_default_billing=True) ad.save() o = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) o.save() small = Order(contact=c, shipping_cost=Decimal('6.00'), site=self.site) small.save() p = Product.objects.get(slug='neat-book-soft') price = p.unit_price item1 = OrderItem(order=o, product=p, quantity=1, unit_price=price, line_item_price=price) item1.save() item1s = OrderItem(order=small, product=p, quantity=1, unit_price=price, line_item_price=price) item1s.save() p = Product.objects.get(slug='neat-book-hard') price = p.unit_price item2 = OrderItem(order=o, product=p, quantity=1, unit_price=price, line_item_price=price) item2.save() self.order = o self.small = small
def get_or_create_order(request, working_cart, contact, data): """Get the existing order from the session, else create using the working_cart, contact and data""" shipping = data['shipping'] discount = data['discount'] try: newOrder = Order.objects.from_request(request) newOrder.notes = working_cart.desc pay_ship_save(newOrder, working_cart, contact, shipping=shipping, discount=discount, update=True) except Order.DoesNotExist: # Create a new order. newOrder = Order(contact=contact) newOrder.notes = working_cart.desc pay_ship_save(newOrder, working_cart, contact, shipping=shipping, discount=discount) request.session['orderID'] = newOrder.id return newOrder
def get_or_create_order(request, working_cart, contact, data): """Get the existing order from the session, else create using the working_cart, contact and data""" shipping = data["shipping"] discount = data["discount"] try: newOrder = Order.objects.from_request(request) pay_ship_save( newOrder, working_cart, contact, shipping=shipping, discount=discount, update=True, ) except Order.DoesNotExist: # Get currency from request iso_4217_code = currency_for_request(request) currency = Currency.objects.all_accepted().get( iso_4217_code=iso_4217_code) try: exchange_rate = currency.exchange_rates.latest().rate except ExchangeRate.DoesNotExist: exchange_rate = Decimal("1.00") # Create a new order. newOrder = Order(contact=contact, currency=currency, exchange_rate=exchange_rate) pay_ship_save(newOrder, working_cart, contact, shipping=shipping, discount=discount) request.session["orderID"] = newOrder.id return newOrder
def test_verify_hash__no_match(self): order = Order(id=1, contact_id=1) # Pass the reverse of the orders hash back into itself self.assertFalse(order.verify_hash(order.verification_hash[::-1]))
def test_verify_hash__match(self): order = Order(id=1, contact_id=1) # Pass the orders hash back into itself self.assertTrue(order.verify_hash(order.verification_hash))
def test_verification_hash(self): with self.settings(SECRET_KEY="123"): order = Order(id=1, contact_id=1) self.assertEqual(order.verification_hash, "97f97b0cd887f1b61e6f7e136aa752b1")