payment.setBillingAddress(billingAddress);
}
protected void populateShippingInfo(PaymentResponseDTO responseDTO, Order order) {
FulfillmentGroup shippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(order);
Address shippingAddress = null;
if (responseDTO.getShipTo() != null && shippableFulfillmentGroup != null) {
shippingAddress = addressService.create();
AddressDTO<PaymentResponseDTO> shipToDTO = responseDTO.getShipTo();
shippingAddress.setFirstName(shipToDTO.getAddressFirstName());
shippingAddress.setLastName(shipToDTO.getAddressLastName());
shippingAddress.setAddressLine1(shipToDTO.getAddressLine1());
shippingAddress.setAddressLine2(shipToDTO.getAddressLine2());
shippingAddress.setCity(shipToDTO.getAddressCityLocality());
State state = null;
if(shipToDTO.getAddressStateRegion() != null) {
state = stateService.findStateByAbbreviation(shipToDTO.getAddressStateRegion());
}
if (state == null) {
LOG.warn("The given state from the response: " + shipToDTO.getAddressStateRegion() + " could not be found"
+ " as a state abbreviation in BLC_STATE");
}
shippingAddress.setState(state);
shippingAddress.setPostalCode(shipToDTO.getAddressPostalCode());
Country country = null;
if (shipToDTO.getAddressCountryCode() != null) {
country = countryService.findCountryByAbbreviation(shipToDTO.getAddressCountryCode());
}
if (country == null) {
LOG.warn("The given country from the response: " + shipToDTO.getAddressCountryCode() + " could not be found"
+ " as a country abbreviation in BLC_COUNTRY");
}
shippingAddress.setCountry(country);
if (shipToDTO.getAddressPhone() != null) {
Phone shippingPhone = phoneService.create();
shippingPhone.setPhoneNumber(shipToDTO.getAddressPhone());
shippingAddress.setPhonePrimary(shippingPhone);
}
shippableFulfillmentGroup = fulfillmentGroupService.findFulfillmentGroupById(shippableFulfillmentGroup.getId());
if (shippableFulfillmentGroup != null) {
shippableFulfillmentGroup.setAddress(shippingAddress);
fulfillmentGroupService.save(shippableFulfillmentGroup);
}
}
}