Search in sources :

Example 1 with Address

use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutTest method buildAddress.

private Address buildAddress() {
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    State state = new StateImpl();
    state.setAbbreviation("ALL");
    state.setName("ALL");
    address.setState(state);
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    state.setCountry(country);
    address.setCountry(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    address.setIsoCountryAlpha2(isoCountry);
    return address;
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry)

Example 2 with Address

use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.

the class CheckoutTest method testCheckout.

@Test(groups = { "checkout" }, dependsOnGroups = { "createCartForCustomer", "testShippingInsert" }, dataProvider = "USCurrency", dataProviderClass = BroadleafCurrencyProvider.class)
@Transactional
public void testCheckout(BroadleafCurrency usCurrency) throws Exception {
    HashMap currencyConsiderationContext = new HashMap();
    currencyConsiderationContext.put("aa", "bb");
    CurrencyConversionContext.setCurrencyConversionContext(currencyConsiderationContext);
    CurrencyConversionContext.setCurrencyConversionService(new CurrencyConversionService() {

        @Override
        public Money convertCurrency(Money source, Currency destinationCurrency, int destinationScale) {
            return source;
        }
    });
    String userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    Order order = orderService.createNewCartForCustomer(customer);
    usCurrency = currencyService.save(usCurrency);
    order.setCurrency(usCurrency);
    Address address = buildAddress();
    FulfillmentGroup group = buildFulfillmentGroup(order, address);
    addSampleItemToOrder(order, group);
    order.setTotalShipping(new Money(0D));
    addPaymentToOrder(order, address);
    // execute pricing for this order
    orderService.save(order, true);
    CheckoutResponse response = checkoutService.performCheckout(order);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Address(org.broadleafcommerce.profile.core.domain.Address) HashMap(java.util.HashMap) Customer(org.broadleafcommerce.profile.core.domain.Customer) Currency(java.util.Currency) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) CurrencyConversionService(org.broadleafcommerce.common.money.CurrencyConversionService) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Address

use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceTest method testOrderItemOfferWithGiftWrap.

@Test(groups = { "testOffersWithGiftWrap" }, dependsOnGroups = { "testShippingInsert" })
@Transactional
public void testOrderItemOfferWithGiftWrap() throws PricingException {
    Order order = createTestOrderWithOfferAndGiftWrap();
    OfferDataItemProvider dataProvider = new OfferDataItemProvider();
    List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))", "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))");
    for (Offer offer : offers) {
        offer.setName("testOffer");
        // //reset the offer is the targets and qualifiers, otherwise the reference is incorrect
        // for (OfferItemCriteria criteria : offer.getTargetItemCriteria()) {
        // criteria.setTargetOffer(null);
        // }
        // for (OfferItemCriteria criteria : offer.getQualifyingItemCriteria()) {
        // criteria.setQualifyingOffer(null);
        // }
        offerService.save(offer);
    }
    order = orderService.save(order, false);
    Set<OrderMultishipOption> options = new HashSet<OrderMultishipOption>();
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        Address address = fg.getAddress();
        for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
            for (int j = 0; j < fgItem.getQuantity(); j++) {
                OrderMultishipOption option = new OrderMultishipOptionImpl();
                option.setOrder(order);
                option.setAddress(address);
                option.setOrderItem(fgItem.getOrderItem());
                option.setFulfillmentOption(fg.getFulfillmentOption());
                options.add(option);
            }
        }
    }
    for (OrderMultishipOption option : options) {
        orderMultishipOptionService.save(option);
    }
    order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
    assert order.getOrderItems().size() == 3;
    assert order.getTotalTax().equals(new Money("2.00"));
    assert order.getTotalShipping().equals(new Money("8.50"));
    assert order.getSubTotal().equals(new Money("40.00"));
    assert order.getTotal().equals(new Money("50.50"));
    boolean foundGiftItemAndCorrectQuantity = false;
    for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem instanceof GiftWrapOrderItem && ((GiftWrapOrderItem) orderItem).getWrappedItems().size() == 1) {
            foundGiftItemAndCorrectQuantity = true;
            break;
        }
    }
    assert foundGiftItemAndCorrectQuantity;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Address

use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.

the class DefaultCustomerPaymentGatewayService method populateCustomerPayment.

protected void populateCustomerPayment(CustomerPayment customerPayment, PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) {
    Map<String, String> responseMap = responseDTO.getResponseMap();
    customerPayment.setPaymentGatewayType(config.getGatewayType());
    customerPayment.setPaymentType(responseDTO.getPaymentType());
    customerPayment.setAdditionalFields(responseMap);
    dtoToEntityService.populateCustomerPaymentToken(responseDTO, customerPayment);
    if (responseDTO.getBillTo() != null && responseDTO.getBillTo().addressPopulated()) {
        Address billingAddress = addressService.create();
        dtoToEntityService.populateAddressInfo(responseDTO.getBillTo(), billingAddress);
        customerPayment.setBillingAddress(billingAddress);
    }
    if (responseDTO.getCreditCard() != null && responseDTO.getCreditCard().creditCardPopulated()) {
        if (responseDTO.getCreditCard().getCreditCardHolderName() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.NAME_ON_CARD.getType(), responseDTO.getCreditCard().getCreditCardHolderName());
        }
        if (responseDTO.getCreditCard().getCreditCardLastFour() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.LAST_FOUR.getType(), responseDTO.getCreditCard().getCreditCardLastFour());
        }
        if (responseDTO.getCreditCard().getCreditCardType() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.CARD_TYPE.getType(), responseDTO.getCreditCard().getCreditCardType());
        }
        if (responseDTO.getCreditCard().getCreditCardExpDate() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_DATE.getType(), responseDTO.getCreditCard().getCreditCardExpDate());
        }
        if (responseDTO.getCreditCard().getCreditCardExpMonth() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_MONTH.getType(), responseDTO.getCreditCard().getCreditCardExpMonth());
        }
        if (responseDTO.getCreditCard().getCreditCardExpYear() != null) {
            customerPayment.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_YEAR.getType(), responseDTO.getCreditCard().getCreditCardExpYear());
        }
    }
    String isDefault = responseMap.get("isDefault");
    customerPayment.setIsDefault(Boolean.parseBoolean(isDefault));
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address)

Example 5 with Address

use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.

the class DefaultPaymentGatewayCheckoutService method applyPaymentToOrder.

@Override
public Long applyPaymentToOrder(PaymentResponseDTO responseDTO, PaymentGatewayConfiguration config) {
    // Payments can ONLY be parsed into Order Payments if they are 'valid'
    if (!responseDTO.isValid()) {
        throw new IllegalArgumentException("Invalid payment responses cannot be parsed into the order payment domain");
    }
    if (config == null) {
        throw new IllegalArgumentException("Config service cannot be null");
    }
    Long orderId = Long.parseLong(responseDTO.getOrderId());
    Order order = orderService.findOrderById(orderId);
    if (!OrderStatus.IN_PROCESS.equals(order.getStatus()) && !OrderStatus.CSR_OWNED.equals(order.getStatus()) && !OrderStatus.QUOTE.equals(order.getStatus())) {
        throw new IllegalArgumentException("Cannot apply another payment to an Order that is not IN_PROCESS or CSR_OWNED");
    }
    Customer customer = order.getCustomer();
    if (customer.isAnonymous()) {
        GatewayCustomerDTO<PaymentResponseDTO> gatewayCustomer = responseDTO.getCustomer();
        if (StringUtils.isEmpty(customer.getFirstName()) && gatewayCustomer != null) {
            customer.setFirstName(gatewayCustomer.getFirstName());
        }
        if (StringUtils.isEmpty(customer.getLastName()) && gatewayCustomer != null) {
            customer.setLastName(gatewayCustomer.getLastName());
        }
        if (StringUtils.isEmpty(customer.getEmailAddress()) && gatewayCustomer != null) {
            customer.setEmailAddress(gatewayCustomer.getEmail());
        }
    }
    // If the gateway sends back an email address and the order does not contain one, set it.
    GatewayCustomerDTO<PaymentResponseDTO> gatewayCustomer = responseDTO.getCustomer();
    if (order.getEmailAddress() == null && gatewayCustomer != null) {
        order.setEmailAddress(gatewayCustomer.getEmail());
    }
    // If the gateway sends back Shipping Information, we will save that to the first shippable fulfillment group.
    dtoToEntityService.populateShippingInfo(responseDTO, order);
    // ALWAYS create a new order payment for the payment that comes in. Invalid payments should be cleaned up by
    // invoking {@link #markPaymentAsInvalid}.
    OrderPayment payment = orderPaymentService.create();
    payment.setType(responseDTO.getPaymentType());
    payment.setPaymentGatewayType(responseDTO.getPaymentGatewayType());
    payment.setAmount(responseDTO.getAmount());
    // If this gateway does not support multiple payments then mark all of the existing payments
    // as invalid before adding the new one
    List<OrderPayment> paymentsToInvalidate = new ArrayList<OrderPayment>();
    Address tempBillingAddress = null;
    if (!config.handlesMultiplePayments()) {
        PaymentGatewayType gateway = config.getGatewayType();
        for (OrderPayment p : order.getPayments()) {
            // - The payment being added has the same gateway type of an existing one.
            if (PaymentGatewayType.TEMPORARY.equals(p.getGatewayType()) || (p.isFinalPayment() && payment.isFinalPayment()) || (p.getGatewayType() != null && p.getGatewayType().equals(gateway))) {
                paymentsToInvalidate.add(p);
                if (PaymentGatewayType.TEMPORARY.equals(p.getGatewayType())) {
                    tempBillingAddress = p.getBillingAddress();
                }
            }
        }
    }
    for (OrderPayment invalid : paymentsToInvalidate) {
        // 2
        markPaymentAsInvalid(invalid.getId());
    }
    // The billing address that will be saved on the order will be parsed off the
    // Response DTO sent back from the Gateway as it may have Address Verification or Standardization.
    // If you do not wish to use the Billing Address coming back from the Gateway, you can override the
    // populateBillingInfo() method or set the useBillingAddressFromGateway property.
    dtoToEntityService.populateBillingInfo(responseDTO, payment, tempBillingAddress, isUseBillingAddressFromGateway());
    // Create the transaction for the payment
    PaymentTransaction transaction = orderPaymentService.createTransaction();
    transaction.setAmount(responseDTO.getAmount());
    transaction.setRawResponse(responseDTO.getRawResponse());
    transaction.setSuccess(responseDTO.isSuccessful());
    transaction.setType(responseDTO.getPaymentTransactionType());
    for (Entry<String, String> entry : responseDTO.getResponseMap().entrySet()) {
        transaction.getAdditionalFields().put(entry.getKey(), entry.getValue());
    }
    // Set the Credit Card Info on the Additional Fields Map
    if (responseDTO.getCreditCard() != null && responseDTO.getCreditCard().creditCardPopulated()) {
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.NAME_ON_CARD.getType(), responseDTO.getCreditCard().getCreditCardHolderName());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.CARD_TYPE.getType(), responseDTO.getCreditCard().getCreditCardType());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_DATE.getType(), responseDTO.getCreditCard().getCreditCardExpDate());
        transaction.getAdditionalFields().put(PaymentAdditionalFieldType.LAST_FOUR.getType(), responseDTO.getCreditCard().getCreditCardLastFour());
    }
    // TODO: validate that this particular type of transaction can be added to the payment (there might already
    // be an AUTHORIZE transaction, for instance)
    // Persist the order payment as well as its transaction
    payment.setOrder(order);
    transaction.setOrderPayment(payment);
    payment.addTransaction(transaction);
    payment = orderPaymentService.save(payment);
    if (transaction.getSuccess()) {
        orderService.addPaymentToOrder(order, payment, null);
    } else {
        // We will have to mark the entire payment as invalid and boot the user to re-enter their
        // billing info and payment information as there may be an error either with the billing address/or credit card
        handleUnsuccessfulTransaction(payment);
    }
    return payment.getId();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) Customer(org.broadleafcommerce.profile.core.domain.Customer) ArrayList(java.util.ArrayList) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) PaymentGatewayType(org.broadleafcommerce.common.payment.PaymentGatewayType) PaymentTransaction(org.broadleafcommerce.core.payment.domain.PaymentTransaction) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Aggregations

Address (org.broadleafcommerce.profile.core.domain.Address)37 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)15 Order (org.broadleafcommerce.core.order.domain.Order)15 Customer (org.broadleafcommerce.profile.core.domain.Customer)14 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)11 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)11 Transactional (org.springframework.transaction.annotation.Transactional)10 Test (org.testng.annotations.Test)10 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)9 Money (org.broadleafcommerce.common.money.Money)8 ArrayList (java.util.ArrayList)7 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)7 State (org.broadleafcommerce.profile.core.domain.State)7 StateImpl (org.broadleafcommerce.profile.core.domain.StateImpl)7 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)6 ISOCountryImpl (org.broadleafcommerce.common.i18n.domain.ISOCountryImpl)6 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)6 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)6 Country (org.broadleafcommerce.profile.core.domain.Country)6 CountryImpl (org.broadleafcommerce.profile.core.domain.CountryImpl)6