}
private Order formatOrder(OrderHeader orderHeader, HttpServletRequest request) {
String remoteAddr = request.getRemoteAddr();
OrderEngine orderEngine = new OrderEngine(orderHeader, null);
CreditCardInfo creditCardInfo = this.getCreditCardInfo();
Order order = new Order();
order.setStoreID(storeId);
order.setPassphrase(passphrase);
OrderAddress orderAddress = orderHeader.getCustAddress();
if (orderHeader.getBillingAddress().getCustUseAddress().equals(Constants.CUST_ADDRESS_USE_OWN)) {
orderAddress = orderHeader.getBillingAddress();
}
order.setBname(orderAddress.getCustFirstName() + " " + orderAddress.getCustLastName());
order.setBcompany("");
order.setBaddress1(orderAddress.getCustAddressLine1());
order.setBaddress2(orderAddress.getCustAddressLine2());
order.setBcity(orderAddress.getCustCityName());
order.setBprovince(orderAddress.getCustStateName());
order.setBcountry(orderAddress.getCustCountryName());
order.setBpostalcode(orderAddress.getCustZipCode());
OrderAddress shipAddress = orderHeader.getCustAddress();
if (orderHeader.getShippingAddress().getCustUseAddress().equals(Constants.CUST_ADDRESS_USE_OWN)) {
shipAddress = orderHeader.getShippingAddress();
}
else if (orderHeader.getShippingAddress().getCustUseAddress().equals(Constants.CUST_ADDRESS_USE_BILL)) {
if (orderHeader.getBillingAddress().getCustUseAddress().equals(Constants.CUST_ADDRESS_USE_OWN)) {
shipAddress = orderHeader.getBillingAddress();
}
else {
shipAddress = orderHeader.getCustAddress();
}
}
order.setSname(shipAddress.getCustFirstName() + " " + shipAddress.getCustLastName());
order.setScompany("");
order.setSaddress1(shipAddress.getCustAddressLine1());
order.setSaddress2(shipAddress.getCustAddressLine2());
order.setScity(shipAddress.getCustCityName());
order.setSprovince(shipAddress.getCustStateName());
order.setScountry(shipAddress.getCustCountryName());
order.setSpostalcode(shipAddress.getCustZipCode());
order.setPhone(orderAddress.getCustPhoneNum());
order.setFax(orderAddress.getCustFaxNum());
order.setEmail(orderHeader.getCustEmail());
order.setTax1(Format.getSimpleFloat(orderEngine.getOrderTaxTotal()));
order.setShippingTotal(Format.getSimpleFloat(orderEngine.getOrderShippingTotal()));
order.setSubtotal(Format.getSimpleFloat(orderEngine.getOrderSubTotal()));
order.setCardAction(CARDACTION_PREAUTH);
order.setPaymentType(PAYMENT_TYPE);
order.setCardNumber(creditCardInfo.getCreditCardNum());
order.setCardExpMonth(creditCardInfo.getCreditCardExpiryMonth());
if (creditCardInfo.getCreditCardExpiryYear().length() > 2) {
order.setCardExpYear(creditCardInfo.getCreditCardExpiryYear().substring(2));
}
else {
order.setCardExpYear(creditCardInfo.getCreditCardExpiryYear());
}
if (creditCardInfo.getCreditCardVerNum() != null) {
order.setCardIDNumber(creditCardInfo.getCreditCardVerNum());
}
order.setCustomerIP(remoteAddr);
return order;
}