Debug.logError("Invalid Google Chechout Merchant settings, check your configuration!", module);
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "GoogleCheckoutConfigurationError", locale));
}
// the checkout request object
CheckoutShoppingCartRequest req = new CheckoutShoppingCartRequest(mInfo, 300);
String requestAuthStr = googleCfg.getString("requestAuthDetails");
if (requestAuthStr == null) {
requestAuthStr = "Y";
}
boolean requestAuth = "Y".equalsIgnoreCase(requestAuthStr) ? true : false;
req.setRequestInitialAuthDetails(requestAuth); // send the auth notification
String sendPromoItemStr = googleCfg.getString("sendPromoItems");
if (sendPromoItemStr == null) {
sendPromoItemStr = "Y";
}
boolean sendPromoItems = "Y".equalsIgnoreCase(sendPromoItemStr) ? true : false;
// add the items
List<ShoppingCartItem> items = cart.items();
for (ShoppingCartItem item : items) {
if (!item.getIsPromo() || sendPromoItems) {
Item i = new Item();
i.setItemName(item.getName());
i.setItemDescription(item.getDescription());
i.setMerchantItemId(item.getProductId());
i.setQuantity(item.getQuantity().intValue());
i.setUnitPriceAmount(item.getBasePrice().floatValue());
i.setUnitPriceCurrency(cart.getCurrency());
//i.setItemWeight(item.getWeight().floatValue()); // must convert weight to Lb
if (!item.taxApplies()) {
i.setTaxTableSelector("tax_exempt");
}
req.addItem(i);
}
}
// flow support URLs
String contShoppingUrl = UtilProperties.getPropertyValue("googleCheckout.properties", "continueShoppingUrl");
String editCartUrl = UtilProperties.getPropertyValue("googleCheckout.properties", "editCartUrl");
req.setContinueShoppingUrl(contShoppingUrl);
req.setEditCartUrl(editCartUrl);
// setup exempt tax support
TaxArea exemptArea = new TaxArea();
exemptArea.addWorldArea();
req.addAlternateTaxRule("tax_exempt", true, 0, exemptArea);
// setup default tax table
// TODO: implement this; for now use the tax table in Google Checkout Settings
// setup shipping options support
List<GenericValue> shippingOptions = null;
try {
shippingOptions = delegator.findByAnd("GoogleCoShippingMethod", UtilMisc.toMap("productStoreId", productStoreId));
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
if (UtilValidate.isNotEmpty(shippingOptions)) {
for (GenericValue option : shippingOptions) {
String shippingName = option.getString("shipmentMethodName");
Double amount = option.getDouble("amount");
if (amount == null) {
amount = 0.0;
}
if ("GOOGLE_FLAT_RATE".equals(option.getString("methodTypeEnumId"))) {
req.addFlatRateShippingMethod(shippingName, amount.floatValue());
} else if ("GOOGLE_MERCHANT_CALC".equals(option.getString("methodTypeEnumId"))) {
req.addMerchantCalculatedShippingMethod(shippingName, amount.floatValue());
} else if ("GOOGLE_PICKUP".equals(option.getString("methodTypeEnumId"))) {
req.addPickupShippingMethod(shippingName, amount.floatValue());
} else if ("GOOGLE_CARRIER_CALC".equals(option.getString("methodTypeEnumId"))) {
String carrierPartyId = option.getString("carrierPartyId");
Double additionalAmount = option.getDouble("additionalAmount");
Double additionalPercent = option.getDouble("additionalPercent");
if (additionalAmount == null) {
additionalAmount = 0.0;
}
if (additionalPercent == null) {
additionalPercent = 0.0;
}
String shippingCompany = null;
if ("ups".equalsIgnoreCase(carrierPartyId)) {
shippingCompany = "UPS";
} else if ("fedex".equalsIgnoreCase(carrierPartyId)) {
shippingCompany = "FedEx";
} else if ("usps".equalsIgnoreCase(carrierPartyId)) {
shippingCompany = "USPS";
}
if (shippingCompany == null) {
return ServiceUtil.returnError(UtilProperties.getMessage(resource, "GoogleCheckoutShippingConfigurationInvalid", locale));
}
req.addCarrierCalculatedShippingOption(amount.floatValue(), shippingCompany, CarrierPickup.REGULAR_PICKUP, shippingName, additionalAmount.floatValue(), additionalPercent.floatValue());
}
}
}
// merchant stuff
String acceptCouponStr = googleCfg.getString("acceptCoupons");
if (acceptCouponStr == null) {
acceptCouponStr = "N";
}
boolean acceptCoupons = "Y".equalsIgnoreCase(acceptCouponStr) ? true : false;
String acceptCertStr = googleCfg.getString("acceptGiftCerts");
if (acceptCertStr == null) {
acceptCertStr = "N";
}
boolean acceptGiftCerts = "Y".equalsIgnoreCase(acceptCertStr) ? true : false;
if (acceptCoupons || acceptGiftCerts) {
req.setAcceptMerchantCoupons(acceptCoupons);
req.setAcceptMerchantGiftCertificates(acceptGiftCerts);
// TODO: merchant calc support needs to be implemented if these are ever TRUE
}
String requestPhoneStr = googleCfg.getString("requestPhone");
if (requestPhoneStr == null) {
requestPhoneStr = "Y";
}
boolean requestPhone = "Y".equalsIgnoreCase(requestPhoneStr) ? true : false;
req.setRequestBuyerPhoneNumber(requestPhone);
// send the request
CheckoutResponse resp = null;
try {
Debug.logInfo("Sending XML to Google:\n\n" + req.getXmlPretty() + "\n\n", module);
resp = req.send();
} catch (CheckoutException e) {
Debug.logError(e, module);
return ServiceUtil.returnError(e.getMessage());
}
if (resp == null) {