def run(self): storeToyAndHaveSonySupply() sonyVendor = Sellers().searchVendorByName("Sony") option = DeliveryOption("FastOptTest", 10, sonyVendor.id) sonyVendor.addDeliveryOption(option) optionRetrieved = sonyVendor.getDeliveryOptions()[0] if optionRetrieved.name == "FastOptTest": return True
def customerOrderProductFromSony(): storeToyAndHaveSonySupply() sonyVendor = Sellers().searchVendorByName("Sony") option = DeliveryOption("FastOptTest", 10, sonyVendor.id) sonyVendor.addDeliveryOption(option) optionRetrieved = sonyVendor.getDeliveryOptions()[0] toyRetrieved = ProductListings().searchForProducts(["Toy"])[0] customer = storeAdamCustomer() customer.basket.addItem(toyRetrieved) payment = Payment() payment.applyDiscount(PromoCodes().getPromotion(123)) orderDescription = customer.basket.createOrderDescription() orderDescription.getOrderedItems()[0].setDeliveryOption(optionRetrieved) payment.payForOrder(orderDescription, CardPayment(124124, 14214), "32 Winding Lane")
def run(self): print("--Checkout--") payment = Payment() deliveryAddress = '' while deliveryAddress == '': deliveryAddress = input("Please type your delivery address: ") if deliveryAddress == 'back': return None if deliveryAddress == '': print("Delivery address cannot be empty") print("Now select delivery options for your ordered products") for orderedItem in self.orderDescription.getOrderedItems(): seller = Sellers().searchVendorById( orderedItem.productStock.sellerId) deliveryOptions = seller.getDeliveryOptions() productListing = ProductListings().searchFromProductById( orderedItem.productStock.productId) print("Delivery options for the " + productListing.name + ": ") for deliveryOption in deliveryOptions: print(" " + deliveryOption.name + ", $" + str(deliveryOption.price)) deliveryOption = None while deliveryOption == None: optInput = input( "Type the name of the delivery option to use: ") if optInput == 'back': return None for option in deliveryOptions: if option.name == optInput: deliveryOption = option orderedItem.deliveryOption = deliveryOption usePromoInput = '' while usePromoInput != 'y' and usePromoInput != 'n': usePromoInput = input( "Do you want to use a promotional code (y/n): ") if usePromoInput == "back": return None promoApplied = False if usePromoInput == 'y': validCode = False while validCode == False: codeInput = input("Enter your promotion code: ") if codeInput == "back": return None else: realCode = PromoCodes().getPromotion(codeInput) if realCode != None: payment.applyDiscount(realCode) validCode = True promoApplied = True if promoApplied: print("Total price before promotion: $" + str(self.orderDescription.getTotalPrice())) print("Price after promotion code: $" + str(payment.calculatePriceAfterPromo(self.orderDescription))) else: print("Total price: $" + str(self.orderDescription.getTotalPrice())) useStoredPaymentMethod = False if self.storedPaymentMethod != None: useStored = '' while useStored != 'y' and useStored != 'n': useStored = input( "Do you want to use your stored payment method?(y,n): ") if useStored == "back": return None useStoredPaymentMethod = useStored == 'y' paymentMethod = None toStore = False if not useStoredPaymentMethod: paymentTypeInput = '' while paymentTypeInput != 'credit' and paymentTypeInput != 'debit' and paymentTypeInput != 'paypal': paymentTypeInput = input( "What payment type do you want to use (credit,debit,paypal): " ) if paymentTypeInput == "back": return None if paymentTypeInput == 'credit': paymentMethod = CardPayment(0, 0) if paymentTypeInput == 'debit': paymentMethod = DebitPayment() if paymentTypeInput == 'paypal': paymentMethod = PaypalPayment() toStoreInput = '' while toStoreInput != 'y' and toStoreInput != 'n': toStoreInput = input( "Do you want to store this payment method for future use?(y,n): " ) if toStoreInput == "back": return None if toStoreInput == 'y': toStore = True else: paymentMethod = self.storedPaymentMethod if toStore: #Only store when the payment is complete self.customer.storedPaymentMethod = paymentMethod payment.payForOrder(self.orderDescription, paymentMethod, deliveryAddress) self.customer.basket.clearBasket() print("Payment successful, you have ordered the products!")