Browse Source

refund-process

master
mohammedthaqi 3 years ago
parent
commit
f4a2879f89
  1. 1
      .classpath
  2. 12
      src/main/java/com/test/world/DTO/RefundRequest.java
  3. 89
      src/main/java/com/test/world/controller/PaymentController.java
  4. 20
      src/main/java/com/test/world/service/PaymentGatewayService.java
  5. 92
      src/main/java/com/test/world/service/PaymentGatewayServiceImpl.java
  6. 5
      src/main/java/com/test/world/service/WorldService.java
  7. 2
      target/classes/META-INF/maven/com.test/world/pom.properties
  8. BIN
      target/classes/com/test/world/DTO/RefundRequest.class
  9. BIN
      target/classes/com/test/world/controller/PaymentController.class
  10. BIN
      target/classes/com/test/world/service/PaymentGatewayService.class
  11. BIN
      target/classes/com/test/world/service/PaymentGatewayServiceImpl.class
  12. BIN
      target/classes/com/test/world/service/WorldService.class

1
.classpath

@ -37,5 +37,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="D:/WorldLine_payment_gateway/JSP/singleurl-dependency/singleurl-dependency/commons-codec-1.3.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

12
src/main/java/com/test/world/DTO/RefundRequest.java

@ -0,0 +1,12 @@
package com.test.world.DTO;
import java.util.HashMap;
public class RefundRequest {
private HashMap<String, String> merchant;
private HashMap<String,String> transaction;
}

89
src/main/java/com/test/world/controller/PaymentController.java

@ -4,6 +4,7 @@ import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@ -11,23 +12,28 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.test.world.service.PaymentGatewayService;
@Controller
@RequestMapping("/payment")
public class PaymentController {
@Autowired
PaymentGatewayService paymentService;
@GetMapping(value = {"","/","/index"})
public String startPayment(Model model) throws NoSuchAlgorithmException {
String txansactionId="1707115835222"; //create transaction Id unique from our side
String txansactionId="1707115835225"; //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 txnId= txansactionId+"|";
String totalAmt=amt+"|";
String accountNo="|";
String consumerId="c964634"+"|"; // Replace consumer ID in c964634 from our side
String consumerMobileNo="9879879870"+"|"; //Replace consumer Mobile no in 9879879870 from our side
String consumerEmailId="mohammedthaqi@bontonsoftwares.com"+"|"; //replace consumer email Id from our side
String consumerId="c964634|"; // Replace consumer ID in c964634 from our side
String consumerMobileNo="7845014181|"; //Replace consumer Mobile no in 9879879870 from our side
String consumerEmailId="mohammedthaqi@bontonsoftwares.com|"; //replace consumer email Id
String debitStartDate="|";
String debitEndDate="|";
String maxAmount="|";
@ -37,42 +43,49 @@ public class PaymentController {
String expMonth="|";
String expYear="|";
String cvvCode="|";
String salt="1025180466GPADTD"; //This is Test salt from worldLine
String salt="1025180466GPADTD";
String token=merchantId+txnId+totalAmt+accountNo+consumerId+consumerMobileNo+
consumerEmailId+debitStartDate+debitEndDate+maxAmount+amountType+
frequency+cardNumber+expMonth+expYear+cvvCode+salt;
//Generate token using SHA-512 or SHA-256
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(token.getBytes());
byte[] bytes = md.digest();
String encryptedtoken = paymentService.generateToken(token);
BigInteger bigInt = new BigInteger(1, bytes);
String encryptedtoken = bigInt.toString(16);
while (encryptedtoken.length() < 128) {
encryptedtoken = "0" + encryptedtoken;
};
System.out.println(token);
System.out.println("Encrypted Password: " + encryptedtoken);
model.addAttribute("txansactionId",txansactionId);
model.addAttribute("token",encryptedtoken);
model.addAttribute("amount",amt);
//check the Index page Configuration of WorldLine
return "index";
}
@PostMapping(value = "/response")
public String response(Model model, @RequestParam(required = false) String msg){
public String response(Model model, @RequestParam(required = false) String msg) throws NoSuchAlgorithmException{
String salt = "1025180466GPADTD";
//Here you will receive the response
System.out.println(msg);
String confirmToken="";
String status="success";
String s = new String(msg);
String c = new String();
String res[] =s.split("\\|");
for(int i=0;i<res.length;i++) {
System.out.println(res[i]);
if(i==res.length-1) {
c=c+salt;
confirmToken=res[i];
}
else if(res[i].isEmpty()) {
c=c+"|";
}
else if(res[i].equals("NA")) {
c=c+"NA|";
}else {
c=c+res[i]+"|";
}
}
System.out.println();
if(paymentService.generateToken(c).equals(confirmToken) && status.equals(res[1])){
System.out.println("payment confirmed");
//set logic here after payment confirmation..
}
model.addAttribute("msg",msg);
return "PaymentResponse";
@ -82,34 +95,10 @@ public class PaymentController {
@GetMapping(value="/refund")
public String refundAmount(Model model) {
System.out.println("Refund Api call.......working on it");
/*
* TransactionRequestBean objTransactionRequestBean=new
* TransactionRequestBean();
*
* objTransactionRequestBean.setStrRequestType("R");
* objTransactionRequestBean.setStrMerchantCode("T955031");
* objTransactionRequestBean.setMerchantTxnRefNumber("");
* objTransactionRequestBean.setStrAmount("10.00");
* objTransactionRequestBean.setStrCurrencyCode("INR");
* objTransactionRequestBean.setStrITC("email:myname@domain.com");
* objTransactionRequestBean.setStrReturnURL("/payment/response");
* objTransactionRequestBean.setStrShoppingCartDetails("");
* objTransactionRequestBean.setTxnDate("12-02-2024");
* objTransactionRequestBean.setStrBankCode("");
* objTransactionRequestBean.setWebServiceLocator(
* "https://www.tpsl-india.in/PaymentGateway/services/TransactionDetailsNew");
* objTransactionRequestBean.setStrTPSLTxnID("1707115835221");
* objTransactionRequestBean.setStrMobileNumber("7845014181");
* objTransactionRequestBean.setKey("1025180466GPADTD".getBytes());
* objTransactionRequestBean.setIv("3232693456UWOWHC".getBytes());
* objTransactionRequestBean.setStrCustomerName("Thaqi");
* objTransactionRequestBean.setStrEmail("mohammedthaqi@bontonsoftwares.com");
* objTransactionRequestBean.setStrTimeOut("1000"); String transactionToken =
* objTransactionRequestBean.getTransactionToken();
* System.out.println(transactionToken);
* model.addAttribute("msg",transactionToken);
*/
return "PaymentResponse";
}
}

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

@ -0,0 +1,20 @@
package com.test.world.service;
import java.io.UnsupportedEncodingException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
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 ToHexStrRefund(byte[] dataBuf);
public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception;
public byte[] FromHexStr (String hxStr);
}

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

@ -0,0 +1,92 @@
package com.test.world.service;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
import org.springframework.stereotype.Service;
@Service
public class PaymentGatewayServiceImpl implements PaymentGatewayService {
@Override
public String generateToken(String token) throws NoSuchAlgorithmException {
System.out.println("Token:-" + token);
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(token.getBytes());
byte[] bytes = md.digest();
BigInteger bigInt = new BigInteger(1, bytes);
String encryptedtoken = bigInt.toString(16);
while (encryptedtoken.length() < 128) {
encryptedtoken = "0" + encryptedtoken;
}
;
System.out.println("Encryption :- " + encryptedtoken);
return encryptedtoken;
}
//The process of encryption for refund API
@Override
public String encryptHxRefund(String text, byte[] iv, byte[] key) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(iv);
cipher.init(1, keySpec, ivSpec);
byte[] results = cipher.doFinal(text.getBytes("UTF-8"));
String hxencstr = ToHexStrRefund(results);
return hxencstr;
}
@Override
public String ToHexStrRefund(byte[] dataBuf) {
String hxstr = null;
Hex hx = new Hex();
hxstr = new String(hx.encode(dataBuf));
return hxstr;
}
//The process of decryption for refund API
@Override
public String decryptHxTRefund(String hxstrr, byte[] iv, byte[] key) throws Exception{
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(iv);
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
byte[] decbytes = FromHexStr(hxstrr);
byte[] results = cipher.doFinal(decbytes);
return new String(results, "UTF-8").trim();
}
@Override
public byte[] FromHexStr(String hxStr) {
byte[] charArray = hxStr.getBytes();
byte[] bufstr = null;
Hex hxx = new Hex();
try {
bufstr = hxx.decode(charArray);
} catch (Exception e) {
e.printStackTrace();
}
return bufstr;
}
}

5
src/main/java/com/test/world/service/WorldService.java

@ -1,5 +0,0 @@
package com.test.world.service;
public class WorldService {
}

2
target/classes/META-INF/maven/com.test/world/pom.properties

@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Fri Feb 16 17:19:32 IST 2024
#Fri Feb 16 21:56:31 IST 2024
m2e.projectLocation=D\:\\WorldLine_payment_gateway\\world
m2e.projectName=world
groupId=com.test

BIN
target/classes/com/test/world/DTO/RefundRequest.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

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

Loading…
Cancel
Save