Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
userManagement
Commits
89e269bf
Commit
89e269bf
authored
1 year ago
by
Mahesh Maney R
Browse files
Options
Download
Patches
Plain Diff
feature for payment gateway response handler <ManeyMR>.
parent
aea96e84
main
UAT_quick_fix_keycloak
UPHRH_8164_ErrorHandling
dev
dev_stable
devops-patch
feature_update_fee
payment-webhook
rahu_error_message_fix
uat
1 merge request
!4
Payment webhook
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
src/main/java/com/tarento/upsmf/userManagement/controller/UserController.java
+3
-7
...rento/upsmf/userManagement/controller/UserController.java
src/main/java/com/tarento/upsmf/userManagement/handler/UserHandler.java
+6
-0
...com/tarento/upsmf/userManagement/handler/UserHandler.java
src/main/java/com/tarento/upsmf/userManagement/services/PaymentService.java
+8
-33
...tarento/upsmf/userManagement/services/PaymentService.java
src/main/java/com/tarento/upsmf/userManagement/services/UserService.java
+9
-0
...om/tarento/upsmf/userManagement/services/UserService.java
src/main/java/com/tarento/upsmf/userManagement/services/impl/PaymentServiceImpl.java
+57
-17
...psmf/userManagement/services/impl/PaymentServiceImpl.java
src/main/resources/application.properties
+1
-0
src/main/resources/application.properties
with
84 additions
and
57 deletions
+84
-57
src/main/java/com/tarento/upsmf/userManagement/controller/UserController.java
+
3
−
7
View file @
89e269bf
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/handler/UserHandler.java
+
6
−
0
View file @
89e269bf
...
...
@@ -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
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/services/PaymentService.java
+
8
−
33
View file @
89e269bf
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
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/services/UserService.java
+
9
−
0
View file @
89e269bf
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
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/com/tarento/upsmf/userManagement/services/impl/PaymentServiceImpl.java
+
57
−
17
View file @
89e269bf
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
This diff is collapsed.
Click to expand it.
src/main/resources/application.properties
+
1
−
0
View file @
89e269bf
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets