Examples: Enabling surcharges

A surcharge, or checkout fee, is an extra fee that is charged by a merchant when receiving a payment.

The following examples demonstrate how you can enable a surcharge using the calculation framework at item-level and order-level.

Item-level example

When a shopper buys a product (for example, SKU FUOF-0101), an extra $5 Special Handling and Shipping fee is charged along with other monetary amounts of the order (including total product, shipping, tax, and so on). Product detail in the development environment sample store:

  • Product Name: White Fabric Roll Arm Chaise
  • SKU (part number): FUOF-0101
  • Catentry_id: 10252
  • Special Shipping/handling fee (surcharge): $5.00 per item

Sample surcharge configuration data for the scenario:

  1. Create a calcode to represent 'special handling fee' under surcharge calculation usage. You can also change the description.
    INSERT INTO CALCODE (CALCODE_ID,CODE,CALUSAGE_ID,STOREENT_ID,GROUPBY,PUBLISHED,SEQUENCE,CALMETHOD_ID,CALMETHOD_ID_APP,CALMETHOD_ID_QFY,DESCRIPTION,DISPLAYLEVEL,FLAGS,PRECEDENCE) values (66666,'surcharge for special handling calcode',6,-1,0,1,0,707060103,707060104,707060102,'surcharge for special handling calculation code description',0,0,0);
  2. Create language-dependent description for calcode. It is used only for display purpose. You can also change the description.
    INSERT INTO CALCODEDSC (CALCODE_ID,LANGUAGE_ID,DESCRIPTION,LONGDESCRIPTION) VALUES (66666,-1,'surcharge for special handling calculation code description in description table','longer version of surcharge for special handling calculation code description in the description table');
  3. Connect the calculation code with the product. You need to add a similar entry into your database for every product (catentry_id) that you want to have the surcharge associated with.
    INSERT INTO CATENCALCD (STORE_ID,CATENCALCD_ID,CATENTRY_ID,CALCODE_ID) VALUES (1,66671,10252,66666);
  4. Create the calculation rule for the calculation code. It represents charge rates.
    INSERT INTO CALRULE (CALRULE_ID,CALCODE_ID,SEQUENCE,COMBINATION,CALMETHOD_ID,CALMETHOD_ID_QFY,FLAGS,IDENTIFIER) VALUES (66667,66666,0,2,707060107,707060106,0,1);
  5. Create the calculation scale properties.
    INSERT INTO CALSCALE (CALSCALE_ID,QTYUNIT_ID,CODE,STOREENT_ID,CALUSAGE_ID,CALMETHOD_ID) VALUES (66668,'C62','scale-surchargeSH',-1,-6,-707060108);
  6. Associate the calculation scale properties to the calculation rules.
    INSERT INTO CRULESCALE (CALSCALE_ID,CALRULE_ID) VALUES (66668,66667);
  7. Create the ranges for the calculations.
    INSERT INTO CALRANGE (CALRANGE_ID,CALSCALE_ID,CALMETHOD_ID,RANGESTART) VALUES (66669,66668,-707060110,0);
  8. Create the surcharge value and associate it with the calculations. You can change the value of the surcharge with this SQL statement.
    INSERT INTO CALRLOOKUP (CALRLOOKUP_ID,CALRANGE_ID,VALUE) VALUES (66670,66669,5);
  9. Change your storefront JSPs to display the surcharge. The Surcharge Adjustment example is taken from .../Stores/WebContent/ConsumerDirect/Snippets/Order/Inventory/CurrentAndTotalCharges.jsp
    <tr>
       <td colspan="5" class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_9">
       <fmt:message key="OrderSummary_TOTAL_PRODUCT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_DISCOUNT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_SURCHARGE" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_TAX" bundle="${orderText}" />
       <br
          />
       <c:if test="${showBaseShipAndAdjust}" >
          <fmt:message key="OrderSummary_TOTAL_ORIGINAL_SHIPPING"
             bundle="${orderText}" />
          <br />
          <fmt:message key="OrderSummary_TOTAL_SHIPPING_ADJUSTMENT"
             bundle="${orderText}" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <fmt:message key="OrderSummary_TOTAL_SHIPPING" bundle="${orderText}"
             />
          <br />
       </c:if>
       <fmt:message key="OrderSummary_TOTAL_SHIPPINGTAX"
          bundle="${orderText}" />
       </td>
       <td class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_10">
       <c:out value="${order_OrderDataBean.formattedTotalProductPrice}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalDiscountAdjustment}"
          escapeXml="false" />
       <br />
       <c:out
          value="${order_OrderDataBean.formattedTotalSurchargeAdjustment}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalTax}"
          escapeXml="false" />
       <br />
       <c:if test="${showBaseShipAndAdjust}" >
          <c:out value="${order_OrderDataBean.formattedShippingCharge}"
             escapeXml="false"/>
          <br />
          <c:out
             value="${order_OrderDataBean.formattedTotalShippingAdjustment}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <c:out value="${order_OrderDataBean.formattedTotalShippingCharge}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:out value="${order_OrderDataBean.formattedTotalShippingTax}"
          escapeXml="false" />
       </td>
    </tr>
  10. You can get the surcharge value from OrderDataBean.getFormattedTotalSurchargeAdjustment().

Order-level example

When a shopper buys a selection of products, an extra $5 surcharge for delivery service fee is charged along with other monetary amounts of the order (including total product, shipping, tax, and so on). Product detail in the development environment sample store:

  • Special Shipping/handling fee (surcharge): $5.00 per order

Sample surcharge configuration data for the scenario:

  1. Create a calcode to represent 'special handling fee' under surcharge calculation usage. You can also change the description.
    INSERT INTO CALCODE (CALCODE_ID,CODE,CALUSAGE_ID,STOREENT_ID,GROUPBY,PUBLISHED,SEQUENCE,CALMETHOD_ID,CALMETHOD_ID_APP,CALMETHOD_ID_QFY,DESCRIPTION,DISPLAYLEVEL,FLAGS,PRECEDENCE) VALUES (66666,'surcharge for delivery service',-6,-1,0,1,0,-707060103,-707060104,-707060102,'surcharge for delivery service description',0,0,0);
  2. Create language-dependent description for calcode. It is used only for display purpose. You can also change the description.
    INSERT INTO CALCODEDSC (CALCODE_ID,LANGUAGE_ID,DESCRIPTION,LONGDESCRIPTION) VALUES (66666,-1,'surcharge for delivery service description in description table','longer version of surcharge for delivery service description in the description table');
  3. Create the calculation rule for the calculation code. It represents charge rates.
    INSERT INTO CALRULE (CALRULE_ID,CALCODE_ID,SEQUENCE,COMBINATION,CALMETHOD_ID,CALMETHOD_ID_QFY,FLAGS,IDENTIFIER) VALUES (66667,66666,0,2,-707060107,-707060106,0,1);
  4. Create the calculation scale properties.
    INSERT INTO CALSCALE (CALSCALE_ID,QTYUNIT_ID,CODE,STOREENT_ID,CALUSAGE_ID,CALMETHOD_ID) VALUES (66668,'C62','special handling',-1,-6,-707060108);
  5. Associate the calculation scale properties to the calculation rules.
    INSERT INTO CRULESCALE (CALSCALE_ID,CALRULE_ID) VALUES (66668,66667);
  6. Create the ranges for the calculations.
    INSERT INTO CALRANGE (CALRANGE_ID,CALSCALE_ID,CALMETHOD_ID,RANGESTART) VALUES (66669,66668,-707060110,0);
  7. Create the surcharge value and associate it with the calculations. You can change the value of the surcharge with this SQL statement.
    INSERT INTO CALRLOOKUP (CALRLOOKUP_ID,CALRANGE_ID,VALUE) VALUES (66670,66669,5);
  8. Apply the new surcharge for use in the store.
    UPDATE STENCALUSG SET CALCODE_ID=66666 WHERE CALUSAGE_ID=-6;
  9. Change your storefront JSPs to display the surcharge. The Surcharge Adjustment example is taken from .../Stores/WebContent/ConsumerDirect/Snippets/Order/Inventory/CurrentAndTotalCharges.jsp
    <tr>
       <td colspan="5" class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_9">
       <fmt:message key="OrderSummary_TOTAL_PRODUCT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_DISCOUNT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_SURCHARGE" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_TAX" bundle="${orderText}" />
       <br
          />
       <c:if test="${showBaseShipAndAdjust}" >
          <fmt:message key="OrderSummary_TOTAL_ORIGINAL_SHIPPING"
             bundle="${orderText}" />
          <br />
          <fmt:message key="OrderSummary_TOTAL_SHIPPING_ADJUSTMENT"
             bundle="${orderText}" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <fmt:message key="OrderSummary_TOTAL_SHIPPING" bundle="${orderText}"
             />
          <br />
       </c:if>
       <fmt:message key="OrderSummary_TOTAL_SHIPPINGTAX"
          bundle="${orderText}" />
       </td>
       <td class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_10">
       <c:out value="${order_OrderDataBean.formattedTotalProductPrice}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalDiscountAdjustment}"
          escapeXml="false" />
       <br />
       <c:out
          value="${order_OrderDataBean.formattedTotalSurchargeAdjustment}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalTax}"
          escapeXml="false" />
       <br />
       <c:if test="${showBaseShipAndAdjust}" >
          <c:out value="${order_OrderDataBean.formattedShippingCharge}"
             escapeXml="false"/>
          <br />
          <c:out
             value="${order_OrderDataBean.formattedTotalShippingAdjustment}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <c:out value="${order_OrderDataBean.formattedTotalShippingCharge}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:out value="${order_OrderDataBean.formattedTotalShippingTax}"
          escapeXml="false" />
       </td>
    </tr>
  10. You can get the surcharge value from OrderDataBean.getFormattedTotalSurchargeAdjustment().