Examples of AnonymousAddress


Examples of com.google.checkout.AnonymousAddress

    BigDecimal defaultTax = JavaCommerce.getConfiguration().getBigDecimal(CONFIG_GOOGLE_CALC_TAX_DEFAULT, DEFAULT_TAX);
    BigDecimal defaultShipping = JavaCommerce.getConfiguration().getBigDecimal(CONFIG_GOOGLE_CALC_SHIPPING_DEFAULT, DEFAULT_SHIPPING);
   
    // Addresses is always passed according to the XSD.
    for (int i = 0; i < _callback.getCalculate().getAddresses().getAnonymousAddressCount(); i++) {
      AnonymousAddress address = _callback.getCalculate().getAddresses().getAnonymousAddress(i);
      TotalTax totalTax = null;
      if (calcTax) {
        // Get the tax rate
        BigDecimal taxRate = JavaCommerce.getConfiguration().getBigDecimal(new StringBuffer(CONFIG_GOOGLE_CALC_TAX).append(".").append(address.getRegion()).toString(), defaultTax);
        // Calculate Tax
        BigDecimal tax = taxRate.multiply(orderTotal);
        tax = tax.setScale(2, BigDecimal.ROUND_UP);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Calculated tax of [" + tax + "] with rate of [" + taxRate + "]");
        }
        totalTax = new TotalTax();
        totalTax.setContent(tax);
        totalTax.setCurrency(DEFAULT_CURRENCY);
      }
      if (calcShipping) {
        for (int j = 0; j < _callback.getCalculate().getShipping().getMethodCount(); j++) {
          Result result = new Result();
          result.setAddressId(address.getId());
          result.setShippable(true);
          Method method = _callback.getCalculate().getShipping().getMethod(j);
          result.setShippingName(method.getName());
          // Load Shipping, read order:
          // 1. google.calculation.shipping.{method name}.{address region}
          // 2. google.calculation.shipping.{method name}.default
          // 3. google.calculation.shipping.default
          BigDecimal shipping = JavaCommerce.getConfiguration().getBigDecimal(new StringBuffer(CONFIG_GOOGLE_CALC_SHIPPING).append(".").append(method.getName()).append(".").append(address.getRegion()).toString(), JavaCommerce.getConfiguration().getBigDecimal(new StringBuffer(CONFIG_GOOGLE_CALC_SHIPPING).append(".").append(method.getName()).append(DOT_DEFAULT).toString(), defaultShipping));
          shipping = shipping.setScale(2, BigDecimal.ROUND_UP);
          if (LOG.isDebugEnabled()) {
            LOG.debug("Calculated shipping of [" + shipping + "] for [" + method.getName() + "]");
          }
          ShippingRate rate = new ShippingRate();
          rate.setContent(shipping);
          rate.setCurrency(DEFAULT_CURRENCY);
          result.setShippingRate(rate);
          if (calcTax) {
            result.setTotalTax(totalTax);
          }
          results.addResult(result);
        }
      }
      else if (calcTax) {
        Result result = new Result();
        result.setAddressId(address.getId());
        result.setTotalTax(totalTax);
        results.addResult(result);
      }
    }
    return mcResults;
View Full Code Here

Examples of com.google.checkout.merchantcalculation.AnonymousAddress

            Iterator addresses = callback.getAnonymousAddresses().iterator();
            Iterator shippingMethods;
            Iterator merchantCodes;
           
            MerchantCalculationResults results = new MerchantCalculationResults();
            AnonymousAddress address;
            String shipping;
            MerchantCodeString code;
           
            while (addresses.hasNext()) {
                address = (AnonymousAddress) addresses.next();
               
                shippingMethods = callback.getShippingMethods().iterator();
                while (shippingMethods.hasNext()) {
                    shipping = (String) shippingMethods.next();
                   
                    merchantCodes = callback.getMerchantCodes().iterator();
                    Collection codeResults = new ArrayList();
                    while (merchantCodes.hasNext()) {
                        code = (MerchantCodeString) merchantCodes.next();
                        CouponResult coupon = new CouponResult(false, 0.0f,
                                mc.getCurrencyCode(),
                                code.getCode(), "Not supported in this example.");
                        codeResults.add(coupon);
                    }
                   
                    results.addResult(shipping, address.getId(), true, 0.0d, 0.0d,
                            mc.getCurrencyCode(), codeResults);
                }
            }
            return results.getXml();
        } catch (Exception e) {
View Full Code Here

Examples of com.google.checkout.merchantcalculation.AnonymousAddress

    Iterator addresses = callback.getAnonymousAddresses().iterator();
    Iterator shippingMethods;
    Iterator merchantCodes;

    MerchantCalculationResults results = new MerchantCalculationResults();
    AnonymousAddress address;
    String shipping;
    MerchantCodeString code;

    while (addresses.hasNext()) {
      address = (AnonymousAddress) addresses.next();

      shippingMethods = callback.getShippingMethods().iterator();
      while (shippingMethods.hasNext()) {
        shipping = (String) shippingMethods.next();

        merchantCodes = callback.getMerchantCodes().iterator();
        Collection codeResults = new ArrayList();
        while (merchantCodes.hasNext()) {
          code = (MerchantCodeString) merchantCodes.next();
          CouponResult coupon = new CouponResult(false, 0.0f,
              merchantConstants.getCurrencyCode(),
              code.getCode(), "Not supported in this example.");
          codeResults.add(coupon);
        }

        results.addResult(shipping, address.getId(), true, 0.0d, 0.0d,
            merchantConstants.getCurrencyCode(), codeResults);
      }
    }
    return results;
  }
View Full Code Here

Examples of com.google.checkout.merchantcalculation.AnonymousAddress

    Iterator shippingMethods;
    Iterator merchantCodes;
    Iterator items;

    MerchantCalculationResults results = new MerchantCalculationResults();
    AnonymousAddress address;
    String shipping;
    MerchantCodeString code;
    Item item;

    while (addresses.hasNext()) {
      address = (AnonymousAddress) addresses.next();
      //compute the taxes if required, using strikeiron tax service
      double tax = 0.0d;
      if (callback.isCalculateTax()) {
        double rate = getTaxRate(address.getPostalCode());
        items = callback.getItems().iterator();
        while (items.hasNext()) {
          item = (Item)items.next();
          tax =+ rate * item.getUnitPriceAmount() * item.getQuantity();
        }
      }

      shippingMethods = callback.getShippingMethods().iterator();
      while (shippingMethods.hasNext()) {
        shipping = (String) shippingMethods.next();

        merchantCodes = callback.getMerchantCodes().iterator();
        Collection codeResults = new ArrayList();
        while (merchantCodes.hasNext()) {
          code = (MerchantCodeString) merchantCodes.next();
          CouponResult coupon = new CouponResult(false, 0.0f,
              merchantConstants.getCurrencyCode(),
              code.getCode(), "Not supported in this example.");
          codeResults.add(coupon);
        }

        results.addResult(shipping, address.getId(), true, tax, 0.0d,
            merchantConstants.getCurrencyCode(), codeResults);
      }
    }
    return results;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.