Search in sources :

Example 1 with CreditCard

use of com.salesmanager.core.model.order.payment.CreditCard in project shopizer by shopizer-ecommerce.

the class PersistableOrderPopulator method populate.

@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
    Validate.notNull(productService, "productService must be set");
    Validate.notNull(digitalProductService, "digitalProductService must be set");
    Validate.notNull(productAttributeService, "productAttributeService must be set");
    Validate.notNull(customerService, "customerService must be set");
    Validate.notNull(countryService, "countryService must be set");
    Validate.notNull(zoneService, "zoneService must be set");
    Validate.notNull(currencyService, "currencyService must be set");
    try {
        Map<String, Country> countriesMap = countryService.getCountriesMap(language);
        Map<String, Zone> zonesMap = zoneService.getZones(language);
        /**
         * customer *
         */
        PersistableCustomer customer = source.getCustomer();
        if (customer != null) {
            if (customer.getId() != null && customer.getId() > 0) {
                Customer modelCustomer = customerService.getById(customer.getId());
                if (modelCustomer == null) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists");
                }
                if (modelCustomer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
                    throw new ConversionException("Customer id " + customer.getId() + " does not exists for store " + store.getCode());
                }
                target.setCustomerId(modelCustomer.getId());
                target.setBilling(modelCustomer.getBilling());
                target.setDelivery(modelCustomer.getDelivery());
                target.setCustomerEmailAddress(source.getCustomer().getEmailAddress());
            }
        }
        target.setLocale(LocaleUtils.getLocale(store));
        CreditCard creditCard = source.getCreditCard();
        if (creditCard != null) {
            String maskedNumber = CreditCardUtils.maskCardNumber(creditCard.getCcNumber());
            creditCard.setCcNumber(maskedNumber);
            target.setCreditCard(creditCard);
        }
        Currency currency = null;
        try {
            currency = currencyService.getByCode(source.getCurrency());
        } catch (Exception e) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        if (currency == null) {
            throw new ConversionException("Currency not found for code " + source.getCurrency());
        }
        target.setCurrency(currency);
        target.setDatePurchased(source.getDatePurchased());
        // target.setCurrency(store.getCurrency());
        target.setCurrencyValue(new BigDecimal(0));
        target.setMerchant(store);
        target.setStatus(source.getOrderStatus());
        target.setPaymentModuleCode(source.getPaymentModule());
        target.setPaymentType(source.getPaymentType());
        target.setShippingModuleCode(source.getShippingModule());
        target.setCustomerAgreement(source.isCustomerAgreed());
        target.setConfirmedAddress(source.isConfirmedAddress());
        if (source.getPreviousOrderStatus() != null) {
            List<OrderStatus> orderStatusList = source.getPreviousOrderStatus();
            for (OrderStatus status : orderStatusList) {
                OrderStatusHistory statusHistory = new OrderStatusHistory();
                statusHistory.setStatus(status);
                statusHistory.setOrder(target);
                target.getOrderHistory().add(statusHistory);
            }
        }
        if (!StringUtils.isBlank(source.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(null);
            statusHistory.setOrder(target);
            statusHistory.setComments(source.getComments());
            target.getOrderHistory().add(statusHistory);
        }
        List<PersistableOrderProduct> products = source.getOrderProductItems();
        if (CollectionUtils.isEmpty(products)) {
            throw new ConversionException("Requires at least 1 PersistableOrderProduct");
        }
        com.salesmanager.shop.populator.order.PersistableOrderProductPopulator orderProductPopulator = new PersistableOrderProductPopulator();
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        orderProductPopulator.setDigitalProductService(digitalProductService);
        for (PersistableOrderProduct orderProduct : products) {
            OrderProduct modelOrderProduct = new OrderProduct();
            orderProductPopulator.populate(orderProduct, modelOrderProduct, store, language);
            target.getOrderProducts().add(modelOrderProduct);
        }
        List<OrderTotal> orderTotals = source.getTotals();
        if (CollectionUtils.isNotEmpty(orderTotals)) {
            for (OrderTotal total : orderTotals) {
                com.salesmanager.core.model.order.OrderTotal totalModel = new com.salesmanager.core.model.order.OrderTotal();
                totalModel.setModule(total.getModule());
                totalModel.setOrder(target);
                totalModel.setOrderTotalCode(total.getCode());
                totalModel.setTitle(total.getTitle());
                totalModel.setValue(total.getValue());
                target.getOrderTotal().add(totalModel);
            }
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
    return target;
}
Also used : OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Customer(com.salesmanager.core.model.customer.Customer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) OrderStatus(com.salesmanager.core.model.order.orderstatus.OrderStatus) Currency(com.salesmanager.core.model.reference.currency.Currency) ConversionException(com.salesmanager.core.business.exception.ConversionException) Zone(com.salesmanager.core.model.reference.zone.Zone) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ConversionException(com.salesmanager.core.business.exception.ConversionException) BigDecimal(java.math.BigDecimal) Country(com.salesmanager.core.model.reference.country.Country) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Example 2 with CreditCard

use of com.salesmanager.core.model.order.payment.CreditCard in project shopizer by shopizer-ecommerce.

the class OrderFacadeImpl method processOrderModel.

/**
 * Commit an order
 * @param order
 * @param customer
 * @param transaction
 * @param store
 * @param language
 * @return
 * @throws ServiceException
 */
private Order processOrderModel(ShopOrder order, Customer customer, Transaction transaction, MerchantStore store, Language language) throws ServiceException {
    try {
        if (order.isShipToBillingAdress()) {
            // customer shipping is billing
            PersistableCustomer orderCustomer = order.getCustomer();
            Address billing = orderCustomer.getBilling();
            orderCustomer.setDelivery(billing);
        }
        Order modelOrder = new Order();
        modelOrder.setDatePurchased(new Date());
        modelOrder.setBilling(customer.getBilling());
        modelOrder.setDelivery(customer.getDelivery());
        modelOrder.setPaymentModuleCode(order.getPaymentModule());
        modelOrder.setPaymentType(PaymentType.valueOf(order.getPaymentMethodType()));
        modelOrder.setShippingModuleCode(order.getShippingModule());
        modelOrder.setCustomerAgreement(order.isCustomerAgreed());
        // set the store
        modelOrder.setLocale(LocaleUtils.getLocale(store));
        // locale based
        // on the
        // country for
        // order $
        // formatting
        List<ShoppingCartItem> shoppingCartItems = order.getShoppingCartItems();
        Set<OrderProduct> orderProducts = new LinkedHashSet<OrderProduct>();
        if (!StringUtils.isBlank(order.getComments())) {
            OrderStatusHistory statusHistory = new OrderStatusHistory();
            statusHistory.setStatus(OrderStatus.ORDERED);
            statusHistory.setOrder(modelOrder);
            statusHistory.setDateAdded(new Date());
            statusHistory.setComments(order.getComments());
            modelOrder.getOrderHistory().add(statusHistory);
        }
        OrderProductPopulator orderProductPopulator = new OrderProductPopulator();
        orderProductPopulator.setDigitalProductService(digitalProductService);
        orderProductPopulator.setProductAttributeService(productAttributeService);
        orderProductPopulator.setProductService(productService);
        String shoppingCartCode = null;
        for (ShoppingCartItem item : shoppingCartItems) {
            if (shoppingCartCode == null && item.getShoppingCart() != null) {
                shoppingCartCode = item.getShoppingCart().getShoppingCartCode();
            }
            /**
             * Before processing order quantity of item must be > 0
             */
            Product product = productService.getById(item.getProductId());
            if (product == null) {
                throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
            }
            LOGGER.debug("Validate inventory");
            for (ProductAvailability availability : product.getAvailabilities()) {
                if (availability.getRegion().equals(Constants.ALL_REGIONS)) {
                    int qty = availability.getProductQuantity();
                    if (qty < item.getQuantity()) {
                        throw new ServiceException(ServiceException.EXCEPTION_INVENTORY_MISMATCH);
                    }
                }
            }
            OrderProduct orderProduct = new OrderProduct();
            orderProduct = orderProductPopulator.populate(item, orderProduct, store, language);
            orderProduct.setOrder(modelOrder);
            orderProducts.add(orderProduct);
        }
        modelOrder.setOrderProducts(orderProducts);
        OrderTotalSummary summary = order.getOrderTotalSummary();
        List<com.salesmanager.core.model.order.OrderTotal> totals = summary.getTotals();
        // re-order totals
        Collections.sort(totals, new Comparator<com.salesmanager.core.model.order.OrderTotal>() {

            public int compare(com.salesmanager.core.model.order.OrderTotal x, com.salesmanager.core.model.order.OrderTotal y) {
                if (x.getSortOrder() == y.getSortOrder())
                    return 0;
                return x.getSortOrder() < y.getSortOrder() ? -1 : 1;
            }
        });
        Set<com.salesmanager.core.model.order.OrderTotal> modelTotals = new LinkedHashSet<com.salesmanager.core.model.order.OrderTotal>();
        for (com.salesmanager.core.model.order.OrderTotal total : totals) {
            total.setOrder(modelOrder);
            modelTotals.add(total);
        }
        modelOrder.setOrderTotal(modelTotals);
        modelOrder.setTotal(order.getOrderTotalSummary().getTotal());
        // order misc objects
        modelOrder.setCurrency(store.getCurrency());
        modelOrder.setMerchant(store);
        // customer object
        orderCustomer(customer, modelOrder, language);
        // populate shipping information
        if (!StringUtils.isBlank(order.getShippingModule())) {
            modelOrder.setShippingModuleCode(order.getShippingModule());
        }
        String paymentType = order.getPaymentMethodType();
        Payment payment = new Payment();
        payment.setPaymentType(PaymentType.valueOf(paymentType));
        payment.setAmount(order.getOrderTotalSummary().getTotal());
        payment.setModuleName(order.getPaymentModule());
        payment.setCurrency(modelOrder.getCurrency());
        if (order.getPayment() != null && order.getPayment().get("paymentToken") != null) {
            // set
            // token
            String paymentToken = order.getPayment().get("paymentToken");
            Map<String, String> paymentMetaData = new HashMap<String, String>();
            payment.setPaymentMetaData(paymentMetaData);
            paymentMetaData.put("paymentToken", paymentToken);
        }
        if (PaymentType.CREDITCARD.name().equals(paymentType)) {
            payment = new CreditCardPayment();
            ((CreditCardPayment) payment).setCardOwner(order.getPayment().get("creditcard_card_holder"));
            ((CreditCardPayment) payment).setCredidCardValidationNumber(order.getPayment().get("creditcard_card_cvv"));
            ((CreditCardPayment) payment).setCreditCardNumber(order.getPayment().get("creditcard_card_number"));
            ((CreditCardPayment) payment).setExpirationMonth(order.getPayment().get("creditcard_card_expirationmonth"));
            ((CreditCardPayment) payment).setExpirationYear(order.getPayment().get("creditcard_card_expirationyear"));
            Map<String, String> paymentMetaData = order.getPayment();
            payment.setPaymentMetaData(paymentMetaData);
            payment.setPaymentType(PaymentType.valueOf(paymentType));
            payment.setAmount(order.getOrderTotalSummary().getTotal());
            payment.setModuleName(order.getPaymentModule());
            payment.setCurrency(modelOrder.getCurrency());
            CreditCardType creditCardType = null;
            String cardType = order.getPayment().get("creditcard_card_type");
            // supported credit cards
            if (CreditCardType.AMEX.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.AMEX;
            } else if (CreditCardType.VISA.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.VISA;
            } else if (CreditCardType.MASTERCARD.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.MASTERCARD;
            } else if (CreditCardType.DINERS.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.DINERS;
            } else if (CreditCardType.DISCOVERY.name().equalsIgnoreCase(cardType)) {
                creditCardType = CreditCardType.DISCOVERY;
            }
            ((CreditCardPayment) payment).setCreditCard(creditCardType);
            if (creditCardType != null) {
                CreditCard cc = new CreditCard();
                cc.setCardType(creditCardType);
                cc.setCcCvv(((CreditCardPayment) payment).getCredidCardValidationNumber());
                cc.setCcOwner(((CreditCardPayment) payment).getCardOwner());
                cc.setCcExpires(((CreditCardPayment) payment).getExpirationMonth() + "-" + ((CreditCardPayment) payment).getExpirationYear());
                // hash credit card number
                if (!StringUtils.isBlank(cc.getCcNumber())) {
                    String maskedNumber = CreditCardUtils.maskCardNumber(order.getPayment().get("creditcard_card_number"));
                    cc.setCcNumber(maskedNumber);
                    modelOrder.setCreditCard(cc);
                }
            }
        }
        if (PaymentType.PAYPAL.name().equals(paymentType)) {
            // check for previous transaction
            if (transaction == null) {
                throw new ServiceException("payment.error");
            }
            payment = new com.salesmanager.core.model.payments.PaypalPayment();
            ((com.salesmanager.core.model.payments.PaypalPayment) payment).setPayerId(transaction.getTransactionDetails().get("PAYERID"));
            ((com.salesmanager.core.model.payments.PaypalPayment) payment).setPaymentToken(transaction.getTransactionDetails().get("TOKEN"));
        }
        modelOrder.setShoppingCartCode(shoppingCartCode);
        modelOrder.setPaymentModuleCode(order.getPaymentModule());
        payment.setModuleName(order.getPaymentModule());
        if (transaction != null) {
            orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, store);
        } else {
            orderService.processOrder(modelOrder, customer, order.getShoppingCartItems(), summary, payment, transaction, store);
        }
        return modelOrder;
    } catch (ServiceException se) {
        // may be invalid credit card
        throw se;
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Address(com.salesmanager.shop.model.customer.address.Address) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) OrderProductPopulator(com.salesmanager.shop.populator.order.OrderProductPopulator) ReadableOrderProductPopulator(com.salesmanager.shop.populator.order.ReadableOrderProductPopulator) HashMap(java.util.HashMap) PersistableCustomer(com.salesmanager.shop.model.customer.PersistableCustomer) OrderTotalSummary(com.salesmanager.core.model.order.OrderTotalSummary) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) ShippingProduct(com.salesmanager.core.model.shipping.ShippingProduct) PersistableOrderProduct(com.salesmanager.shop.model.order.PersistableOrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ReadableOrderProduct(com.salesmanager.shop.model.order.ReadableOrderProduct) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) ShopOrder(com.salesmanager.shop.model.order.ShopOrder) Order(com.salesmanager.core.model.order.Order) CreditCardType(com.salesmanager.core.model.payments.CreditCardType) Date(java.util.Date) LocalDate(java.time.LocalDate) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) CreditCardPayment(com.salesmanager.core.model.payments.CreditCardPayment) Payment(com.salesmanager.core.model.payments.Payment) ServiceException(com.salesmanager.core.business.exception.ServiceException) ShoppingCartItem(com.salesmanager.core.model.shoppingcart.ShoppingCartItem) ReadableOrderStatusHistory(com.salesmanager.shop.model.order.history.ReadableOrderStatusHistory) PersistableOrderStatusHistory(com.salesmanager.shop.model.order.history.PersistableOrderStatusHistory) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) OrderTotal(com.salesmanager.shop.model.order.total.OrderTotal)

Example 3 with CreditCard

use of com.salesmanager.core.model.order.payment.CreditCard in project shopizer by shopizer-ecommerce.

the class OrderTest method getMerchantOrders.

@Test
public void getMerchantOrders() throws ServiceException {
    Currency currency = currencyService.getByCode(USD_CURRENCY_CODE);
    Country country = countryService.getByCode("US");
    Zone zone = zoneService.getByCode("VT");
    Language en = languageService.getByCode("en");
    MerchantStore merchant = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
    /**
     * Create a customer *
     */
    Customer customer = new Customer();
    customer.setMerchantStore(merchant);
    customer.setDefaultLanguage(en);
    customer.setEmailAddress("email@email.com");
    customer.setPassword("-1999");
    customer.setNick("My New nick");
    customer.setCompany(" Apple");
    customer.setGender(CustomerGender.M);
    customer.setDateOfBirth(new Date());
    Billing billing = new Billing();
    billing.setAddress("Billing address");
    billing.setCity("Billing city");
    billing.setCompany("Billing company");
    billing.setCountry(country);
    billing.setFirstName("Carl");
    billing.setLastName("Samson");
    billing.setPostalCode("Billing postal code");
    billing.setState("Billing state");
    billing.setZone(zone);
    Delivery delivery = new Delivery();
    delivery.setAddress("Shipping address");
    delivery.setCountry(country);
    delivery.setZone(zone);
    customer.setBilling(billing);
    customer.setDelivery(delivery);
    customerService.create(customer);
    // create a product with attributes
    /**
     * CATALOG CREATION *
     */
    ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
    /**
     * Create the category
     */
    Category shirts = new Category();
    shirts.setMerchantStore(merchant);
    shirts.setCode("shirts");
    CategoryDescription shirtsEnglishDescription = new CategoryDescription();
    shirtsEnglishDescription.setName("Shirts");
    shirtsEnglishDescription.setCategory(shirts);
    shirtsEnglishDescription.setLanguage(en);
    Set<CategoryDescription> descriptions = new HashSet<CategoryDescription>();
    descriptions.add(shirtsEnglishDescription);
    shirts.setDescriptions(descriptions);
    categoryService.create(shirts);
    /**
     * Create a manufacturer
     */
    Manufacturer addidas = new Manufacturer();
    addidas.setMerchantStore(merchant);
    addidas.setCode("addidas");
    ManufacturerDescription addidasDesc = new ManufacturerDescription();
    addidasDesc.setLanguage(en);
    addidasDesc.setManufacturer(addidas);
    addidasDesc.setName("Addidas");
    addidas.getDescriptions().add(addidasDesc);
    manufacturerService.create(addidas);
    /**
     * Create an option
     */
    ProductOption option = new ProductOption();
    option.setMerchantStore(merchant);
    option.setCode("color");
    option.setProductOptionType(ProductOptionType.Radio.name());
    ProductOptionDescription optionDescription = new ProductOptionDescription();
    optionDescription.setLanguage(en);
    optionDescription.setName("Color");
    optionDescription.setDescription("Item color");
    optionDescription.setProductOption(option);
    option.getDescriptions().add(optionDescription);
    productOptionService.saveOrUpdate(option);
    /**
     * first option value *
     */
    ProductOptionValue white = new ProductOptionValue();
    white.setMerchantStore(merchant);
    white.setCode("white");
    ProductOptionValueDescription whiteDescription = new ProductOptionValueDescription();
    whiteDescription.setLanguage(en);
    whiteDescription.setName("White");
    whiteDescription.setDescription("White color");
    whiteDescription.setProductOptionValue(white);
    white.getDescriptions().add(whiteDescription);
    productOptionValueService.saveOrUpdate(white);
    ProductOptionValue black = new ProductOptionValue();
    black.setMerchantStore(merchant);
    black.setCode("black");
    /**
     * second option value *
     */
    ProductOptionValueDescription blackDesc = new ProductOptionValueDescription();
    blackDesc.setLanguage(en);
    blackDesc.setName("Black");
    blackDesc.setDescription("Black color");
    blackDesc.setProductOptionValue(black);
    black.getDescriptions().add(blackDesc);
    productOptionValueService.saveOrUpdate(black);
    /**
     * Create a complex product
     */
    Product product = new Product();
    product.setProductHeight(new BigDecimal(4));
    product.setProductLength(new BigDecimal(3));
    product.setProductWidth(new BigDecimal(1));
    product.setSku("TB12345");
    product.setManufacturer(addidas);
    product.setType(generalType);
    product.setMerchantStore(merchant);
    // Product description
    ProductDescription description = new ProductDescription();
    description.setName("Short sleeves shirt");
    description.setLanguage(en);
    description.setProduct(product);
    product.getDescriptions().add(description);
    product.getCategories().add(shirts);
    // availability
    ProductAvailability availability = new ProductAvailability();
    availability.setProductDateAvailable(new Date());
    availability.setProductQuantity(100);
    availability.setRegion("*");
    // associate with product
    availability.setProduct(product);
    // price
    ProductPrice dprice = new ProductPrice();
    dprice.setDefaultPrice(true);
    dprice.setProductPriceAmount(new BigDecimal(29.99));
    dprice.setProductAvailability(availability);
    ProductPriceDescription dpd = new ProductPriceDescription();
    dpd.setName("Base price");
    dpd.setProductPrice(dprice);
    dpd.setLanguage(en);
    dprice.getDescriptions().add(dpd);
    availability.getPrices().add(dprice);
    product.getAvailabilities().add(availability);
    // attributes
    // white
    ProductAttribute whiteAttribute = new ProductAttribute();
    whiteAttribute.setProduct(product);
    whiteAttribute.setProductOption(option);
    whiteAttribute.setAttributeDefault(true);
    // no price variation
    whiteAttribute.setProductAttributePrice(new BigDecimal(0));
    // no weight variation
    whiteAttribute.setProductAttributeWeight(new BigDecimal(0));
    whiteAttribute.setProductOption(option);
    whiteAttribute.setProductOptionValue(white);
    product.getAttributes().add(whiteAttribute);
    // black
    ProductAttribute blackAttribute = new ProductAttribute();
    blackAttribute.setProduct(product);
    blackAttribute.setProductOption(option);
    // 5 + dollars
    blackAttribute.setProductAttributePrice(new BigDecimal(5));
    // no weight variation
    blackAttribute.setProductAttributeWeight(new BigDecimal(0));
    blackAttribute.setProductOption(option);
    blackAttribute.setProductOptionValue(black);
    product.getAttributes().add(blackAttribute);
    productService.create(product);
    /**
     * Create an order *
     */
    Order order = new Order();
    /**
     * payment details *
     */
    CreditCard creditCard = new CreditCard();
    creditCard.setCardType(CreditCardType.VISA);
    creditCard.setCcCvv("123");
    creditCard.setCcExpires("12/30/2020");
    creditCard.setCcNumber("123456789");
    creditCard.setCcOwner("ccOwner");
    order.setCreditCard(creditCard);
    /**
     * order core attributes *
     */
    order.setDatePurchased(new Date());
    order.setCurrency(currency);
    order.setMerchant(merchant);
    order.setLastModified(new Date());
    // no price variation because of the currency
    order.setCurrencyValue(new BigDecimal(1));
    order.setCustomerId(1L);
    order.setDelivery(delivery);
    order.setIpAddress("ipAddress");
    order.setMerchant(merchant);
    order.setOrderDateFinished(new Date());
    order.setPaymentType(PaymentType.CREDITCARD);
    order.setPaymentModuleCode("payment Module Code");
    order.setShippingModuleCode("UPS");
    order.setStatus(OrderStatus.ORDERED);
    order.setCustomerAgreement(true);
    order.setConfirmedAddress(true);
    order.setTotal(dprice.getProductPriceAmount());
    order.setCustomerEmailAddress(customer.getEmailAddress());
    order.setBilling(billing);
    order.setDelivery(delivery);
    /**
     * ORDER PRODUCT *
     */
    // OrderProduct
    OrderProduct oproduct = new OrderProduct();
    oproduct.setDownloads(null);
    oproduct.setOneTimeCharge(dprice.getProductPriceAmount());
    oproduct.setOrder(order);
    oproduct.setProductName(description.getName());
    oproduct.setProductQuantity(1);
    oproduct.setSku(product.getSku());
    // set order product price
    OrderProductPrice orderProductPrice = new OrderProductPrice();
    // default price (same as default product price)
    orderProductPrice.setDefaultPrice(true);
    orderProductPrice.setOrderProduct(oproduct);
    orderProductPrice.setProductPrice(dprice.getProductPriceAmount());
    orderProductPrice.setProductPriceCode(ProductPriceType.ONE_TIME.name());
    oproduct.getPrices().add(orderProductPrice);
    // order product attribute
    OrderProductAttribute orderProductAttribute = new OrderProductAttribute();
    orderProductAttribute.setOrderProduct(oproduct);
    // no extra charge
    orderProductAttribute.setProductAttributePrice(new BigDecimal("0.00"));
    orderProductAttribute.setProductAttributeName(whiteDescription.getName());
    orderProductAttribute.setProductOptionId(option.getId());
    orderProductAttribute.setProductOptionValueId(white.getId());
    oproduct.getOrderAttributes().add(orderProductAttribute);
    order.getOrderProducts().add(oproduct);
    /**
     * ORDER TOTAL *
     */
    OrderTotal subTotal = new OrderTotal();
    subTotal.setOrder(order);
    subTotal.setOrderTotalCode(Constants.OT_SUBTOTAL_MODULE_CODE);
    subTotal.setSortOrder(0);
    subTotal.setTitle("Sub Total");
    subTotal.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(subTotal);
    OrderTotal total = new OrderTotal();
    total.setOrder(order);
    total.setOrderTotalCode(Constants.OT_TOTAL_MODULE_CODE);
    total.setSortOrder(1);
    total.setTitle("Total");
    total.setValue(dprice.getProductPriceAmount());
    order.getOrderTotal().add(total);
    /**
     * ORDER HISTORY *
     */
    // create a log entry in order history
    OrderStatusHistory history = new OrderStatusHistory();
    history.setOrder(order);
    history.setDateAdded(new Date());
    history.setStatus(OrderStatus.ORDERED);
    history.setComments("We received your order");
    order.getOrderHistory().add(history);
    /**
     * CREATE ORDER *
     */
    orderService.create(order);
    /**
     * SEARCH ORDERS *
     */
    OrderCriteria criteria = new OrderCriteria();
    criteria.setStartIndex(0);
    criteria.setMaxCount(10);
    OrderList ordserList = orderService.listByStore(merchant, criteria);
    Assert.assertNotNull(ordserList);
    Assert.assertNotNull("Merchant Orders are null.", ordserList.getOrders());
    Assert.assertTrue("Merchant Orders count is not one.", (ordserList.getOrders() != null && ordserList.getOrders().size() == 1));
}
Also used : Category(com.salesmanager.core.model.catalog.category.Category) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Customer(com.salesmanager.core.model.customer.Customer) OrderProduct(com.salesmanager.core.model.order.orderproduct.OrderProduct) Product(com.salesmanager.core.model.catalog.product.Product) ProductPrice(com.salesmanager.core.model.catalog.product.price.ProductPrice) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) ProductAttribute(com.salesmanager.core.model.catalog.product.attribute.ProductAttribute) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) ProductOptionDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription) ProductOptionValue(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue) Language(com.salesmanager.core.model.reference.language.Language) ProductAvailability(com.salesmanager.core.model.catalog.product.availability.ProductAvailability) Currency(com.salesmanager.core.model.reference.currency.Currency) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ProductPriceDescription(com.salesmanager.core.model.catalog.product.price.ProductPriceDescription) HashSet(java.util.HashSet) ProductOption(com.salesmanager.core.model.catalog.product.attribute.ProductOption) Order(com.salesmanager.core.model.order.Order) Zone(com.salesmanager.core.model.reference.zone.Zone) ProductType(com.salesmanager.core.model.catalog.product.type.ProductType) OrderCriteria(com.salesmanager.core.model.order.OrderCriteria) Date(java.util.Date) BigDecimal(java.math.BigDecimal) CreditCard(com.salesmanager.core.model.order.payment.CreditCard) Billing(com.salesmanager.core.model.common.Billing) OrderProductPrice(com.salesmanager.core.model.order.orderproduct.OrderProductPrice) OrderProductAttribute(com.salesmanager.core.model.order.orderproduct.OrderProductAttribute) Country(com.salesmanager.core.model.reference.country.Country) ManufacturerDescription(com.salesmanager.core.model.catalog.product.manufacturer.ManufacturerDescription) CategoryDescription(com.salesmanager.core.model.catalog.category.CategoryDescription) Delivery(com.salesmanager.core.model.common.Delivery) ProductDescription(com.salesmanager.core.model.catalog.product.description.ProductDescription) OrderList(com.salesmanager.core.model.order.OrderList) OrderTotal(com.salesmanager.core.model.order.OrderTotal) OrderStatusHistory(com.salesmanager.core.model.order.orderstatus.OrderStatusHistory) ProductOptionValueDescription(com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription) Test(org.junit.Test)

Aggregations

OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)3 OrderStatusHistory (com.salesmanager.core.model.order.orderstatus.OrderStatusHistory)3 CreditCard (com.salesmanager.core.model.order.payment.CreditCard)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 Product (com.salesmanager.core.model.catalog.product.Product)2 ProductAvailability (com.salesmanager.core.model.catalog.product.availability.ProductAvailability)2 Customer (com.salesmanager.core.model.customer.Customer)2 Order (com.salesmanager.core.model.order.Order)2 Country (com.salesmanager.core.model.reference.country.Country)2 Currency (com.salesmanager.core.model.reference.currency.Currency)2 Zone (com.salesmanager.core.model.reference.zone.Zone)2 Date (java.util.Date)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 Category (com.salesmanager.core.model.catalog.category.Category)1 CategoryDescription (com.salesmanager.core.model.catalog.category.CategoryDescription)1 ProductAttribute (com.salesmanager.core.model.catalog.product.attribute.ProductAttribute)1 ProductOption (com.salesmanager.core.model.catalog.product.attribute.ProductOption)1 ProductOptionDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionDescription)1 ProductOptionValue (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValue)1 ProductOptionValueDescription (com.salesmanager.core.model.catalog.product.attribute.ProductOptionValueDescription)1