Author: jaz
Date: Wed Dec 29 20:05:11 2010 New Revision: 1053723 URL: http://svn.apache.org/viewvc?rev=1053723&view=rev Log: added eway payment integration Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/EwayServices.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayConnector.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayRequest.java ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayResponse.java Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml ofbiz/trunk/applications/accounting/data/PaymentGatewayConfData.xml ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigScreens.xml Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=1053723&r1=1053722&r2=1053723&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original) +++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Wed Dec 29 20:05:11 2010 @@ -821,6 +821,10 @@ under the License. <CustomMethod customMethodId="PAYPAL_RELEASE_PFP" customMethodTypeId="PAYPAL_RELEASE" customMethodName="payflowPayPalVoid" description="Payflow PayPal Order release"/> <CustomMethod customMethodId="PAYPAL_RELEASE" customMethodTypeId="PAYPAL_RELEASE" customMethodName="payPalVoid" description="PayPal Order Release"/> + <CustomMethod customMethodId="CC_CHARGE_EWAY" customMethodTypeId="CC_AUTH" customMethodName="ewayCharge" description="eWay CC Charge"/> + <CustomMethod customMethodId="CC_REFUND_EWAY" customMethodTypeId="CC_REFUND" customMethodName="ewayRefund" description="eWay CC Refund"/> + <CustomMethod customMethodId="CC_RELEASE_EWAY" customMethodTypeId="CC_RELEASE" customMethodName="ewayRelease" description="eWay CC Release"/> + <CustomMethod customMethodId="SECURE_AUTH_OFBIZ" customMethodTypeId="CC_AUTH" customMethodName="ofbScAuthorize" description="SecurePay payment authorize"/> <CustomMethod customMethodId="SECURE_CAPTURE_OFBIZ" customMethodTypeId="CC_CAPTURE" customMethodName="ofbScCapture" description="SecurePay payment capture"/> <CustomMethod customMethodId="SECURE_REFUND_OFBIZ" customMethodTypeId="CC_REFUND" customMethodName="ofbScRefund" description="SecurePay payment refund"/> Modified: ofbiz/trunk/applications/accounting/data/PaymentGatewayConfData.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/PaymentGatewayConfData.xml?rev=1053723&r1=1053722&r2=1053723&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/data/PaymentGatewayConfData.xml (original) +++ ofbiz/trunk/applications/accounting/data/PaymentGatewayConfData.xml Wed Dec 29 20:05:11 2010 @@ -32,6 +32,10 @@ under the License. <PaymentGatewayConfig paymentGatewayConfigId="CYBERSOURCE_CONFIG" paymentGatewayConfigTypeId="CYBERSOURCE" description="CyberSource Config"/> <PaymentGatewayCyberSource paymentGatewayConfigId="CYBERSOURCE_CONFIG" merchantId="[MerchantID]" apiVersion="1.43" production="false" keysDir="${sys:getProperty('ofbiz.home')}/applications/accounting/icskeys" keysFile="merchantID.p12" logEnabled="true" logDir="${sys:getProperty('ofbiz.home')}/runtime/logs" logFile="cybersource.log" logSize="10" merchantDescr="Some Nice Web Store" merchantContact="" autoBill="false" enableDav="N" fraudScore="N" ignoreAvs="false" disableBillAvs="Y" avsDeclineCodes=""/> + <PaymentGatewayConfigType paymentGatewayConfigTypeId="EWAY" hasTable="N" description="eWay Payment Gateway"/> + <PaymentGatewayConfig paymentGatewayConfigId="EWAY_CONFIG" paymentGatewayConfigTypeId="EWAY" description="eWay Config"/> + <PaymentGatewayEway paymentGatewayConfigId="EWAY_CONFIG" customerId="87654321" refundPwd="" testMode="Y" enableBeagle="N" enableCvn="N"/> + <PaymentGatewayConfigType paymentGatewayConfigTypeId="PAYFLOWPRO" hasTable="N" description="Payflow Pro Payment Gateway"/> <PaymentGatewayConfig paymentGatewayConfigId="PAYFLOWPRO_CONFIG" paymentGatewayConfigTypeId="PAYFLOWPRO" description="Payflow Pro Config"/> <PaymentGatewayPayflowPro paymentGatewayConfigId="PAYFLOWPRO_CONFIG" certsPath="${sys:getProperty('ofbiz.home')}/applications/accounting/pfcerts" hostAddress="pilot-payflowpro.paypal.com" hostPort="443" timeout="80" proxyAddress="" proxyPort="80" proxyLogon="" proxyPassword="" Modified: ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml?rev=1053723&r1=1053722&r2=1053723&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml (original) +++ ofbiz/trunk/applications/accounting/entitydef/entitymodel.xml Wed Dec 29 20:05:11 2010 @@ -3271,6 +3271,20 @@ under the License. <key-map field-name="paymentGatewayConfigId"/> </relation> </entity> + <entity entity-name="PaymentGatewayEway" + package-name="org.ofbiz.accounting.payment" + title="eWay Payment Gateway Configuration"> + <field name="paymentGatewayConfigId" type="id-ne"></field> + <field name="customerId" type="value"/> + <field name="refundPwd" type="value" encrypt="true"/> + <field name="testMode" type="short-varchar"/> + <field name="enableCvn" type="short-varchar"/> + <field name="enableBeagle" type="short-varchar"/> + <prim-key field="paymentGatewayConfigId"/> + <relation type="one" fk-name="PGEW_PGC" rel-entity-name="PaymentGatewayConfig"> + <key-map field-name="paymentGatewayConfigId"/> + </relation> + </entity> <entity entity-name="PaymentGatewayCyberSource" package-name="org.ofbiz.accounting.payment" title="CyberSource Payment Gateway Configuration"> Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/EwayServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/EwayServices.java?rev=1053723&view=auto ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/EwayServices.java (added) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/EwayServices.java Wed Dec 29 20:05:11 2010 @@ -0,0 +1,280 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.accounting.thirdparty.eway; + +import java.math.BigDecimal; +import java.util.Map; + +import org.ofbiz.accounting.payment.PaymentGatewayServices; +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.entity.Delegator; +import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; +import org.ofbiz.service.DispatchContext; +import org.ofbiz.service.ServiceUtil; + +public class EwayServices { + + public static final String module = EwayServices.class.getName(); + + // eway charge (auth w/ capture) + public static Map<String, Object> ewayCharge(DispatchContext dctx, Map<String, Object> context) { + String orderId = (String) context.get("orderId"); + String cvv2 = (String) context.get("cardSecurityCode"); + String custIp = (String) context.get("customerIpAddress"); + BigDecimal processAmount = (BigDecimal) context.get("processAmount"); + GenericValue cc = (GenericValue) context.get("creditCard"); + GenericValue address = (GenericValue) context.get("billingAddress"); + GenericValue party = (GenericValue) context.get("billToParty"); + + GatewayRequest req = initRequest(dctx, context, false); + req.setCustomerInvoiceRef(orderId); + req.setTotalAmount(processAmount); + req.setCustomerIPAddress(custIp); + + // bill to party info + req.setCustomerFirstName(UtilFormatOut.checkNull(party.getString("firstName"))); + req.setCustomerLastName(UtilFormatOut.checkNull(party.getString("lastName"))); + + // card info + String ccName = cc.getString("firstNameOnCard") + " " + cc.getString("lastNameOnCard"); + req.setCardHoldersName(ccName); + req.setCardNumber(cc.getString("cardNumber")); + if (cc.get("expireDate") != null) { + String[] exp = cc.getString("expireDate").split("\\/"); + req.setCardExpiryMonth(exp[0]); + req.setCardExpiryYear(exp[1]); + } + + // security code + if (UtilValidate.isNotEmpty(cvv2)) { + req.setCVN(cvv2); + } + + // billing address + if (address != null) { + String street = address.getString("address1") + ((UtilValidate.isNotEmpty(address.getString("address2"))) ? " " + address.getString("address2") : ""); + req.setCustomerAddress(street); + req.setCustomerPostcode(address.getString("postalCode")); + req.setCustomerBillingCountry(address.getString("countryGeoId")); + } + + // send the request + GatewayConnector con = new GatewayConnector(); + GatewayResponse reply; + try { + reply = con.sendRequest(req); + } catch (Exception e) { + return ServiceUtil.returnError(e.getMessage()); + } + + // process the result + Map<String, Object> result = ServiceUtil.returnSuccess(); + Boolean authResult = reply.getTrxnStatus(); + + // auth fields + result.put("authResult", new Boolean(authResult.booleanValue())); + result.put("authMessage", reply.getTrxnError()); + result.put("authCode", reply.getAuthCode()); + result.put("authRefNum", reply.getTrxnNumber()); + result.put("scoreCode", Double.valueOf(reply.getBeagleScore()).toString()); + result.put("processAmount", reply.getTransactionAmount()); + + // capture fields + result.put("captureResult", result.get("authResult")); + result.put("captureMessage", result.get("authMessage")); + result.put("captureRefNum", result.get("authRefNum")); + + return result; + } + + // eway refund + public static Map<String, Object> ewayRefund(DispatchContext dctx, Map<String, Object> context) { + Delegator delegator = dctx.getDelegator(); + GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference"); + BigDecimal refundAmount = (BigDecimal) context.get("refundAmount"); + + // original charge transaction + GenericValue chargeTrans = PaymentGatewayServices.getCaptureTransaction(paymentPref); + if (chargeTrans == null) { + return ServiceUtil.returnError("No charge transaction found for the OrderPaymentPreference; cannot refund"); + } + + // credit card used for transaction + GenericValue cc = null; + try { + cc = delegator.getRelatedOne("CreditCard", paymentPref); + } catch (GenericEntityException e) { + Debug.logError(e, module); + return ServiceUtil.returnError("Unable to obtain credit card information from payment preference; cannot refund"); + } + + // orig ref number + String refNum = chargeTrans.getString("referenceNum"); + String orderId = paymentPref.getString("orderId"); + + GatewayRequest req = initRequest(dctx, context, true); + req.setCustomerInvoiceRef(orderId); + req.setTotalAmount(refundAmount); + req.setTrxnNumber(refNum); + + // set the card expire date + if (cc.get("expireDate") != null) { + String[] exp = cc.getString("expireDate").split("\\/"); + req.setCardExpiryMonth(exp[0]); + req.setCardExpiryYear(exp[1]); + } + + // send the request + GatewayConnector con = new GatewayConnector(); + GatewayResponse reply; + try { + reply = con.sendRequest(req); + } catch (Exception e) { + return ServiceUtil.returnError(e.getMessage()); + } + + // process the result + Map<String, Object> result = ServiceUtil.returnSuccess(); + Boolean refundResult = reply.getTrxnStatus(); + result.put("refundResult", new Boolean(refundResult.booleanValue())); + result.put("refundMessage", reply.getTrxnError()); + result.put("refundCode", reply.getAuthCode()); + result.put("refundRefNum", reply.getTrxnNumber()); + result.put("refundAmount", reply.getTransactionAmount()); + + return result; + } + + // eway release (does a refund) + public static Map<String, Object> ewayRelease(DispatchContext dctx, Map<String, Object> context) { + Delegator delegator = dctx.getDelegator(); + GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference"); + BigDecimal releaseAmount = (BigDecimal) context.get("releaseAmount"); + + // original charge transaction + GenericValue chargeTrans = (GenericValue) context.get("authTrans"); + if (chargeTrans == null) { + chargeTrans = PaymentGatewayServices.getAuthTransaction(paymentPref); + } + + if (chargeTrans == null) { + return ServiceUtil.returnError("No charge transaction found for the OrderPaymentPreference; cannot refund (release)"); + } + + // credit card used for transaction + GenericValue cc = null; + try { + cc = delegator.getRelatedOne("CreditCard", paymentPref); + } catch (GenericEntityException e) { + Debug.logError(e, module); + return ServiceUtil.returnError("Unable to obtain credit card information from payment preference; cannot refund"); + } + + // orig ref number + String refNum = chargeTrans.getString("referenceNum"); + String orderId = paymentPref.getString("orderId"); + + GatewayRequest req = initRequest(dctx, context, true); + req.setCustomerInvoiceRef(orderId); + req.setTotalAmount(releaseAmount); + req.setTrxnNumber(refNum); + + // set the card expire date + if (cc.get("expireDate") != null) { + String[] exp = cc.getString("expireDate").split("\\/"); + req.setCardExpiryMonth(exp[0]); + req.setCardExpiryYear(exp[1]); + } + + // send the request + GatewayConnector con = new GatewayConnector(); + GatewayResponse reply; + try { + reply = con.sendRequest(req); + } catch (Exception e) { + return ServiceUtil.returnError(e.getMessage()); + } + + // process the result + Map<String, Object> result = ServiceUtil.returnSuccess(); + Boolean refundResult = reply.getTrxnStatus(); + result.put("releaseResult", new Boolean(refundResult.booleanValue())); + result.put("releaseMessage", reply.getTrxnError()); + result.put("releaseCode", reply.getAuthCode()); + result.put("releaseRefNum", reply.getTrxnNumber()); + result.put("releaseAmount", reply.getTransactionAmount()); + + return result; + } + + + private static GatewayRequest initRequest(DispatchContext dctx, Map<String, Object> context, boolean refund) { + String pgcId = (String) context.get("paymentGatewayConfigId"); + String cfgStr = (String) context.get("paymentConfig"); + Delegator delegator = dctx.getDelegator(); + + String customerId = getPaymentGatewayConfigValue(delegator, pgcId, "customerId", cfgStr, "payment.eway.customerId"); + String refundPwd = getPaymentGatewayConfigValue(delegator, pgcId, "refundPwd", cfgStr, "payment.eway.refundPwd"); + Boolean testMode = "Y".equalsIgnoreCase(getPaymentGatewayConfigValue(delegator, pgcId, "testMode", cfgStr, "payment.eway.testMode")); + Boolean beagle = "Y".equalsIgnoreCase(getPaymentGatewayConfigValue(delegator, pgcId, "enableBeagle", cfgStr, "payment.eway.enableBeagle")); + Boolean cvn = "Y".equalsIgnoreCase(getPaymentGatewayConfigValue(delegator, pgcId, "enableCvn", cfgStr, "payment.eway.enableCvn")); + + // the request mode + int requestMode = refund ? GatewayRequest.REQUEST_METHOD_REFUND : beagle ? + GatewayRequest.REQUEST_METHOD_BEAGLE : cvn ? GatewayRequest.REQUEST_METHOD_CVN : 0; + + // create the request object + GatewayRequest req = new GatewayRequest(requestMode); + req.setTestMode(testMode); + req.setCustomerID(customerId); + if (refund) { + req.setRefundPassword(refundPwd); + } + + return req; + } + + private static String getPaymentGatewayConfigValue(Delegator delegator, String cfgId, String cfgParamName, + String resource, String resParamName) { + String returnValue = ""; + if (UtilValidate.isNotEmpty(cfgId)) { + try { + GenericValue gv = delegator.findOne("PaymentGatewayEway", true, "paymentGatewayConfigId", cfgId); + if (UtilValidate.isNotEmpty(gv)) { + Object field = gv.get(cfgParamName); + if (field != null) { + returnValue = field.toString().trim(); + } + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } + } else { + String value = UtilProperties.getPropertyValue(resource, resParamName); + if (value != null) { + returnValue = value.trim(); + } + } + return returnValue; + } +} Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayConnector.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayConnector.java?rev=1053723&view=auto ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayConnector.java (added) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayConnector.java Wed Dec 29 20:05:11 2010 @@ -0,0 +1,116 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.accounting.thirdparty.eway; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.ofbiz.base.util.Debug; + +/** + * Handles connections to the eWay servers. + * + * Based on public domain sample code provided by eWay.com.au + */ +public class GatewayConnector { + + private static final String module = GatewayConnector.class.getName(); + + private int timeout = 0; + + public GatewayConnector(int timeout) { + this.timeout = timeout; + } + + public GatewayConnector() { + this(60); + } + + /** + * Get the timeout value set in the corresponding setter. + * @return timeout value in seconds, 0 for infinite + */ + public int getTimeout() { + return timeout; + } + + /** + * Set the timout value. Note that setting the timeout for an HttpURLConnection + * is possible only since Java 1.5. This method has no effect on earlier + * versions. + * @param time timeout value in seconds, 0 for infinite + */ + public void setTimeout(int time) { + timeout = time; + } + + /** + * Send a request to the payment gateway and get the response. This is a + * blocking method: when it returns the response object is filled in with + * the parameters from the gateway. + * @param request the request object, can be any of the 3 supported payment + * methods. Its data have to be filled in by its setter methods before + * calling sendRequest(). + * @return the response object, containing the gateway's response to the + * request + * @throws Exception in case of networking and xml parsing errors + */ + public GatewayResponse sendRequest(GatewayRequest request) throws Exception { + + // determine the gateway url to be used, based on the request type + String serverurl = request.getUrl(); + + GatewayResponse response = null; + InputStream in = null; + HttpURLConnection connection = null; + try { + // connect to the gateway + URL u = new URL(serverurl); + connection = (HttpURLConnection)(u.openConnection()); + connection.setDoOutput(true); + connection.setDoInput(true); + connection.setRequestMethod("POST"); + connection.setConnectTimeout(timeout*1000); + + OutputStream out = connection.getOutputStream(); + Writer wout = new OutputStreamWriter(out); + wout.write(request.toXml()); + wout.flush(); + wout.close(); + + in = connection.getInputStream(); + response = new GatewayResponse(in, request); + return response; + } + catch (Exception e) { + // rethrow exception so that the caller learns what went wrong + Debug.logError(e, e.getMessage(), module); + throw e; + } + finally { + // close resources + if (in != null) in.close(); + if (connection != null) connection.disconnect(); + } + } +} \ No newline at end of file Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayRequest.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayRequest.java?rev=1053723&view=auto ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayRequest.java (added) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayRequest.java Wed Dec 29 20:05:11 2010 @@ -0,0 +1,414 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.accounting.thirdparty.eway; + +import java.math.BigDecimal; + +import org.ofbiz.base.util.Debug; + +/** + * A class representing a payment request. It holds the fields of the request, + * provides setters and getters to manipulate them. It also holds information + * about the type of the request: the request can be of Real-time, CVN, and + * Beagle type, or the combination of the latter two. You set the request type + * in the constructor of the object. + * + * Based on public domain sample code provided by eWay.com.au + */ +public class GatewayRequest { + + private static final String module = GatewayRequest.class.getName(); + + // request urls + public static final String REQUEST_URL_REFUND_TEST = ""; + public static final String REQUEST_URL_REFUND = "https://www.eway.com.au/gateway/xmlpaymentrefund.asp"; + + public static final String REQUEST_URL_BEAGLE_TEST = "https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp"; + public static final String REQUEST_URL_BEAGLE = "https://www.eway.com.au/gateway_cvn/xmlbeagle.asp"; + + public static final String REQUEST_URL_CVN_TEST = "https://www.eway.com.au/gateway_cvn/xmltest/testpage.asp"; + public static final String REQUEST_URL_CVN = "https://www.eway.com.au/gateway_cvn/xmlpayment.asp"; + + public static final String REQUEST_URL_RT_TEST = "https://www.eway.com.au/gateway/xmltest/testpage.asp"; + public static final String REQUEST_URL_RT = "https://www.eway.com.au/gateway/xmlpayment.asp"; + + /** + * Constant value to be used with the CVN payment method + */ + public static final int REQUEST_METHOD_CVN = 1; + + /** + * Constant value to be used with the Beagle (GeoIP) payment method + */ + public static final int REQUEST_METHOD_BEAGLE = 2; + + /** + * Constant value to be used with the Refund method + */ + public static final int REQUEST_METHOD_REFUND = 4; + + /** + * The request method used in the transaction, set in the constructor. + * This value is the boolean + * combination of the values REQUEST_METHOD_CVN and REQUEST_METHOD_BEAGLE. + * Defaults to 0, meaning that Real-time payment method is used. + */ + + private BigDecimal txTotalAmount = BigDecimal.ZERO; + private boolean isTestMode = false; + private int requestMethod = 0; + + private String txCustomerID = ""; + private String txCardHoldersName = ""; + private String txCardNumber = ""; + private String txCardExpiryMonth = ""; + private String txCardExpiryYear = ""; + private String txTrxnNumber = ""; + private String txCustomerFirstName = ""; + private String txCustomerLastName = ""; + private String txCustomerEmailAddress = ""; + private String txCustomerAddress = ""; + private String txCustomerPostcode = ""; + private String txCustomerInvoiceRef = ""; + private String txCustomerInvoiceDescription = ""; + private String txCVN = ""; + private String txOption1 = ""; + private String txOption2 = ""; + private String txOption3 = ""; + private String txCustomerIPAddress = ""; + private String txCustomerBillingCountry = ""; + private String txRefundPassword = ""; + + + /** + * Default constructor to be used with the Real-Time payment method. The + * same as calling <code>GatewayRequest(0)</code>; + */ + public GatewayRequest() { + requestMethod = 0; + } + + /** + * Constructor to be used with the CVN and Beagle payment methods. + * @param method Logical combination of the REQUEST_METHOD_CVN and + * REQUEST_METHOD_BEAGLE constants. + */ + public GatewayRequest(int method) { + requestMethod = method; + } + + /** + * Gets the request method given when constructing the object. + * @return the request method as a logical combination of the + * REQUEST_METHOD_CVN and REQUEST_METHOD_BEAGLE constants. + */ + public int getRequestMethod() { + return requestMethod; + } + + /** + * Gets the URL for the configured request + */ + public String getUrl() { + if ((requestMethod & REQUEST_METHOD_REFUND) != 0) { + if (isTestMode()) { + return null; + } else { + return REQUEST_URL_REFUND; + } + } else if ((requestMethod & REQUEST_METHOD_BEAGLE) != 0) { + if (isTestMode()) { + return REQUEST_URL_BEAGLE_TEST; + } else { + return REQUEST_URL_BEAGLE; + } + } else if ((requestMethod & REQUEST_METHOD_CVN) != 0) { + if (isTestMode()) { + return REQUEST_URL_CVN_TEST; + } else { + return REQUEST_URL_CVN; + } + } else { + if (isTestMode()) { + return REQUEST_URL_RT_TEST; + } else { + return REQUEST_URL_RT; + } + } + } + + /* + * Getters and setters follow for each defined field of the request. + */ + + public String getCustomerID() { + return txCustomerID; + } + + public void setCustomerID(String value) { + txCustomerID = value; + } + + public String getRefundPassword() { + return txRefundPassword; + } + + public void setRefundPassword(String value) { + txRefundPassword = value; + } + + public BigDecimal getTotalAmount() { + return txTotalAmount; + } + + public void setTotalAmount(BigDecimal value) { + txTotalAmount = value; + } + + public String getCardHoldersName() { + return txCardHoldersName; + } + + public void setCardHoldersName(String value) { + txCardHoldersName = value; + } + + public String getCardNumber() { + return txCardNumber; + } + + public void setCardNumber(String value) { + txCardNumber = value; + } + + public String getCardExpiryMonth() { + return txCardExpiryMonth; + } + + public void setCardExpiryMonth(String value) { + txCardExpiryMonth = value; + } + + public String getCardExpiryYear() { + return txCardExpiryYear; + } + + public void setCardExpiryYear(String value) { + txCardExpiryYear = value; + } + + public String getTrxnNumber() { + return txTrxnNumber; + } + + public void setTrxnNumber(String value) { + txTrxnNumber = value; + } + + public String getCustomerFirstName() { + return txCustomerFirstName; + } + + public void setCustomerFirstName(String value) { + txCustomerFirstName = value; + } + + public String getCustomerLastName() { + return txCustomerLastName; + } + + public void setCustomerLastName(String value) { + txCustomerLastName = value; + } + + public String getCustomerEmailAddress() { + return txCustomerEmailAddress; + } + + public void setCustomerEmailAddress(String value) { + txCustomerEmailAddress = value; + } + + public String getCustomerAddress() { + return txCustomerAddress; + } + + public void setCustomerAddress(String value) { + txCustomerAddress = value; + } + + public String getCustomerPostcode() { + return txCustomerPostcode; + } + + public void setCustomerPostcode(String value) { + txCustomerPostcode = value; + } + + public String getCustomerInvoiceRef() { + return txCustomerInvoiceRef; + } + + public void setCustomerInvoiceRef(String value) { + txCustomerInvoiceRef = value; + } + + public String getCustomerInvoiceDescription() { + return txCustomerInvoiceDescription; + } + + public void setCustomerInvoiceDescription(String value) { + txCustomerInvoiceDescription = value; + } + + public String getCVN() { + return txCVN; + } + + public void setCVN(String value) { + txCVN = value; + } + + public String getOption1() { + return txOption1; + } + + public void setOption1(String value) { + txOption1 = value; + } + + public String getOption2() { + return txOption2; + } + + public void setOption2(String value) { + txOption2 = value; + } + + public String getOption3() { + return txOption3; + } + + public void setOption3(String value) { + txOption3 = value; + } + + public String getCustomerIPAddress() { + return txCustomerIPAddress; + } + + public void setCustomerIPAddress(String value) { + txCustomerIPAddress = value; + } + + public String getCustomerBillingCountry() { + return txCustomerBillingCountry; + } + + public void setCustomerBillingCountry(String value) { + txCustomerBillingCountry = value; + } + + public boolean isTestMode() { + return isTestMode; + } + + public void setTestMode(boolean b) { + isTestMode = b; + } + + /** + * Gives the xml representation of this object. This xml will be sent to + * the gateway. This method is public only for debugging purposes, you + * might wish to examine the xml content. The special fields of the CVN + * and Beagle requests are added only if the request belongs to the CVN or + * Beagle types, respectively. + * @return The GatewayRequest object as an xml string. + */ + public String toXml() { + // We don't really need the overhead of creating an XML DOM object + // just to concatenate a String together. + + Integer totalInt = txTotalAmount.multiply(new BigDecimal(100)).intValue(); + + StringBuffer xml = new StringBuffer("<ewaygateway>"); + xml.append(createNode("ewayCustomerID", txCustomerID)); + xml.append(createNode("ewayTotalAmount", "" + totalInt)); + xml.append(createNode("ewayCustomerInvoiceRef", txCustomerInvoiceRef)); + xml.append(createNode("ewayCardExpiryMonth", txCardExpiryMonth)); + xml.append(createNode("ewayCardExpiryYear", txCardExpiryYear)); + + // all charge methods (not refund) + if (requestMethod != REQUEST_METHOD_REFUND) { + xml.append(createNode("ewayCardHoldersName", txCardHoldersName)); + xml.append(createNode("ewayCardNumber", txCardNumber)); + xml.append(createNode("ewayTrxnNumber", txTrxnNumber)); + xml.append(createNode("ewayCustomerInvoiceDescription", txCustomerInvoiceDescription)); + xml.append(createNode("ewayCustomerFirstName", txCustomerFirstName)); + xml.append(createNode("ewayCustomerLastName", txCustomerLastName)); + xml.append(createNode("ewayCustomerEmail", txCustomerEmailAddress)); + xml.append(createNode("ewayCustomerAddress", txCustomerAddress)); + xml.append(createNode("ewayCustomerPostcode", txCustomerPostcode)); + } + + // fill in also CVN data if the request is of CVN type + if (requestMethod == REQUEST_METHOD_CVN || requestMethod == REQUEST_METHOD_BEAGLE) { + xml.append(createNode("ewayCVN", txCVN)); + } + + xml.append(createNode("ewayOption1", txOption1)); + xml.append(createNode("ewayOption2", txOption2)); + xml.append(createNode("ewayOption3", txOption3)); + + // fill in also Beagle data if the request is of Beagle type + if (requestMethod == REQUEST_METHOD_BEAGLE) { + xml.append(createNode("ewayCustomerIPAddress", txCustomerIPAddress)); + xml.append(createNode("ewayCustomerBillingCountry", + txCustomerBillingCountry)); + } + + // fill in the refund password if REFUND type + if (requestMethod == REQUEST_METHOD_REFUND) { + xml.append(createNode("ewayOriginalTrxnNumber", txTrxnNumber)); + xml.append(createNode("ewayRefundPassword", txRefundPassword)); + } + + xml.append("</ewaygateway>"); + + // log the request for test mode + if (isTestMode()) { + Debug.logInfo("[eWay Request] : " + xml.toString(), module); + } + + return xml.toString(); + } + + /** + * Helper method to build an XML node. + * + * @param nodeName + * The name of the node being created. + * @param nodeValue + * The value of the node being created. + * @return An XML node as a String in <nodName>nodeValue</nodeName> format + */ + private String createNode(String nodeName, String nodeValue) { + return "<" + nodeName + ">" + nodeValue + "</" + nodeName + ">"; + } +} Added: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayResponse.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayResponse.java?rev=1053723&view=auto ============================================================================== --- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayResponse.java (added) +++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/thirdparty/eway/GatewayResponse.java Wed Dec 29 20:05:11 2010 @@ -0,0 +1,208 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.accounting.thirdparty.eway; + +import java.io.InputStream; +import java.math.BigDecimal; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.ofbiz.base.util.Debug; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +/** + * A class representing the payment gateway's response to a request. It holds + * fields of the response which are filled in when the response arrives and + * available through getter methods. This response class supports all 3 payment + * methods. + * + * Based on public domain sample code provided by eWay.com.au + */ +public class GatewayResponse { + + private static final String module = GatewayResponse.class.getName(); + + // private field definitions, values are set to default + + private double txBeagleScore = -1; + private int txReturnAmount = 0; + + private boolean txTrxnStatus = false; + + private String txTrxnNumber = ""; + private String txTrxnReference = ""; + private String txTrxnOption1 = ""; + private String txTrxnOption2 = ""; + private String txTrxnOption3 = ""; + private String txAuthCode = ""; + private String txTrxnError = ""; + + // getter methods for the response fields + + public String getTrxnNumber() { + return txTrxnNumber; + } + + public String getTrxnReference() { + return txTrxnReference; + } + + public String getTrxnOption1() { + return txTrxnOption1; + } + + public String getTrxnOption2() { + return txTrxnOption2; + } + + public String getTrxnOption3() { + return txTrxnOption3; + } + + public String getAuthCode() { + return txAuthCode; + } + + public String getTrxnError() { + return txTrxnError; + } + + public int getReturnAmount() { + return txReturnAmount; + } + + public BigDecimal getTransactionAmount() { + BigDecimal amt = new BigDecimal(getReturnAmount()); + amt = amt.divide(new BigDecimal(100)); + return amt.setScale(2, BigDecimal.ROUND_HALF_UP); + } + + public boolean getTrxnStatus() { + return txTrxnStatus; + } + + /** + * Gets the beagle score. Defaults to -1 in case of non-Beagle payment + * methods or if the response does not contain this field. + * + * @return The beagle score or -1 if it was not defined in the response + */ + public double getBeagleScore() { + return txBeagleScore; + } + + /** + * Creates the GatewayResponse object by parsing an xml from a stream. Fills + * in the fields of the object that are available through getters after this + * method returns. + * + * @param xmlstream + * the stream to parse the response from + * @throws Exception + * if the xml contains a root element with a bad name or an + * unknown element, or if the xml is badly formatted + */ + public GatewayResponse(InputStream xmlstream, GatewayRequest req) throws Exception { + + DocumentBuilderFactory builderFactory = DocumentBuilderFactory + .newInstance(); + DocumentBuilder builder = builderFactory.newDocumentBuilder(); + Document doc = builder.parse(xmlstream); + + // get the root node + Node rootnode = doc.getDocumentElement(); + String root = rootnode.getNodeName(); + + if (root != "ewayResponse") { + throw new Exception("Bad root element in response: " + root); + } + + // get all elements + NodeList list = doc.getElementsByTagName("*"); + for (int i = 0; i < list.getLength(); i++) { + Node node = list.item(i); + String name = node.getNodeName(); + if (name == "ewayResponse") + continue; + Text textnode = (Text) node.getFirstChild(); + String value = ""; + if (textnode != null) + value = textnode.getNodeValue(); + + if (name == "ewayTrxnError") + txTrxnError = value; + else if (name == "ewayTrxnStatus") { + if (value.toLowerCase().trim().equals("true")) { + txTrxnStatus = true; + } + } + else if (name == "ewayTrxnNumber") + txTrxnNumber = value; + else if (name == "ewayTrxnOption1") + txTrxnOption1 = value; + else if (name == "ewayTrxnOption2") + txTrxnOption2 = value; + else if (name == "ewayTrxnOption3") + txTrxnOption3 = value; + else if (name == "ewayReturnAmount") { + if (!value.equals("")) { + txReturnAmount = Integer.parseInt(value); + } + } + else if (name == "ewayAuthCode") + txAuthCode = value; + else if (name == "ewayTrxnReference") + txTrxnReference = value; + else if (name == "ewayBeagleScore") { + if (!value.equals("")) { + txBeagleScore = Double.parseDouble(value); + } + } + else { + throw new Exception("Unknown field in response: " + name); + } + } + + if (req.isTestMode()) { + Debug.logInfo("[eWay Reply]\n" + this.toString(), module); + } + } + + @Override + public String toString() { + StringBuffer buf = new StringBuffer(); + buf.append("<ewayResponse>").append("\n"); + buf.append("\t<ewayTrxnError>").append(txTrxnError).append("</ewayTrxnError>\n"); + buf.append("\t<ewayTrxnStatus>").append(txTrxnStatus).append("</ewayTrxnStatus>\n"); + buf.append("\t<ewayTrxnNumber>").append(txTrxnNumber).append("</ewayTrxnNumber>\n"); + buf.append("\t<ewayTrxnOption1>").append(txTrxnOption1).append("</ewayTrxnOption1>\n"); + buf.append("\t<ewayTrxnOption2>").append(txTrxnOption2).append("</ewayTrxnOption2>\n"); + buf.append("\t<ewayTrxnOption3>").append(txTrxnOption3).append("</ewayTrxnOption3>\n"); + buf.append("\t<ewayReturnAmount>").append(txReturnAmount).append("</ewayReturnAmount>\n"); + buf.append("\t<ewayAuthCode>").append(txAuthCode).append("</ewayAuthCode>\n"); + buf.append("\t<ewayBeagleScore>").append(txBeagleScore).append("</ewayBeagleScore>\n"); + buf.append("\t<ewayTrxnReference>").append(txTrxnReference).append("</ewayTrxnReference>\n"); + buf.append("</ewayResponse>").append("\n"); + return buf.toString(); + } +} Modified: ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml?rev=1053723&r1=1053722&r2=1053723&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml (original) +++ ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigForms.xml Wed Dec 29 20:05:11 2010 @@ -315,6 +315,32 @@ under the License. </field> </form> + <form name="EditPaymentGatewayConfigEway" type="single" target="UpdatePaymentGatewayConfigClearCommerce" default-map-name="paymentGatewayClearCommerce" header-row-style="header-row" default-table-style="basic-table"> + <auto-fields-entity entity-name="PaymentGatewayEway" default-field-type="edit"/> + <field name="paymentGatewayConfigId"><hidden/></field> + <field name="testMode"> + <drop-down> + <option key="Y" description="${uiLabelMap.CommonYes}"/> + <option key="N" description="${uiLabelMap.CommonNo}"/> + </drop-down> + </field> + <field name="enableBeagle"> + <drop-down> + <option key="Y" description="${uiLabelMap.CommonYes}"/> + <option key="N" description="${uiLabelMap.CommonNo}"/> + </drop-down> + </field> + <field name="enableCvn"> + <drop-down> + <option key="Y" description="${uiLabelMap.CommonYes}"/> + <option key="N" description="${uiLabelMap.CommonNo}"/> + </drop-down> + </field> + <field name="submitButton" title="${uiLabelMap.CommonUpdate}" widget-style="smallSubmit"> + <submit button-type="button"/> + </field> + </form> + <form name="EditPaymentGatewayConfigWorldPay" type="single" target="UpdatePaymentGatewayConfigWorldPay" default-map-name="paymentGatewayWorldPay" header-row-style="header-row" default-table-style="basic-table"> <auto-fields-entity entity-name="PaymentGatewayWorldPay" default-field-type="edit"/> <field name="paymentGatewayConfigId"><hidden/></field> Modified: ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigScreens.xml?rev=1053723&r1=1053722&r2=1053723&view=diff ============================================================================== --- ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigScreens.xml (original) +++ ofbiz/trunk/applications/accounting/widget/PaymentGatewayConfigScreens.xml Wed Dec 29 20:05:11 2010 @@ -95,6 +95,9 @@ under the License. <entity-one entity-name="PaymentGatewayCyberSource" value-field="paymentGatewayCyberSource"> <field-map field-name="paymentGatewayConfigId" from-field="parameters.paymentGatewayConfigId"/> </entity-one> + <entity-one entity-name="PaymentGatewayEway" value-field="paymentGatewayEway"> + <field-map field-name="paymentGatewayConfigId" from-field="parameters.paymentGatewayConfigId"/> + </entity-one> <entity-one entity-name="PaymentGatewayPayflowPro" value-field="paymentGatewayPayflowPro"> <field-map field-name="paymentGatewayConfigId" from-field="parameters.paymentGatewayConfigId"/> </entity-one> @@ -208,6 +211,16 @@ under the License. </screenlet> </widgets> </section> + <section> + <condition> + <not><if-empty field="paymentGatewayEway"/></not> + </condition> + <widgets> + <screenlet title="${uiLabelMap.PageTitleUpdatePaymentGatewayConfigClearCommerce}"> + <include-form name="EditPaymentGatewayConfigEway" location="component://accounting/widget/PaymentGatewayConfigForms.xml"/> + </screenlet> + </widgets> + </section> </decorator-section> </decorator-screen> </widgets> |
Free forum by Nabble | Edit this page |