diff --git a/firstdatapaymentgateway/README.adoc b/firstdatapaymentgateway/README.adoc
new file mode 100644
index 000000000..6621b7383
--- /dev/null
+++ b/firstdatapaymentgateway/README.adoc
@@ -0,0 +1,25 @@
+[[FirstDataPaymentGateway]]
+= First Data Payment Gateway
+
+[[steps-to-integrate]]
+== Steps to integrate First Data Payment Gateway with Apache OFBiz
+
+* Checkout or install the "firstdatapaymentgateway" plugin from the Apache OFBiz repository.
+https://github.com/apache/ofbiz-plugins.git
+* Make sure you load the data from following files manually or using loadAll command.
+** FirstDataTypeData.xml
+** FirstDataSecurityPermissionSeedData.xml
+** FirstDataSecurityGroupDemoData.xml
+** FirstDataDemoData.xml
+* Make sure you have created your test account on First Data and you have enabled REST APIs for your test merchant account.
+Also you have got following configuration parameters from the First Data against your merchant account.
+** App Name
+** API Key
+** API Secret
+* Now build and start the server.
+* Hit following URL and use admin credentials for login.
+`https://localhost:8443/firstdata/control/main`
+* Fill in the configuration parameters which you have got from First Data in appropriate fields.
+Transaction URL to be entered should be of sandbox server.
+`https://cert.api.firstdata.com/gateway/v2`
+* Now you can place order and check transactions like Auth, Capture, Refund and Release.
\ No newline at end of file
diff --git a/firstdatapaymentgateway/build.gradle b/firstdatapaymentgateway/build.gradle
new file mode 100644
index 000000000..3ebcfec5a
--- /dev/null
+++ b/firstdatapaymentgateway/build.gradle
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+dependencies {
+ //Examples of compile-time and runtime dependencies
+
+ //pluginLibsCompile 'junit:junit-dep:4.10'
+ //pluginLibsRuntime 'junit:junit-dep:4.10'
+}
\ No newline at end of file
diff --git a/firstdatapaymentgateway/config/FirstDataUiLabels.xml b/firstdatapaymentgateway/config/FirstDataUiLabels.xml
new file mode 100644
index 000000000..93ec755a9
--- /dev/null
+++ b/firstdatapaymentgateway/config/FirstDataUiLabels.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+ FirstData Application
+ FirstData应用程序
+ FirstData應用程式
+
+
+ OFBiz: FirstData
+ OFBiz: FirstData
+
+
+ Part of the Apache OFBiz Family of Open Source Software
+ Un modulo della famiglia di software open source Apache OFBiz
+ 开源软件OFBiz的组成部分
+ 開源軟體OFBiz的組成部分
+
+
+ You are not allowed to view this page.
+ 不允许你浏览这个页面。
+ 不允許您檢視這個頁面.
+
+
+ First Data Configurations
+
+
+ Edit Configurations
+
+
+ App Name
+
+
+ API Key
+
+
+ API Secret
+
+
+ Transaction URL
+
+
+ Enable Data Vault
+
+
diff --git a/firstdatapaymentgateway/config/firstdata.properties b/firstdatapaymentgateway/config/firstdata.properties
new file mode 100644
index 000000000..82dc3d2d3
--- /dev/null
+++ b/firstdatapaymentgateway/config/firstdata.properties
@@ -0,0 +1,23 @@
+###############################################################################
+# 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.
+###############################################################################
+
+paymentgateway.firstdata.template.preauth.location=component://firstdatapaymentgateway/template/FirstDataPreAuthTemplate.json.ftl
+paymentgateway.firstdata.template.postauth.location=component://firstdatapaymentgateway/template/FirstDataPostAuthTemplate.json.ftl
+paymentgateway.firstdata.template.refund.location=component://firstdatapaymentgateway/template/FirstDataRefundTemplate.json.ftl
+paymentgateway.firstdata.template.release.location=component://firstdatapaymentgateway/template/FirstDataReleaseTemplate.json.ftl
\ No newline at end of file
diff --git a/firstdatapaymentgateway/data/FirstDataDemoData.xml b/firstdatapaymentgateway/data/FirstDataDemoData.xml
new file mode 100644
index 000000000..e73b58ac5
--- /dev/null
+++ b/firstdatapaymentgateway/data/FirstDataDemoData.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/firstdatapaymentgateway/data/FirstDataSecurityGroupDemoData.xml b/firstdatapaymentgateway/data/FirstDataSecurityGroupDemoData.xml
new file mode 100644
index 000000000..ee7d7c21e
--- /dev/null
+++ b/firstdatapaymentgateway/data/FirstDataSecurityGroupDemoData.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/firstdatapaymentgateway/data/FirstDataSecurityPermissionSeedData.xml b/firstdatapaymentgateway/data/FirstDataSecurityPermissionSeedData.xml
new file mode 100644
index 000000000..3d6e7b76e
--- /dev/null
+++ b/firstdatapaymentgateway/data/FirstDataSecurityPermissionSeedData.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/firstdatapaymentgateway/data/FirstDataTypeData.xml b/firstdatapaymentgateway/data/FirstDataTypeData.xml
new file mode 100644
index 000000000..c2abb7d61
--- /dev/null
+++ b/firstdatapaymentgateway/data/FirstDataTypeData.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/firstdatapaymentgateway/entitydef/entitymodel.xml b/firstdatapaymentgateway/entitydef/entitymodel.xml
new file mode 100644
index 000000000..57c9cfc8c
--- /dev/null
+++ b/firstdatapaymentgateway/entitydef/entitymodel.xml
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+ Entity of FirstData Component
+ None
+
+
+
+
+
+ App Name
+ API Key
+ API Secret
+ Transaction URL Test or Live
+ Enable Data Vault
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/firstdatapaymentgateway/ofbiz-component.xml b/firstdatapaymentgateway/ofbiz-component.xml
new file mode 100644
index 000000000..10cec1a43
--- /dev/null
+++ b/firstdatapaymentgateway/ofbiz-component.xml
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/firstdatapaymentgateway/servicedef/services.xml b/firstdatapaymentgateway/servicedef/services.xml
new file mode 100644
index 000000000..b552fd9e1
--- /dev/null
+++ b/firstdatapaymentgateway/servicedef/services.xml
@@ -0,0 +1,54 @@
+
+
+
+
+ FirstData Services
+
+ 1.0
+
+
+ Update a PaymentGatwayFirstData
+
+
+
+
+
+
+ First Data Payment Authorization Service
+
+
+
+ First Data Payment Capture Service
+
+
+
+ First Data Payment Release Service
+
+
+
+ First Data Payment Refund Service
+
+
+
\ No newline at end of file
diff --git a/firstdatapaymentgateway/src/main/java/org/apache/ofbiz/firstdatapaymentgateway/FirstDataPaymentServices.java b/firstdatapaymentgateway/src/main/java/org/apache/ofbiz/firstdatapaymentgateway/FirstDataPaymentServices.java
new file mode 100644
index 000000000..a3e63478d
--- /dev/null
+++ b/firstdatapaymentgateway/src/main/java/org/apache/ofbiz/firstdatapaymentgateway/FirstDataPaymentServices.java
@@ -0,0 +1,422 @@
+package org.apache.ofbiz.firstdatapaymentgateway;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import freemarker.template.TemplateException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.codec.digest.HmacAlgorithms;
+import org.apache.commons.codec.digest.HmacUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.apache.ofbiz.base.util.Debug;
+import org.apache.ofbiz.base.util.UtilValidate;
+import org.apache.ofbiz.base.util.template.FreeMarkerWorker;
+import org.apache.ofbiz.entity.Delegator;
+import org.apache.ofbiz.entity.GenericEntityException;
+import org.apache.ofbiz.entity.GenericValue;
+import org.apache.ofbiz.entity.util.EntityQuery;
+import org.apache.ofbiz.entity.util.EntityUtilProperties;
+import org.apache.ofbiz.service.DispatchContext;
+import org.apache.ofbiz.service.ModelService;
+import org.apache.ofbiz.service.ServiceUtil;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+public class FirstDataPaymentServices {
+ private static final String MODULE = FirstDataPaymentServices.class.getName();
+
+ private static Properties FDProperties = null;
+
+ public static Map ccAuth(DispatchContext ctx, Map context) {
+ Delegator delegator = ctx.getDelegator();
+ BigDecimal processAmount = (BigDecimal) context.get("processAmount");
+ String orderId = (String) context.get("orderId");
+ String currency = (String) context.get("currency");
+ String cardSecurityCode = (String) context.get("cardSecurityCode");
+ GenericValue creditCard = (GenericValue) context.get("creditCard");
+ String paymentGatewayConfigId = (String) context.get("paymentGatewayConfigId");
+ Map result = ServiceUtil.returnSuccess();
+ result.put("processAmount", processAmount);
+ Boolean isSuccess = Boolean.FALSE;
+ String cardNumber = creditCard.getString("cardNumber");
+
+ try {
+ String clientRequestId = UUID.randomUUID().toString();
+ String epochTime = String.valueOf(System.currentTimeMillis());
+ Date expireDate = new SimpleDateFormat("MM/yyyy").parse(creditCard.getString("expireDate"));
+ SimpleDateFormat df = new SimpleDateFormat("MM");
+ String strMonth = df.format(expireDate);
+ df = new SimpleDateFormat("yy");
+ String strYear = df.format(expireDate);
+
+ Map ccAuthReqContext = new HashMap();
+ ccAuthReqContext.put("amount", processAmount);
+ ccAuthReqContext.put("currency", currency);
+ ccAuthReqContext.put("cardSecurityCode", cardSecurityCode);
+ ccAuthReqContext.put("cardNumber", cardNumber);
+ ccAuthReqContext.put("expireMonth", strMonth);
+ ccAuthReqContext.put("expireYear", strYear);
+
+ StringWriter outWriter = new StringWriter();
+ String firstDataPreAuthTemplate = EntityUtilProperties.getPropertyValue("firstdata", "paymentgateway.firstdata.template.preauth.location", delegator);
+ FreeMarkerWorker.renderTemplate(firstDataPreAuthTemplate, ccAuthReqContext, outWriter);
+ String requestBody = outWriter.toString();
+
+ String messageSignature = buildMessageSignature(paymentGatewayConfigId, requestBody, clientRequestId, epochTime, delegator);
+
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ StringEntity stringEntity = new StringEntity(requestBody);
+ HttpPost httpPost = new HttpPost(FDProperties.getProperty("transactionUrl") + "/payments");
+ httpPost.setEntity(stringEntity);
+ httpPost.setHeader("Client-Request-Id", clientRequestId);
+ httpPost.setHeader("Api-Key", FDProperties.getProperty("apiKey"));
+ httpPost.setHeader("Timestamp", epochTime);
+ httpPost.setHeader("Message-Signature", messageSignature);
+ httpPost.setHeader("Content-Type", "application/json");
+
+ CloseableHttpResponse response = httpClient.execute(httpPost);
+
+ HttpEntity entity = response.getEntity();
+ String responseString = EntityUtils.toString(entity);
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map convertedMap = objectMapper.readValue(responseString, new TypeReference