Commit 89e269bf authored by Mahesh Maney R's avatar Mahesh Maney R
Browse files

feature for payment gateway response handler <ManeyMR>.

Showing with 84 additions and 57 deletions
+84 -57
......@@ -71,12 +71,8 @@ public class UserController {
return userHandler.login(body);
}
@GetMapping(value = "/payment")
public ResponseEntity<?> paymentRedirect(Payment payment){
//Print params here
HttpHeaders headers = new HttpHeaders();
String redirectUrl = paymentService.makePayment(payment);
headers.setLocation(URI.create(redirectUrl));
return new ResponseEntity<String>(null,headers,HttpStatus.PERMANENT_REDIRECT);
@PostMapping(value = "/payment")
public String paymentRedirect(Payment payment) throws URISyntaxException, IOException {
return userHandler.paymentRedirect(payment);
}
}
......@@ -2,6 +2,7 @@ package com.tarento.upsmf.userManagement.handler;
import com.fasterxml.jackson.databind.JsonNode;
import com.tarento.upsmf.userManagement.model.KeyCloakUserDTO;
import com.tarento.upsmf.userManagement.model.Payment;
import com.tarento.upsmf.userManagement.services.UserService;
import com.tarento.upsmf.userManagement.utility.*;
import org.slf4j.Logger;
......@@ -120,4 +121,9 @@ public class UserHandler {
private String getorDefault(final JsonNode request, final String key, final String defaultValue){
return request.get(key) != null ? request.get(key).asText() : defaultValue;
}
public String paymentRedirect(Payment payment) throws URISyntaxException, IOException {
logger.info("payload from paymentRedirect {}",payment);
return userService.paymentRedirect(payment);
}
}
package com.tarento.upsmf.userManagement.services;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.tarento.upsmf.userManagement.model.Payment;
import com.tarento.upsmf.userManagement.model.ResponseDto;
import org.springframework.stereotype.Service;
public interface PaymentService {
public String makePayment(Payment payment);
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
/*@Autowired
PaymentRepository paymentRepository;
public ResponseDto makePayment(Payment payment){
ResponseDto response = new ResponseDto("api.payment.make");
// Calculate noOfExams based on the number of selected options
int noOfExams = payment.getExams().size();
// Calculate the fee amount based on noOfExams and exam fee amount (replace with actual fee calculation)
int examFeeAmount = 100; // Example exam fee amount
int feeAmount = calculateFee(noOfExams, examFeeAmount);
// Set the calculated values in the FeeManage object
payment.setNoOfExams(noOfExams);
payment.setFeeAmount(feeAmount);
// Save the FeeManage object
try {
Payment result = paymentRepository.save(payment);
response.put("message", "Success");
response.put("response", "Created.");
response.setResponseCode(HttpStatus.OK);
} catch (Exception e) {
response.put("message", "Error saving fee details");
response.put("response", "Failed to create a message");
response.setResponseCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
return response;
}
public Integer calculateFee(Integer noOfExams, Integer examFeeAmount) {
return noOfExams * examFeeAmount;
}*/
@Service
public interface PaymentService {
public String makePayment(Payment payment) throws URISyntaxException, IOException;
}
\ No newline at end of file
package com.tarento.upsmf.userManagement.services;
import com.fasterxml.jackson.databind.JsonNode;
import com.tarento.upsmf.userManagement.model.Payment;
import com.tarento.upsmf.userManagement.utility.KeycloakTokenRetriever;
import com.tarento.upsmf.userManagement.utility.SunbirdRCKeycloakTokenRetriever;
import org.apache.http.client.HttpClient;
......@@ -35,6 +36,9 @@ public class UserService {
@Autowired
private SunbirdRCKeycloakTokenRetriever sunbirdRCKeycloakTokenRetriever;
@Autowired
private PaymentService paymentService;
private static Environment environment;
private String BASE_URL;
private String KEYCLOAK_BASEURL;
......@@ -174,4 +178,9 @@ public class UserService {
ResponseEntity<String> result = restTemplate.postForEntity(uri,httpEntity,String.class);
return result;
}
public String paymentRedirect(Payment payment) throws URISyntaxException, IOException {
return paymentService.makePayment(payment);
}
}
package com.tarento.upsmf.userManagement.services.impl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.tarento.upsmf.userManagement.model.Payment;
import com.tarento.upsmf.userManagement.model.ResponseDto;
import com.tarento.upsmf.userManagement.repository.PaymentRepository;
import com.tarento.upsmf.userManagement.services.PaymentService;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
@Service
@PropertySource({ "classpath:application.properties" })
public class PaymentServiceImpl implements PaymentService {
private static final Logger logger = LoggerFactory.getLogger(PaymentServiceImpl.class);
@Autowired
private Environment env;
private static Environment environment;
@Autowired
PaymentRepository paymentRepository;
// @Override
public String makePayment(Payment payment) {
//read params
System.out.println(payment);
//check status
//if valid
//save transaction details with success
//redirect to success page with success params - transaction id, amount,
//return "https://applicant.upsmfac.org?resp=success&transactionId{}=&amount={}";
//if invalid
// save transactions details with error
//redirect to error page with error params - transaction id, error code , amount
return "https://applicant.upsmfac.org?resp=fail&transactionId{}=&amount={}";
private String PAYMENT_GATEWAY_ENDPOINT;
private ObjectMapper mapper = new ObjectMapper();
@PostConstruct
public void init(){
environment = env;
PAYMENT_GATEWAY_ENDPOINT = getPropertyValue("paymentGatewayEndPoint");
}
public static String getPropertyValue(String property){
return environment.getProperty(property);
}
@Override
public String makePayment(Payment payment) throws URISyntaxException, IOException {
logger.info("payment details...{} ", payment);
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(PAYMENT_GATEWAY_ENDPOINT);
String strPaymentURL = mapper.writeValueAsString(payment);
StringEntity entity = new StringEntity(strPaymentURL);
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost);
logger.info("Response from httpClient call : {}", response);
String responseBody = EntityUtils.toString(response.getEntity());
logger.info("Response from keycloak Rest API call : {}", responseBody);
return responseBody;
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ sunbirdRC.keycloak.adminToken.userName =admin
sunbirdRC.keycloak.adminToken.clientID =admin-api
sunbirdRC.keycloak.adminToken.clientSecret =QF5op6Hb3Y9mY1rU0IycdjmD7j3Bvzkh
sunbirdRC.keycloak.adminToken.password =admin
paymentGatewayEndPoint =https://applicant.upsmfac.org?resp=fail&transactionId
spring.datasource.url=jdbc:postgresql://localhost:5432/frac_tool
spring.datasource.username=postgres
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment