├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── javatechie │ │ └── spring │ │ └── paytm │ │ └── api │ │ ├── PaymentController.java │ │ ├── PaytmDetails.java │ │ └── SpringPaymentPaytmApplication.java └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ ├── application.properties │ ├── application.yml │ ├── static │ └── style.css │ └── templates │ ├── home.html │ └── report.html └── test └── java └── com └── javatechie └── spring └── paytm └── api └── SpringPaymentPaytmApplicationTests.java /README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-paytm-integration 2 | How to do payment integration using paytm with Spring Boot 3 | 4 | # Testing Integration URL 5 | https://developer.paytm.com/docs/testing-integration/ 6 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.1.4.RELEASE 10 | 11 | 12 | com.javatechie 13 | spring-payment-paytm 14 | 0.0.1-SNAPSHOT 15 | spring-payment-paytm 16 | payment integration with paytm 17 | 18 | 19 | 1.8 20 | 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-web 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-thymeleaf 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-devtools 34 | runtime 35 | true 36 | 37 | 38 | org.projectlombok 39 | lombok 40 | true 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-test 45 | test 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-configuration-processor 50 | true 51 | 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/spring/paytm/api/PaymentController.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.paytm.api; 2 | 3 | import java.util.Map; 4 | import java.util.TreeMap; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.core.env.Environment; 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.ui.Model; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestParam; 15 | import org.springframework.web.servlet.ModelAndView; 16 | 17 | import com.paytm.pg.merchant.CheckSumServiceHelper; 18 | 19 | @Controller 20 | public class PaymentController { 21 | 22 | @Autowired 23 | private PaytmDetails paytmDetails; 24 | @Autowired 25 | private Environment env; 26 | 27 | @GetMapping("/") 28 | public String home() { 29 | return "home"; 30 | } 31 | 32 | @PostMapping(value = "/pgredirect") 33 | public ModelAndView getRedirect(@RequestParam(name = "CUST_ID") String customerId, 34 | @RequestParam(name = "TXN_AMOUNT") String transactionAmount, 35 | @RequestParam(name = "ORDER_ID") String orderId) throws Exception { 36 | 37 | ModelAndView modelAndView = new ModelAndView("redirect:" + paytmDetails.getPaytmUrl()); 38 | TreeMap parameters = new TreeMap<>(); 39 | paytmDetails.getDetails().forEach((k, v) -> parameters.put(k, v)); 40 | parameters.put("MOBILE_NO", env.getProperty("paytm.mobile")); 41 | parameters.put("EMAIL", env.getProperty("paytm.email")); 42 | parameters.put("ORDER_ID", orderId); 43 | parameters.put("TXN_AMOUNT", transactionAmount); 44 | parameters.put("CUST_ID", customerId); 45 | String checkSum = getCheckSum(parameters); 46 | parameters.put("CHECKSUMHASH", checkSum); 47 | modelAndView.addAllObjects(parameters); 48 | return modelAndView; 49 | } 50 | 51 | 52 | @PostMapping(value = "/pgresponse") 53 | public String getResponseRedirect(HttpServletRequest request, Model model) { 54 | 55 | Map mapData = request.getParameterMap(); 56 | TreeMap parameters = new TreeMap(); 57 | mapData.forEach((key, val) -> parameters.put(key, val[0])); 58 | String paytmChecksum = ""; 59 | if (mapData.containsKey("CHECKSUMHASH")) { 60 | paytmChecksum = mapData.get("CHECKSUMHASH")[0]; 61 | } 62 | String result; 63 | 64 | boolean isValideChecksum = false; 65 | System.out.println("RESULT : "+parameters.toString()); 66 | try { 67 | isValideChecksum = validateCheckSum(parameters, paytmChecksum); 68 | if (isValideChecksum && parameters.containsKey("RESPCODE")) { 69 | if (parameters.get("RESPCODE").equals("01")) { 70 | result = "Payment Successful"; 71 | } else { 72 | result = "Payment Failed"; 73 | } 74 | } else { 75 | result = "Checksum mismatched"; 76 | } 77 | } catch (Exception e) { 78 | result = e.toString(); 79 | } 80 | model.addAttribute("result",result); 81 | parameters.remove("CHECKSUMHASH"); 82 | model.addAttribute("parameters",parameters); 83 | return "report"; 84 | } 85 | 86 | private boolean validateCheckSum(TreeMap parameters, String paytmChecksum) throws Exception { 87 | return CheckSumServiceHelper.getCheckSumServiceHelper().verifycheckSum(paytmDetails.getMerchantKey(), 88 | parameters, paytmChecksum); 89 | } 90 | 91 | 92 | private String getCheckSum(TreeMap parameters) throws Exception { 93 | return CheckSumServiceHelper.getCheckSumServiceHelper().genrateCheckSum(paytmDetails.getMerchantKey(), parameters); 94 | } 95 | 96 | 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/spring/paytm/api/PaytmDetails.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.paytm.api; 2 | 3 | import java.util.Map; 4 | 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.stereotype.Component; 7 | 8 | import lombok.AllArgsConstructor; 9 | import lombok.Data; 10 | import lombok.NoArgsConstructor; 11 | import lombok.ToString; 12 | 13 | @Data 14 | @AllArgsConstructor 15 | @NoArgsConstructor 16 | @ToString 17 | @Component 18 | @ConfigurationProperties("paytm.payment.sandbox") 19 | 20 | public class PaytmDetails { 21 | 22 | private String merchantId; 23 | 24 | private String merchantKey; 25 | 26 | private String channelId; 27 | 28 | private String website; 29 | 30 | private String industryTypeId; 31 | 32 | private String paytmUrl; 33 | 34 | private Map details; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/javatechie/spring/paytm/api/SpringPaymentPaytmApplication.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.paytm.api; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringPaymentPaytmApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringPaymentPaytmApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | {"properties": [ 2 | { 3 | "name": "paytm.payment.sandbox.merchant-id", 4 | "type": "java.lang.String", 5 | "description": "A description for 'paytm.payment.sandbox.merchant-id'" 6 | }, 7 | { 8 | "name": "paytm.payment.sandbox.callback-url", 9 | "type": "java.lang.String", 10 | "description": "A description for 'paytm.payment.sandbox.callback-url'" 11 | } 12 | ]} -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=9090 2 | paytm.email=Enter your Email id 3 | paytm.mobile=Enter your mobile number 4 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | paytm.payment: 2 | sandbox: 3 | merchantId: {generate your own merchantId} 4 | merchantKey: {generate your merchantKey} 5 | channelId: WEB 6 | website: WEBSTAGING 7 | industryTypeId: Retail 8 | paytmUrl: https://securegw-stage.paytm.in/order/process 9 | callbackUrl: http://localhost:9090/pgresponse 10 | details: 11 | MID: ${paytm.payment.sandbox.merchantid} 12 | CHANNEL_ID: ${paytm.payment.sandbox.channelid} 13 | INDUSTRY_TYPE_ID: ${paytm.payment.sandbox.industrytypeid} 14 | WEBSITE: ${paytm.payment.sandbox.website} 15 | CALLBACK_URL: ${paytm.payment.sandbox.callbackUrl} 16 | -------------------------------------------------------------------------------- /src/main/resources/static/style.css: -------------------------------------------------------------------------------- 1 | .register{ 2 | background: -webkit-linear-gradient(left, #3931af, #00c6ff); 3 | margin-top: 3%; 4 | padding: 3%; 5 | } 6 | .register-left{ 7 | text-align: center; 8 | color: #fff; 9 | margin-top: 4%; 10 | } 11 | .register-left input{ 12 | border: none; 13 | border-radius: 1.5rem; 14 | padding: 2%; 15 | width: 60%; 16 | background: #f8f9fa; 17 | font-weight: bold; 18 | color: #383d41; 19 | margin-top: 30%; 20 | margin-bottom: 3%; 21 | cursor: pointer; 22 | } 23 | .register-right{ 24 | background: #f8f9fa; 25 | border-top-left-radius: 10% 50%; 26 | border-bottom-left-radius: 10% 50%; 27 | } 28 | .register-left img{ 29 | margin-top: 15%; 30 | margin-bottom: 5%; 31 | width: 25%; 32 | -webkit-animation: mover 2s infinite alternate; 33 | animation: mover 1s infinite alternate; 34 | } 35 | @-webkit-keyframes mover { 36 | 0% { transform: translateY(0); } 37 | 100% { transform: translateY(-20px); } 38 | } 39 | @keyframes mover { 40 | 0% { transform: translateY(0); } 41 | 100% { transform: translateY(-20px); } 42 | } 43 | .register-left p{ 44 | font-weight: lighter; 45 | padding: 12%; 46 | margin-top: -9%; 47 | } 48 | .register .register-form{ 49 | padding: 10%; 50 | margin-top: 10%; 51 | } 52 | .btnRegister { 53 | border: none; 54 | border-radius: 1.5rem; 55 | background: #0062cc; 56 | color: #fff; 57 | font-weight: 600; 58 | width: 55%; 59 | cursor: pointer; 60 | padding: 1%; 61 | font-size: xx-large; 62 | /* margin-top: 3px;*/ 63 | margin:auto; 64 | display:block 65 | } 66 | .register .nav-tabs{ 67 | margin-top: 3%; 68 | border: none; 69 | background: #0062cc; 70 | border-radius: 1.5rem; 71 | width: 28%; 72 | float: right; 73 | } 74 | .register .nav-tabs .nav-link{ 75 | padding: 2%; 76 | height: 34px; 77 | font-weight: 600; 78 | color: #fff; 79 | border-top-right-radius: 1.5rem; 80 | border-bottom-right-radius: 1.5rem; 81 | } 82 | .register .nav-tabs .nav-link:hover{ 83 | border: none; 84 | } 85 | .register .nav-tabs .nav-link.active{ 86 | width: 100px; 87 | color: #0062cc; 88 | border: 2px solid #0062cc; 89 | border-top-left-radius: 1.5rem; 90 | border-bottom-left-radius: 1.5rem; 91 | } 92 | 93 | .register-heading { 94 | /* text-align: center; */ 95 | /* margin-top: 8%; */ 96 | margin-bottom: -15%; 97 | color: #495057; 98 | float: left; 99 | /* margin-left: 0px; */ 100 | padding-left: 75px; 101 | } -------------------------------------------------------------------------------- /src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Welcome 18 | You are 30 seconds away from earning your own money! 19 | 20 | 21 | 22 | 23 | Welcome to Paytm Payment 24 | 25 | 26 | 27 | 29 | 30 | 31 | 33 | 34 | 35 | 37 | 38 | 39 | 41 | 42 | 43 | 45 | 46 | 47 | Pay with Paytm 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /src/main/resources/templates/report.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Payment Report 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Receipt #: 34522677W 23 | 24 | 25 | 26 | 27 | 28 | Receipt 29 | 30 | 31 | 32 | 33 | 34 | Components 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/test/java/com/javatechie/spring/paytm/api/SpringPaymentPaytmApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.spring.paytm.api; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class SpringPaymentPaytmApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------
You are 30 seconds away from earning your own money!
22 | Receipt #: 34522677W 23 |