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());
}
}
}
}
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());
}
}
}
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);
}
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;
}
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;
}
Aggregations