Browse Source

Paymentconfig added

master
mohammedthaqi 3 years ago
parent
commit
addc18b524
  1. 6
      .project
  2. 77
      src/main/java/com/test/world/config/PaymentConfig.java
  3. 25
      src/main/java/com/test/world/controller/APIController.java
  4. 53
      src/main/java/com/test/world/controller/PaymentController.java
  5. 4
      src/main/java/com/test/world/service/PaymentGatewayService.java
  6. 19
      src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
  7. 5
      src/main/resources/paymentConfig.properties
  8. 6
      src/main/resources/templates/index.html
  9. BIN
      target/classes/com/test/world/config/PaymentConfig.class
  10. BIN
      target/classes/com/test/world/controller/APIController.class
  11. BIN
      target/classes/com/test/world/controller/PaymentController.class
  12. BIN
      target/classes/com/test/world/service/PaymentGatewayService.class
  13. BIN
      target/classes/com/test/world/service/PaymentGatewayServiceImpl.class
  14. 5
      target/classes/paymentConfig.properties
  15. 6
      target/classes/templates/index.html

6
.project

@ -15,9 +15,15 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>org.eclipse.babel.editor.rbeBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.jdt.core.javanature</nature> <nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>com.jaspersoft.studio.babel.editor.rbeNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

77
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;
}
}

25
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.RefundRequest;
import com.test.world.DTO.Transaction; import com.test.world.DTO.Transaction;
import com.test.world.DTO.TransactionData; import com.test.world.DTO.TransactionData;
import com.test.world.config.PaymentConfig;
import com.test.world.refund.DTO.TransactionRefundResponse; import com.test.world.refund.DTO.TransactionRefundResponse;
import com.test.world.service.PaymentGatewayService; import com.test.world.service.PaymentGatewayService;
@ -29,6 +30,10 @@ public class APIController {
@Autowired @Autowired
PaymentGatewayService paymentService; PaymentGatewayService paymentService;
@Autowired
private PaymentConfig paymentConfig;
@GetMapping("/api/all") @GetMapping("/api/all")
public PensionerResponse getAll() { public PensionerResponse getAll() {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
@ -59,15 +64,15 @@ public class APIController {
public ResponseEntity<?> refundAmount(Model model) throws Exception { public ResponseEntity<?> refundAmount(Model model) throws Exception {
System.out.println("Refund Api call.......working on it"); System.out.println("Refund Api call.......working on it");
Merchant merchant = new Merchant(); Merchant merchant = new Merchant();
merchant.setIdentifier("T955031");
merchant.setIdentifier(this.paymentConfig.getMerchantId());
Transaction transaction = new Transaction(); Transaction transaction = new Transaction();
transaction.setAmount("10.00");
transaction.setAmount("10.00");//Amount given here
transaction.setIdentifier(""); transaction.setIdentifier("");
transaction.setDateTime("17-02-2024");
transaction.setDateTime("17-02-2024"); //At what date transaction happens
transaction.setRequestType("R"); transaction.setRequestType("R");
transaction.setToken(""); transaction.setToken("");
transaction.setReference("1707115835226");
transaction.setReference("1707115835226"); //transaction refer number
TransactionData transactionData = new TransactionData(); TransactionData transactionData = new TransactionData();
@ -80,14 +85,12 @@ public class APIController {
// Print the JSON string // Print the JSON string
System.out.println(json); 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(); 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<String> postForEntity = resttemplate.postForEntity(Url, encryptHxRefund, String.class); ResponseEntity<String> 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 { try {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
@ -96,6 +99,10 @@ public class APIController {
// Print the object // Print the object
System.out.println(myObject.toString()); System.out.println(myObject.toString());
if(myObject.getTransactionState().equals("S")) {
//Refund Amount sent successfully Set Logic here after refund
}
return ResponseEntity.ok(myObject); return ResponseEntity.ok(myObject);
} catch (Exception e) { } catch (Exception e) {

53
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 org.springframework.web.bind.annotation.RequestParam;
import com.test.world.DTO.RefundRequest; import com.test.world.DTO.RefundRequest;
import com.test.world.config.PaymentConfig;
import com.test.world.service.PaymentGatewayService; import com.test.world.service.PaymentGatewayService;
@ -25,12 +26,17 @@ public class PaymentController {
@Autowired @Autowired
PaymentGatewayService paymentService; PaymentGatewayService paymentService;
@Autowired
private PaymentConfig paymentConfig;
@GetMapping(value = {"","/","/index"}) @GetMapping(value = {"","/","/index"})
public String startPayment(Model model) throws NoSuchAlgorithmException { 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 txansactionId="1707115835226"; //create transaction Id unique from our side
String amt = "10"; //Amount of Community Hall 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 txnId= txansactionId+"|";
String totalAmt=amt+"|"; String totalAmt=amt+"|";
String accountNo="|"; String accountNo="|";
@ -46,7 +52,7 @@ public class PaymentController {
String expMonth="|"; String expMonth="|";
String expYear="|"; String expYear="|";
String cvvCode="|"; String cvvCode="|";
String salt="1025180466GPADTD";
String salt=this.paymentConfig.getEncryptionKey();
String token=merchantId+txnId+totalAmt+accountNo+consumerId+consumerMobileNo+ String token=merchantId+txnId+totalAmt+accountNo+consumerId+consumerMobileNo+
consumerEmailId+debitStartDate+debitEndDate+maxAmount+amountType+ consumerEmailId+debitStartDate+debitEndDate+maxAmount+amountType+
frequency+cardNumber+expMonth+expYear+cvvCode+salt; frequency+cardNumber+expMonth+expYear+cvvCode+salt;
@ -56,6 +62,7 @@ public class PaymentController {
model.addAttribute("txansactionId",txansactionId); model.addAttribute("txansactionId",txansactionId);
model.addAttribute("token",encryptedtoken); model.addAttribute("token",encryptedtoken);
model.addAttribute("amount",amt); model.addAttribute("amount",amt);
model.addAttribute("merchantId",this.paymentConfig.getMerchantId());
return "index"; 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<String,String> merchant = new HashMap<String,String>();
merchant.put("identifier", "T955031");
rr.setMerchant(merchant);
HashMap<String,String> transaction = new HashMap<String,String>();
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<String,String> merchant = new
* HashMap<String,String>(); merchant.put("identifier",
* this.paymentConfig.getMerchantId()); rr.setMerchant(merchant);
*
* HashMap<String,String> transaction = new HashMap<String,String>();
* 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";
*
* }
*/
} }

4
src/main/java/com/test/world/service/PaymentGatewayService.java

@ -12,9 +12,9 @@ import javax.crypto.NoSuchPaddingException;
public interface PaymentGatewayService { public interface PaymentGatewayService {
public String generateToken(String token)throws NoSuchAlgorithmException; 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 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); public byte[] FromHexStr (String hxStr);
} }

19
src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java

@ -14,12 +14,17 @@ import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.test.world.config.PaymentConfig;
@Service @Service
public class PaymentGatewayServiceImpl implements PaymentGatewayService { public class PaymentGatewayServiceImpl implements PaymentGatewayService {
@Autowired
private PaymentConfig paymentConfig;
@Override @Override
public String generateToken(String token) throws NoSuchAlgorithmException { public String generateToken(String token) throws NoSuchAlgorithmException {
System.out.println("Token:-" + token); System.out.println("Token:-" + token);
@ -41,10 +46,10 @@ public class PaymentGatewayServiceImpl implements PaymentGatewayService {
//The process of encryption for refund API //The process of encryption for refund API
@Override @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"); 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); cipher.init(1, keySpec, ivSpec);
byte[] results = cipher.doFinal(text.getBytes("UTF-8")); byte[] results = cipher.doFinal(text.getBytes("UTF-8"));
String hxencstr = ToHexStrRefund(results); String hxencstr = ToHexStrRefund(results);
@ -61,11 +66,11 @@ public class PaymentGatewayServiceImpl implements PaymentGatewayService {
//The process of decryption for refund API //The process of decryption for refund API
@Override @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"); 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); cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
byte[] decbytes = FromHexStr(hxstrr); byte[] decbytes = FromHexStr(hxstrr);

5
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

6
src/main/resources/templates/index.html

@ -26,6 +26,10 @@ var amount="";
amount="[[${amount}]]" amount="[[${amount}]]"
console.log(amount); console.log(amount);
var merchantId="";
merchantId="[[${merchantId}]]"
console.log(merchantId);
$(document).ready(function() { $(document).ready(function() {
function handleResponse(res) { 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") { 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 "merchantLogoUrl": "https://upload.wikimedia.org/wikipedia/commons/a/a8/Chennai_Corporation_Emblem.png", //provided merchant logo will be displayed
"merchantName": "Greater Chennai Corporation", "merchantName": "Greater Chennai Corporation",
"merchantMsg": "Community Hall Booking", "merchantMsg": "Community Hall Booking",
"merchantId": "T955031",
"merchantId": merchantId,
"currency": "INR", "currency": "INR",
"consumerId": "c964634", "consumerId": "c964634",
"consumerMobileNo": "7845014181", "consumerMobileNo": "7845014181",

BIN
target/classes/com/test/world/config/PaymentConfig.class

BIN
target/classes/com/test/world/controller/APIController.class

BIN
target/classes/com/test/world/controller/PaymentController.class

BIN
target/classes/com/test/world/service/PaymentGatewayService.class

BIN
target/classes/com/test/world/service/PaymentGatewayServiceImpl.class

5
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

6
target/classes/templates/index.html

@ -26,6 +26,10 @@ var amount="";
amount="[[${amount}]]" amount="[[${amount}]]"
console.log(amount); console.log(amount);
var merchantId="";
merchantId="[[${merchantId}]]"
console.log(merchantId);
$(document).ready(function() { $(document).ready(function() {
function handleResponse(res) { 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") { 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 "merchantLogoUrl": "https://upload.wikimedia.org/wikipedia/commons/a/a8/Chennai_Corporation_Emblem.png", //provided merchant logo will be displayed
"merchantName": "Greater Chennai Corporation", "merchantName": "Greater Chennai Corporation",
"merchantMsg": "Community Hall Booking", "merchantMsg": "Community Hall Booking",
"merchantId": "T955031",
"merchantId": merchantId,
"currency": "INR", "currency": "INR",
"consumerId": "c964634", "consumerId": "c964634",
"consumerMobileNo": "7845014181", "consumerMobileNo": "7845014181",

Loading…
Cancel
Save