A few fixes for Express Checkout, including a wonderfully undocumented typo in PayPal's API - L_SHIPPINGOPTIONLABEL needs to be L_SHIPINGPOPTIONLABEL

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@803513 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Scott Gray
2009-08-12 13:55:14 +00:00
parent e3218de18f
commit 700d2e5dcb
4 changed files with 38 additions and 17 deletions
@@ -34,6 +34,11 @@ under the License.
location="org.ofbiz.accounting.thirdparty.paypal.PayPalServices" invoke="doExpressCheckout">
<implements service="payPalDoExpressCheckoutInterface"/>
</service>
<service name="payPalCheckoutUpdate" engine="java" auth="false"
location="org.ofbiz.accounting.thirdparty.paypal.PayPalServices" invoke="payPalCheckoutUpdate">
<attribute name="request" mode="IN" type="javax.servlet.http.HttpServletRequest"/>
<attribute name="response" mode="IN" type="javax.servlet.http.HttpServletResponse"/>
</service>
<service name="payPalProcessor" engine="java"
location="org.ofbiz.accounting.thirdparty.paypal.PayPalServices" invoke="doAuthorization">
@@ -120,7 +120,7 @@ public class PayPalServices {
encoder.add("L_SHIPPINGOPTIONISDEFAULT0", "true");
encoder.add("L_SHIPPINGOPTIONNAME0", "NO_SHIPPING@_NA_");
//TODO: This isn't working
encoder.add("L_SHIPPINGOPTIONLABEL0", "Calculated Offline");
encoder.add("L_SHIPINGPOPTIONLABEL0", "Calculated Offline");
encoder.add("L_SHIPPINGOPTIONAMOUNT0", "0.00");
}
encoder.add("ALLOWNOTE", "1");
@@ -161,21 +161,21 @@ public class PayPalServices {
return ServiceUtil.returnSuccess();
}
public Map<String, Object> payPalExpressCheckoutUpdate(DispatchContext dctx, Map<String, Object> context) {
public static Map<String, Object> payPalCheckoutUpdate(DispatchContext dctx, Map context) {
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericDelegator delegator = dctx.getDelegator();
HttpServletRequest request = (HttpServletRequest) context.get("request");
HttpServletResponse response = (HttpServletResponse) context.get("response");
String remoteHost = request.getRemoteHost();
if (!remoteHost.endsWith(".paypal.com")) {
try {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
Debug.logError("An Express Checkout Update request was received from a host other than *.paypal.com, responded with 403 Forbidden", module);
} catch (IOException e) {
Debug.logError(e, module);
}
return ServiceUtil.returnSuccess();
}
// String remoteHost = request.getRemoteHost();
// if (!remoteHost.endsWith(".paypal.com")) {
// try {
// response.sendError(HttpServletResponse.SC_FORBIDDEN);
// Debug.logError("An Express Checkout Update request was received from a host other than *.paypal.com, responded with 403 Forbidden", module);
// } catch (IOException e) {
// Debug.logError(e, module);
// }
// return ServiceUtil.returnSuccess();
// }
String requestMessage = null;
try {
@@ -331,11 +331,11 @@ public class PayPalServices {
line++;
}
encoder.add("ITEMAMT", cart.getSubTotal().add(otherAdjustments).setScale(2).toPlainString());
encoder.add("SHIPPINGAMT", "1.00");
encoder.add("SHIPPINGAMT", "0.00");
encoder.add("TAXAMT", "0.00");
encoder.add("AMT", cart.getSubTotal().add(otherAdjustments).add(BigDecimal.ONE).setScale(2).toPlainString());
encoder.add("AMT", cart.getSubTotal().add(otherAdjustments).setScale(2).toPlainString());
//NOTE: The docs say this is optional but then won't work without it
encoder.add("MAXAMT", cart.getSubTotal().add(otherAdjustments).add(BigDecimal.ONE).setScale(2).toPlainString());
encoder.add("MAXAMT", cart.getSubTotal().add(otherAdjustments).setScale(2).toPlainString());
}
public static Map<String, Object> getExpressCheckout(DispatchContext dctx, Map<String, Object> context) {
@@ -99,6 +99,22 @@ public class ExpressCheckoutEvents {
return "success";
}
public static String expressCheckoutUpdate(HttpServletRequest request, HttpServletResponse response) {
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
CheckoutType checkoutType = determineCheckoutType(request);
if (checkoutType.equals(CheckoutType.STANDARD)) {
Map<String, Object> inMap = FastMap.newInstance();
inMap.put("request", request);
inMap.put("response", response);
try {
dispatcher.runSync("payPalCheckoutUpdate", inMap);
} catch (GenericServiceException e) {
Debug.logError(e, module);
}
}
return "success";
}
public static String getExpressCheckoutDetails(HttpServletRequest request, HttpServletResponse response) {
Locale locale = UtilHttp.getLocale(request);
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
@@ -810,8 +810,8 @@ under the License.
</request-map>
<request-map uri="payPalCheckoutUpdate">
<description>Handles callbacks from PayPal's Express Checkout Instant Update API</description>
<security auth="false" https="true"/>
<event type="service" invoke="payPalExpressCheckoutUpdate"/>
<security auth="false" https="false"/>
<event type="java" path="org.ofbiz.order.thirdparty.paypal.ExpressCheckoutEvents" invoke="expressCheckoutUpdate"/>
<response name="success" type="none"/>
</request-map>