svn commit: r433421 - in /incubator/ofbiz/trunk/applications/accounting: servicedef/services_paymentmethod.xml src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

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

svn commit: r433421 - in /incubator/ofbiz/trunk/applications/accounting: servicedef/services_paymentmethod.xml src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

sichen
Author: sichen
Date: Mon Aug 21 16:21:48 2006
New Revision: 433421

URL: http://svn.apache.org/viewvc?rev=433421&view=rev
Log:
Service for capturing billing account payments will now create a PaymentGatewayResponse record so that later we can use it to figure out how much of the order was captured to each payment method

Modified:
    incubator/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
    incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java

Modified: incubator/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml?rev=433421&r1=433420&r2=433421&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml (original)
+++ incubator/ofbiz/trunk/applications/accounting/servicedef/services_paymentmethod.xml Mon Aug 21 16:21:48 2006
@@ -268,7 +268,9 @@
         <attribute name="invoiceId" type="String" mode="IN" optional="false"/>
         <attribute name="billingAccountId" type="String" mode="IN" optional="false"/>
         <attribute name="captureAmount" type="Double" mode="IN" optional="false"/>
+        <attribute name="orderId" type="String" mode="IN" optional="true"/>
         <attribute name="paymentId" type="String" mode="OUT" optional="false"/>
+        <attribute name="paymentGatewayResponseId" type="String" mode="OUT" optional="true"/>
     </service>
         
 

Modified: incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java?rev=433421&r1=433420&r2=433421&view=diff
==============================================================================
--- incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java (original)
+++ incubator/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/payment/PaymentGatewayServices.java Mon Aug 21 16:21:48 2006
@@ -905,7 +905,7 @@
                 // capturing to a billing account if amount is greater than zero
                 if (billingAccountCaptureAmount.compareTo(ZERO) == 1) {
                     Map tmpResult = dispatcher.runSync("captureBillingAccountPayment", UtilMisc.toMap("invoiceId", invoiceId, "billingAccountId", billingAccountId,
-                            "captureAmount", new Double(billingAccountCaptureAmount.doubleValue()), "userLogin", userLogin));
+                            "captureAmount", new Double(billingAccountCaptureAmount.doubleValue()), "orderId", orderId, "userLogin", userLogin));
                     if (ServiceUtil.isError(tmpResult)) {
                         return tmpResult;
                     }
@@ -1108,6 +1108,7 @@
         String invoiceId = (String) context.get("invoiceId");
         String billingAccountId = (String) context.get("billingAccountId");
         Double captureAmount = (Double) context.get("captureAmount");
+        String orderId = (String) context.get("orderId");
         Map results = ServiceUtil.returnSuccess();
         
         try {
@@ -1134,6 +1135,44 @@
                 return ServiceUtil.returnError("No payment created for invoice [" + invoiceId + "] and billing account [" + billingAccountId + "]");
             }
             results.put("paymentId", paymentId);
+            
+            if (orderId != null && captureAmount.doubleValue() > 0) {
+                // Create a paymentGatewayResponse, if necessary
+                GenericValue order = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+                if (order == null) {
+                    return ServiceUtil.returnError("No paymentGatewayResponse created for invoice [" + invoiceId + "] and billing account [" + billingAccountId + "]: Order with ID [" + orderId + "] not found!");
+                }
+                // See if there's an orderPaymentPreference - there should be only one OPP for EXT_BILLACT per order
+                List orderPaymentPreferences = delegator.findByAnd("OrderPaymentPreference", UtilMisc.toMap("orderId", orderId, "paymentMethodTypeId", "EXT_BILLACT"));
+                if (orderPaymentPreferences != null && orderPaymentPreferences.size() > 0) {
+                    GenericValue orderPaymentPreference = EntityUtil.getFirst(orderPaymentPreferences);
+                    
+                    // Check the productStore setting to see if we need to do this explicitly
+                    GenericValue productStore = order.getRelatedOne("ProductStore");
+                    if (productStore.getString("manualAuthIsCapture") == null || (! productStore.getString("manualAuthIsCapture").equalsIgnoreCase("Y"))) {        
+                        String responseId = delegator.getNextSeqId("PaymentGatewayResponse");
+                        GenericValue pgResponse = delegator.makeValue("PaymentGatewayResponse", null);
+                        pgResponse.set("paymentGatewayResponseId", responseId);
+                        pgResponse.set("paymentServiceTypeEnumId", CAPTURE_SERVICE_TYPE);
+                        pgResponse.set("orderPaymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId"));
+                        pgResponse.set("paymentMethodTypeId", "EXT_BILLACT");
+                        pgResponse.set("transCodeEnumId", "PGT_CAPTURE");
+                        pgResponse.set("amount", captureAmount);
+                        pgResponse.set("currencyUomId", invoice.getString("currencyUomId"));
+                        pgResponse.set("transactionDate", UtilDateTime.nowTimestamp());
+                        // referenceNum holds the relation to the order.
+                        // todo: Extend PaymentGatewayResponse with a billingAccountId field?
+                        pgResponse.set("referenceNum", billingAccountId);
+                        pgResponse.create();
+
+                        // Update the orderPaymentPreference
+                        orderPaymentPreference.set("statusId", "PAYMENT_SETTLED");
+                        orderPaymentPreference.store();
+                        
+                        results.put("paymentGatewayResponseId", responseId);
+                    }
+                }
+            }
         } catch (GenericEntityException ex) {
             return ServiceUtil.returnError(ex.getMessage());
         } catch (GenericServiceException ex) {