Search in sources :

Example 21 with Address

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

the class OrderToPaymentRequestDTOServiceImpl method populateBillTo.

@Override
public void populateBillTo(Order order, PaymentRequestDTO requestDTO) {
    for (OrderPayment payment : order.getPayments()) {
        if (payment.isActive()) {
            Address billAddress = payment.getBillingAddress();
            if (billAddress != null) {
                String stateAbbr = null;
                String countryAbbr = null;
                String phone = null;
                if (StringUtils.isNotBlank(billAddress.getStateProvinceRegion())) {
                    stateAbbr = billAddress.getStateProvinceRegion();
                } else if (billAddress.getState() != null) {
                    // support legacy
                    stateAbbr = billAddress.getState().getAbbreviation();
                }
                if (billAddress.getIsoCountryAlpha2() != null) {
                    countryAbbr = billAddress.getIsoCountryAlpha2().getAlpha2();
                } else if (billAddress.getCountry() != null) {
                    // support legacy
                    countryAbbr = billAddress.getCountry().getAbbreviation();
                }
                if (billAddress.getPhonePrimary() != null) {
                    phone = billAddress.getPhonePrimary().getPhoneNumber();
                }
                NameResponse name = getName(billAddress);
                requestDTO.billTo().addressFirstName(name.firstName).addressLastName(name.lastName).addressCompanyName(billAddress.getCompanyName()).addressLine1(billAddress.getAddressLine1()).addressLine2(billAddress.getAddressLine2()).addressCityLocality(billAddress.getCity()).addressStateRegion(stateAbbr).addressPostalCode(billAddress.getPostalCode()).addressCountryCode(countryAbbr).addressPhone(phone).addressEmail(billAddress.getEmailAddress());
            }
        }
    }
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment)

Example 22 with Address

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

the class OrderToPaymentRequestDTOServiceImpl method populateShipTo.

/**
 * Uses the first shippable fulfillment group to populate the {@link PaymentRequestDTO#shipTo()} object
 * @param order the {@link Order} to get data from
 * @param requestDTO the {@link PaymentRequestDTO} that should be populated
 * @see {@link FulfillmentGroupService#getFirstShippableFulfillmentGroup(Order)}
 */
@Override
public void populateShipTo(Order order, PaymentRequestDTO requestDTO) {
    List<FulfillmentGroup> fgs = order.getFulfillmentGroups();
    if (fgs != null && fgs.size() > 0) {
        FulfillmentGroup defaultFg = fgService.getFirstShippableFulfillmentGroup(order);
        if (defaultFg != null && defaultFg.getAddress() != null) {
            Address fgAddress = defaultFg.getAddress();
            String stateAbbr = null;
            String countryAbbr = null;
            String phone = null;
            if (StringUtils.isNotBlank(fgAddress.getStateProvinceRegion())) {
                stateAbbr = fgAddress.getStateProvinceRegion();
            } else if (fgAddress.getState() != null) {
                // support legacy
                stateAbbr = fgAddress.getState().getAbbreviation();
            }
            if (fgAddress.getIsoCountryAlpha2() != null) {
                countryAbbr = fgAddress.getIsoCountryAlpha2().getAlpha2();
            } else if (fgAddress.getCountry() != null) {
                // support legacy
                countryAbbr = fgAddress.getCountry().getAbbreviation();
            }
            if (fgAddress.getPhonePrimary() != null) {
                phone = fgAddress.getPhonePrimary().getPhoneNumber();
            }
            NameResponse name = getName(fgAddress);
            requestDTO.shipTo().addressFirstName(name.firstName).addressLastName(name.lastName).addressCompanyName(fgAddress.getCompanyName()).addressLine1(fgAddress.getAddressLine1()).addressLine2(fgAddress.getAddressLine2()).addressCityLocality(fgAddress.getCity()).addressStateRegion(stateAbbr).addressPostalCode(fgAddress.getPostalCode()).addressCountryCode(countryAbbr).addressPhone(phone).addressEmail(fgAddress.getEmailAddress());
        }
    }
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 23 with Address

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

the class PaymentResponseDTOToEntityServiceImpl method populateBillingInfo.

@Override
public void populateBillingInfo(PaymentResponseDTO responseDTO, OrderPayment payment, Address tempBillingAddress, boolean isUseBillingAddressFromGateway) {
    Address billingAddress = tempBillingAddress;
    if (responseDTO.getBillTo() != null && responseDTO.getBillTo().addressPopulated() && isUseBillingAddressFromGateway) {
        billingAddress = addressService.create();
        AddressDTO<PaymentResponseDTO> billToDTO = responseDTO.getBillTo();
        populateAddressInfo(billToDTO, billingAddress);
    }
    payment.setBillingAddress(billingAddress);
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Example 24 with Address

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

the class PaymentInfoServiceTest method createTestPayment.

@Test(groups = { "testCreatePaymentInfo" }, dependsOnGroups = { "createPaymentInfo" })
@Transactional
public void createTestPayment() {
    userName = "customer1";
    OrderPayment paymentInfo = paymentInfoService.create();
    Customer customer = customerService.readCustomerByUsername(userName);
    List<CustomerAddress> addresses = customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId());
    Address address = null;
    if (!addresses.isEmpty())
        address = addresses.get(0).getAddress();
    Order salesOrder = orderService.findCartForCustomer(customer);
    paymentInfo.setBillingAddress(address);
    paymentInfo.setOrder(salesOrder);
    paymentInfo.setType(PaymentType.CREDIT_CARD);
    assert paymentInfo != null;
    paymentInfo = paymentInfoService.save(paymentInfo);
    assert paymentInfo.getId() != null;
    Long paymentInfoId = paymentInfo.getId();
    paymentInfoService.delete(paymentInfo);
    paymentInfo = paymentInfoService.readPaymentById(paymentInfoId);
    assert paymentInfo == null;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Address

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

the class PaymentInfoServiceTest method createPayment.

@Test(groups = { "createPaymentInfo" }, dataProvider = "basicPaymentInfo", dataProviderClass = PaymentInfoDataProvider.class, dependsOnGroups = { "readCustomer", "createOrder" })
@Rollback(false)
@Transactional
public void createPayment(OrderPayment payment) {
    userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    List<CustomerAddress> addresses = customerAddressDao.readActiveCustomerAddressesByCustomerId(customer.getId());
    Address address = null;
    if (!addresses.isEmpty())
        address = addresses.get(0).getAddress();
    Order salesOrder = orderService.createNewCartForCustomer(customer);
    payment.setBillingAddress(address);
    payment.setOrder(salesOrder);
    payment.setType(PaymentType.CREDIT_CARD);
    assert payment.getId() == null;
    payment = paymentInfoService.save(payment);
    assert payment.getId() != null;
    this.paymentInfo = payment;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

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