svn commit: r522743 - in /ofbiz/trunk/applications/order: servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r522743 - in /ofbiz/trunk/applications/order: servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

jaz-3
Author: jaz
Date: Mon Mar 26 21:39:42 2007
New Revision: 522743

URL: http://svn.apache.org/viewvc?view=rev&rev=522743
Log:
very basic create non-product order service

Modified:
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=522743&r1=522742&r2=522743
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Mon Mar 26 21:39:42 2007
@@ -140,7 +140,22 @@
         <attribute name="orderId" type="String" mode="OUT" optional="false"/>
         <attribute name="statusId" type="String" mode="OUT" optional="false"/>
     </service>
+    
+    <service name="callProcessOrderPayments" engine="java"
+            location="org.ofbiz.order.order.OrderServices" invoke="callProcessOrderPayments" auth="true">
+        <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+        <attribute name="manualHold" type="Boolean" mode="IN" optional="true"/>
+    </service>
 
+    <service name="createSimpleNonProductSalesOrder" engine="java"
+            location="org.ofbiz.order.order.OrderServices" invoke="createSimpleNonProductSalesOrder" auth="true">
+        <attribute name="paymentMethodId" type="String" mode="IN" optional="false"/>
+        <attribute name="productStoreId" type="String" mode="IN" optional="false"/>
+        <attribute name="currency" type="String" mode="IN" optional="false"/>
+        <attribute name="partyId" type="String" mode="IN" optional="false"/>
+        <attribute name="itemMap" type="Map" mode="IN" optional="false"/>        
+    </service>
+    
     <service name="createOrderItemBilling" engine="simple"
         location="org/ofbiz/order/order/OrderSimpleMethods.xml" invoke="createOrderItemBilling">
         <description>Create a new order item billing record</description>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=522743&r1=522742&r2=522743
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Mar 26 21:39:42 2007
@@ -3978,4 +3978,88 @@
 
         return ServiceUtil.returnSuccess();
     }
+
+    // create simple non-product order
+    public static Map createSimpleNonProductSalesOrder(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Locale locale = (Locale) context.get("locale");
+
+        String paymentMethodId = (String) context.get("paymentMethodId");
+        String productStoreId = (String) context.get("productStoreId");        
+        String currency = (String) context.get("currency");
+        String partyId = (String) context.get("partyId");
+        Map itemMap = (Map) context.get("itemMap");
+
+        ShoppingCart cart = new ShoppingCart(delegator, productStoreId, null, locale, currency);
+        cart.setOrderType("SALES_ORDER");
+        cart.setOrderPartyId(partyId);
+
+        Iterator i = itemMap.keySet().iterator();
+        while (i.hasNext()) {
+            String item = (String) i.next();
+            Double price = (Double) itemMap.get(item);
+            try {
+                cart.addNonProductItem("BULK_ORDER_ITEM", item, null, price, 1, null, null, null, dispatcher);
+            } catch (CartItemModifyException e) {
+                Debug.logError(e, module);
+                return ServiceUtil.returnError(e.getMessage());
+            }
+        }
+
+        // set the payment method
+        cart.addPayment(paymentMethodId);
+
+        Map procCtx = FastMap.newInstance();
+        procCtx.put("shoppingCart", cart);
+        procCtx.put("userLogin", userLogin);
+        Map procResp;
+        try {
+            procResp = dispatcher.runSync("callProcessOrderPayments", procCtx);
+        } catch (GenericServiceException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        if (ServiceUtil.isError(procResp)) {
+            return procResp;
+        }
+        
+        Map result = ServiceUtil.returnSuccess();
+        //result.put("shoppingCart", cart);
+        return result;
+    }
+
+    // generic method for processing an order's payment(s)
+    public static Map callProcessOrderPayments(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        ShoppingCart cart = (ShoppingCart) context.get("shoppingCart");
+        Boolean manualHold = (Boolean) context.get("manualHold");
+        if (manualHold == null) {
+            manualHold = Boolean.FALSE;
+        }
+
+        String productStoreId = cart.getProductStoreId();
+        
+        GenericValue productStore = ProductStoreWorker.getProductStore(productStoreId, delegator);
+        CheckOutHelper coh = new CheckOutHelper(dispatcher, delegator, cart);
+
+        // process payment
+        Map payResp;
+        try {
+            payResp = coh.processPayment(productStore, userLogin, false, manualHold.booleanValue());
+        } catch (GeneralException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        if (ServiceUtil.isError(payResp)) {
+            return ServiceUtil.returnError(ServiceUtil.getErrorMessage(payResp));
+        }
+
+        return ServiceUtil.returnSuccess();
+    }
 }