diff --git a/.project b/.project
index db929a9..461de1e 100644
--- a/.project
+++ b/.project
@@ -15,9 +15,15 @@
+
+ org.eclipse.babel.editor.rbeBuilder
+
+
+
org.eclipse.jdt.core.javanature
org.eclipse.m2e.core.maven2Nature
+ com.jaspersoft.studio.babel.editor.rbeNature
diff --git a/src/main/java/com/test/world/config/PaymentConfig.java b/src/main/java/com/test/world/config/PaymentConfig.java
new file mode 100644
index 0000000..b91250b
--- /dev/null
+++ b/src/main/java/com/test/world/config/PaymentConfig.java
@@ -0,0 +1,77 @@
+package com.test.world.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+@Configuration
+@PropertySource("classpath:paymentConfig.properties")
+public class PaymentConfig {
+
+ @Value("${payment.worldline.merchantId}")
+ private String merchantId;
+
+ @Value("${payment.worldline.encryptionKey}")
+ private String encryptionKey;
+
+ @Value("${payment.worldline.encryptionIV}")
+ private String encryptionIV;
+
+ @Value("${payment.worldline.schemeCode}")
+ private String schemeCode;
+
+ @Value("${payment.worldline.merchantName}")
+ private String merchantName;
+
+
+ public String getMerchantId() {
+ return merchantId;
+ }
+
+ public void setMerchantId(String merchantId) {
+ this.merchantId = merchantId;
+ }
+
+ public String getEncryptionKey() {
+ return encryptionKey;
+ }
+ public byte[] getEncryptionKeyByte() {
+ return encryptionKey.getBytes();
+ }
+
+ public void setEncryptionKey(String encryptionKey) {
+ this.encryptionKey = encryptionKey;
+ }
+
+ public String getEncryptionIV() {
+ return encryptionIV;
+ }
+
+ public byte[] getEncryptionIVByte() {
+ return encryptionIV.getBytes();
+ }
+
+ public void setEncryptionIV(String encryptionIV) {
+ this.encryptionIV = encryptionIV;
+ }
+
+ public String getSchemeCode() {
+ return schemeCode;
+ }
+
+ public void setSchemeCode(String schemeCode) {
+ this.schemeCode = schemeCode;
+ }
+
+ public String getMerchantName() {
+ return merchantName;
+ }
+
+ public void setMerchantName(String merchantName) {
+ this.merchantName = merchantName;
+ }
+
+
+
+
+}
diff --git a/src/main/java/com/test/world/controller/APIController.java b/src/main/java/com/test/world/controller/APIController.java
index 8cda991..ce2bd33 100644
--- a/src/main/java/com/test/world/controller/APIController.java
+++ b/src/main/java/com/test/world/controller/APIController.java
@@ -20,6 +20,7 @@ import com.test.world.DTO.PensionerResponse;
import com.test.world.DTO.RefundRequest;
import com.test.world.DTO.Transaction;
import com.test.world.DTO.TransactionData;
+import com.test.world.config.PaymentConfig;
import com.test.world.refund.DTO.TransactionRefundResponse;
import com.test.world.service.PaymentGatewayService;
@@ -28,6 +29,10 @@ public class APIController {
@Autowired
PaymentGatewayService paymentService;
+
+ @Autowired
+ private PaymentConfig paymentConfig;
+
@GetMapping("/api/all")
public PensionerResponse getAll() {
@@ -59,15 +64,15 @@ public class APIController {
public ResponseEntity> refundAmount(Model model) throws Exception {
System.out.println("Refund Api call.......working on it");
Merchant merchant = new Merchant();
- merchant.setIdentifier("T955031");
+ merchant.setIdentifier(this.paymentConfig.getMerchantId());
Transaction transaction = new Transaction();
- transaction.setAmount("10.00");
+ transaction.setAmount("10.00");//Amount given here
transaction.setIdentifier("");
- transaction.setDateTime("17-02-2024");
+ transaction.setDateTime("17-02-2024"); //At what date transaction happens
transaction.setRequestType("R");
transaction.setToken("");
- transaction.setReference("1707115835226");
+ transaction.setReference("1707115835226"); //transaction refer number
TransactionData transactionData = new TransactionData();
@@ -80,22 +85,24 @@ public class APIController {
// Print the JSON string
System.out.println(json);
- String enKey = "1025180466GPADTD";
- String enIV="3232693456UWOWHC";
- String encryptHxRefund = this.paymentService.encryptHxRefund(json, enIV.getBytes(), enKey.getBytes());
+ String encryptHxRefund = this.paymentService.encryptHxRefund(json);
RestTemplate resttemplate = new RestTemplate();
- String Url ="https://www.tpsl-india.in/PaymentGateway/merchant2.pg/T955031";
+ String Url ="https://www.tpsl-india.in/PaymentGateway/merchant2.pg/"+this.paymentConfig.getMerchantId();
ResponseEntity postForEntity = resttemplate.postForEntity(Url, encryptHxRefund, String.class);
- String decryptHxTRefund = this.paymentService.decryptHxTRefund(postForEntity.getBody(), enIV.getBytes(), enKey.getBytes());
+ String decryptHxTRefund = this.paymentService.decryptHxTRefund(postForEntity.getBody());
try {
ObjectMapper objectMapper = new ObjectMapper();
- // Deserialize JSON string into Java class object
+ // Deserialize JSON string into Java class object
TransactionRefundResponse myObject = objectMapper.readValue(decryptHxTRefund, TransactionRefundResponse.class);
// Print the object
System.out.println(myObject.toString());
+ if(myObject.getTransactionState().equals("S")) {
+ //Refund Amount sent successfully Set Logic here after refund
+ }
+
return ResponseEntity.ok(myObject);
} catch (Exception e) {
diff --git a/src/main/java/com/test/world/controller/PaymentController.java b/src/main/java/com/test/world/controller/PaymentController.java
index 6f0329e..2ae75da 100644
--- a/src/main/java/com/test/world/controller/PaymentController.java
+++ b/src/main/java/com/test/world/controller/PaymentController.java
@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.test.world.DTO.RefundRequest;
+import com.test.world.config.PaymentConfig;
import com.test.world.service.PaymentGatewayService;
@@ -25,12 +26,17 @@ public class PaymentController {
@Autowired
PaymentGatewayService paymentService;
+ @Autowired
+ private PaymentConfig paymentConfig;
+
@GetMapping(value = {"","/","/index"})
public String startPayment(Model model) throws NoSuchAlgorithmException {
+ System.out.println("Merchant ID:-"+this.paymentConfig.getMerchantId());
+
String txansactionId="1707115835226"; //create transaction Id unique from our side
String amt = "10"; //Amount of Community Hall from our side
- String merchantId="T955031|"; //This is Test Merchant ID from worldLine
+ String merchantId = this.paymentConfig.getMerchantId()+"|"; //This is Test Merchant ID from worldLine
String txnId= txansactionId+"|";
String totalAmt=amt+"|";
String accountNo="|";
@@ -46,7 +52,7 @@ public class PaymentController {
String expMonth="|";
String expYear="|";
String cvvCode="|";
- String salt="1025180466GPADTD";
+ String salt=this.paymentConfig.getEncryptionKey();
String token=merchantId+txnId+totalAmt+accountNo+consumerId+consumerMobileNo+
consumerEmailId+debitStartDate+debitEndDate+maxAmount+amountType+
frequency+cardNumber+expMonth+expYear+cvvCode+salt;
@@ -56,6 +62,7 @@ public class PaymentController {
model.addAttribute("txansactionId",txansactionId);
model.addAttribute("token",encryptedtoken);
model.addAttribute("amount",amt);
+ model.addAttribute("merchantId",this.paymentConfig.getMerchantId());
return "index";
}
@@ -95,29 +102,25 @@ public class PaymentController {
}
- @GetMapping(value="/refund")
- public String refundAmount(Model model) {
- System.out.println("Refund Api call.......working on it");
- RefundRequest rr = new RefundRequest();
- HashMap merchant = new HashMap();
- merchant.put("identifier", "T955031");
- rr.setMerchant(merchant);
-
- HashMap transaction = new HashMap();
- transaction.put("amount", "10");
- transaction.put("identifier", "");
- transaction.put("dateTime", "");
- transaction.put("requestType", "R");
- transaction.put("token", "");
- transaction.put("reference", "1707115835225");
- rr.setTransaction(transaction);
- model.addAttribute("msg",rr);
-
-
-
- return "PaymentResponse";
-
- }
+ /*
+ * @GetMapping(value="/refund") public String refundAmount(Model model) {
+ * System.out.println("Refund Api call.......working on it"); RefundRequest rr =
+ * new RefundRequest(); HashMap merchant = new
+ * HashMap(); merchant.put("identifier",
+ * this.paymentConfig.getMerchantId()); rr.setMerchant(merchant);
+ *
+ * HashMap transaction = new HashMap();
+ * transaction.put("amount", "10"); transaction.put("identifier", "");
+ * transaction.put("dateTime", ""); transaction.put("requestType", "R");
+ * transaction.put("token", ""); transaction.put("reference", "1707115835225");
+ * rr.setTransaction(transaction); model.addAttribute("msg",rr);
+ *
+ *
+ *
+ * return "PaymentResponse";
+ *
+ * }
+ */
}
diff --git a/src/main/java/com/test/world/service/PaymentGatewayService.java b/src/main/java/com/test/world/service/PaymentGatewayService.java
index 20ecaf6..294e8e1 100644
--- a/src/main/java/com/test/world/service/PaymentGatewayService.java
+++ b/src/main/java/com/test/world/service/PaymentGatewayService.java
@@ -12,9 +12,9 @@ import javax.crypto.NoSuchPaddingException;
public interface PaymentGatewayService {
public String generateToken(String token)throws NoSuchAlgorithmException;
- public String encryptHxRefund(String text, byte[] iv, byte[] key) throws Exception;
+ public String encryptHxRefund(String text) throws Exception;
public String ToHexStrRefund(byte[] dataBuf);
- public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception;
+ public String decryptHxTRefund(String hxstrr) throws Exception;
public byte[] FromHexStr (String hxStr);
}
diff --git a/src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java b/src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
index 26fd231..658105b 100644
--- a/src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
+++ b/src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
@@ -14,11 +14,16 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
-
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import com.test.world.config.PaymentConfig;
+
@Service
public class PaymentGatewayServiceImpl implements PaymentGatewayService {
+
+ @Autowired
+ private PaymentConfig paymentConfig;
@Override
public String generateToken(String token) throws NoSuchAlgorithmException {
@@ -41,10 +46,10 @@ public class PaymentGatewayServiceImpl implements PaymentGatewayService {
//The process of encryption for refund API
@Override
- public String encryptHxRefund(String text, byte[] iv, byte[] key) throws Exception {
+ public String encryptHxRefund(String text) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
- SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
- IvParameterSpec ivSpec = new IvParameterSpec(iv);
+ SecretKeySpec keySpec = new SecretKeySpec(this.paymentConfig.getEncryptionKeyByte(), "AES");
+ IvParameterSpec ivSpec = new IvParameterSpec(this.paymentConfig.getEncryptionIVByte());
cipher.init(1, keySpec, ivSpec);
byte[] results = cipher.doFinal(text.getBytes("UTF-8"));
String hxencstr = ToHexStrRefund(results);
@@ -61,11 +66,11 @@ public class PaymentGatewayServiceImpl implements PaymentGatewayService {
//The process of decryption for refund API
@Override
- public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception{
+ public String decryptHxTRefund(String hxstrr) throws Exception{
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
- SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
- IvParameterSpec ivSpec = new IvParameterSpec(iv);
+ SecretKeySpec keySpec = new SecretKeySpec(this.paymentConfig.getEncryptionKeyByte(), "AES");
+ IvParameterSpec ivSpec = new IvParameterSpec(this.paymentConfig.getEncryptionIVByte());
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
byte[] decbytes = FromHexStr(hxstrr);
diff --git a/src/main/resources/paymentConfig.properties b/src/main/resources/paymentConfig.properties
new file mode 100644
index 0000000..35a3792
--- /dev/null
+++ b/src/main/resources/paymentConfig.properties
@@ -0,0 +1,5 @@
+payment.worldline.merchantId=T955031
+payment.worldline.encryptionKey=1025180466GPADTD
+payment.worldline.encryptionIV=3232693456UWOWHC
+payment.worldline.schemeCode=FIRST
+payment.worldline.merchantName=Greater Chennai Corporation
\ No newline at end of file
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index 14ac23d..22b0ec5 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -26,6 +26,10 @@ var amount="";
amount="[[${amount}]]"
console.log(amount);
+var merchantId="";
+merchantId="[[${merchantId}]]"
+console.log(merchantId);
+
$(document).ready(function() {
function handleResponse(res) {
if (typeof res != "undefined" && typeof res.paymentMethod != "undefined" && typeof res.paymentMethod.paymentTransaction != "undefined" && typeof res.paymentMethod.paymentTransaction.statusCode != "undefined" && res.paymentMethod.paymentTransaction.statusCode == "0300") {
@@ -63,7 +67,7 @@ console.log(amount);
"merchantLogoUrl": "https://upload.wikimedia.org/wikipedia/commons/a/a8/Chennai_Corporation_Emblem.png", //provided merchant logo will be displayed
"merchantName": "Greater Chennai Corporation",
"merchantMsg": "Community Hall Booking",
- "merchantId": "T955031",
+ "merchantId": merchantId,
"currency": "INR",
"consumerId": "c964634",
"consumerMobileNo": "7845014181",
diff --git a/target/classes/com/test/world/config/PaymentConfig.class b/target/classes/com/test/world/config/PaymentConfig.class
new file mode 100644
index 0000000..88029aa
Binary files /dev/null and b/target/classes/com/test/world/config/PaymentConfig.class differ
diff --git a/target/classes/com/test/world/controller/APIController.class b/target/classes/com/test/world/controller/APIController.class
index 9939898..de1743b 100644
Binary files a/target/classes/com/test/world/controller/APIController.class and b/target/classes/com/test/world/controller/APIController.class differ
diff --git a/target/classes/com/test/world/controller/PaymentController.class b/target/classes/com/test/world/controller/PaymentController.class
index 46fbedb..dc02e5d 100644
Binary files a/target/classes/com/test/world/controller/PaymentController.class and b/target/classes/com/test/world/controller/PaymentController.class differ
diff --git a/target/classes/com/test/world/service/PaymentGatewayService.class b/target/classes/com/test/world/service/PaymentGatewayService.class
index fe9dafb..419f8f7 100644
Binary files a/target/classes/com/test/world/service/PaymentGatewayService.class and b/target/classes/com/test/world/service/PaymentGatewayService.class differ
diff --git a/target/classes/com/test/world/service/PaymentGatewayServiceImpl.class b/target/classes/com/test/world/service/PaymentGatewayServiceImpl.class
index 23d2d07..8d72029 100644
Binary files a/target/classes/com/test/world/service/PaymentGatewayServiceImpl.class and b/target/classes/com/test/world/service/PaymentGatewayServiceImpl.class differ
diff --git a/target/classes/paymentConfig.properties b/target/classes/paymentConfig.properties
new file mode 100644
index 0000000..35a3792
--- /dev/null
+++ b/target/classes/paymentConfig.properties
@@ -0,0 +1,5 @@
+payment.worldline.merchantId=T955031
+payment.worldline.encryptionKey=1025180466GPADTD
+payment.worldline.encryptionIV=3232693456UWOWHC
+payment.worldline.schemeCode=FIRST
+payment.worldline.merchantName=Greater Chennai Corporation
\ No newline at end of file
diff --git a/target/classes/templates/index.html b/target/classes/templates/index.html
index 14ac23d..22b0ec5 100644
--- a/target/classes/templates/index.html
+++ b/target/classes/templates/index.html
@@ -26,6 +26,10 @@ var amount="";
amount="[[${amount}]]"
console.log(amount);
+var merchantId="";
+merchantId="[[${merchantId}]]"
+console.log(merchantId);
+
$(document).ready(function() {
function handleResponse(res) {
if (typeof res != "undefined" && typeof res.paymentMethod != "undefined" && typeof res.paymentMethod.paymentTransaction != "undefined" && typeof res.paymentMethod.paymentTransaction.statusCode != "undefined" && res.paymentMethod.paymentTransaction.statusCode == "0300") {
@@ -63,7 +67,7 @@ console.log(amount);
"merchantLogoUrl": "https://upload.wikimedia.org/wikipedia/commons/a/a8/Chennai_Corporation_Emblem.png", //provided merchant logo will be displayed
"merchantName": "Greater Chennai Corporation",
"merchantMsg": "Community Hall Booking",
- "merchantId": "T955031",
+ "merchantId": merchantId,
"currency": "INR",
"consumerId": "c964634",
"consumerMobileNo": "7845014181",