working web-based entent code
This commit is contained in:
@@ -25,7 +25,7 @@ public class PaymentStartController {
|
|||||||
// Defensive: if bean not injected, return failure
|
// Defensive: if bean not injected, return failure
|
||||||
return ResponseEntity.badRequest().body(new ResponseModel("PaymentStartService not available", "FAILED", 400, null));
|
return ResponseEntity.badRequest().body(new ResponseModel("PaymentStartService not available", "FAILED", 400, null));
|
||||||
}
|
}
|
||||||
ResponseModel response = paymentStartService.startPayment(paymentStartUserRequest);
|
ResponseModel response = paymentStartService.startWebPayment(paymentStartUserRequest);
|
||||||
return ResponseEntity.ok(response);
|
return ResponseEntity.ok(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,6 @@ import com.billpaymentservice.bbps.dto.request.PaymentStartUserRequest;
|
|||||||
|
|
||||||
public interface PaymentStartService {
|
public interface PaymentStartService {
|
||||||
ResponseModel startPayment(PaymentStartUserRequest request);
|
ResponseModel startPayment(PaymentStartUserRequest request);
|
||||||
|
|
||||||
|
ResponseModel startWebPayment(PaymentStartUserRequest request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,46 @@ public class HttpService {
|
|||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
public HashMap<String, String> postFormRequest(String url, String formBody) {
|
||||||
|
HashMap<String, String> response = new HashMap<>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
|
log.info("🌐 Sending FORM POST to: {}", url);
|
||||||
|
log.info("📦 Payload: {}", formBody);
|
||||||
|
|
||||||
|
ResponseEntity<String> restResponse = restClient.post()
|
||||||
|
.uri(url)
|
||||||
|
.headers(h -> h.addAll(headers))
|
||||||
|
.body(formBody)
|
||||||
|
.retrieve()
|
||||||
|
.toEntity(String.class);
|
||||||
|
|
||||||
|
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
|
||||||
|
|
||||||
|
// HTML RESPONSE directly stored
|
||||||
|
response.put("data", restResponse.getBody());
|
||||||
|
|
||||||
|
log.info("✅ FORM POST Response Status: {}", restResponse.getStatusCode());
|
||||||
|
|
||||||
|
} catch (HttpClientErrorException e) {
|
||||||
|
log.error("❌ FORM POST Error: {} - {}", e.getStatusCode(), e.getMessage());
|
||||||
|
|
||||||
|
response.put("respCode", String.valueOf(e.getStatusCode().value()));
|
||||||
|
response.put("data", e.getResponseBodyAsString()); // still HTML or error string
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("❌ FORM POST Exception: {}", e.getMessage(), e);
|
||||||
|
|
||||||
|
response.put("respCode", "500");
|
||||||
|
response.put("data", "HttpService FORM Error: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(PaymentStartServiceImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PaymentStartServiceImpl.class);
|
||||||
|
|
||||||
private String uatPaymentUrl="https://uat.godemo.in/api/UATIntegration/paymentrequest/seamless";
|
private String uatPaymentUrl="https://uat.godemo.in/api/UATIntegration/uat/payin/paymentrequest";
|
||||||
|
|
||||||
private final PaymentStartRecordRepository paymentStartRecordRepository;
|
private final PaymentStartRecordRepository paymentStartRecordRepository;
|
||||||
private final HttpService httpService;
|
private final HttpService httpService;
|
||||||
@@ -290,4 +290,81 @@ public class PaymentStartServiceImpl implements PaymentStartService {
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResponseModel startWebPayment(PaymentStartUserRequest request) {
|
||||||
|
|
||||||
|
String requestId = request.getReqId();
|
||||||
|
String apiName = "StartPayment";
|
||||||
|
String txnId = helper.generateTxnId(15);
|
||||||
|
|
||||||
|
helper.validateMerchant(request.getMid());
|
||||||
|
|
||||||
|
// inbound log
|
||||||
|
String requestJson = helper.convertObjectToJson(request);
|
||||||
|
InboundTraceLog inboundLog =
|
||||||
|
helper.createInboundLog(requestId, txnId, apiName, request.getMid(),
|
||||||
|
BBPSConstant.HTTP_POST, requestJson);
|
||||||
|
|
||||||
|
// Prepare request payload
|
||||||
|
PaymentDetailSentRequest sent = createPaymentSentRequest(request);
|
||||||
|
String orderNo = "ORD" + helper.generateTxnId(12);
|
||||||
|
sent.setOrderNo(orderNo);
|
||||||
|
|
||||||
|
String plaintext = helper.convertObjectToJson(sent);
|
||||||
|
String encKey = BBPSConstant.enckey;
|
||||||
|
sent.setEnckey(encKey);
|
||||||
|
|
||||||
|
String encrypted = encryptionUtil.encryptMData(plaintext, encKey);
|
||||||
|
|
||||||
|
// ----------- BUILD x-www-form-urlencoded PAYLOAD -----------
|
||||||
|
String formPayload =
|
||||||
|
"mid=" + URLEncoder.encode(BBPSConstant.mid, StandardCharsets.UTF_8) +
|
||||||
|
"&payload=" + URLEncoder.encode(encrypted, StandardCharsets.UTF_8);
|
||||||
|
LOGGER.info("Form Payload: {}", formPayload);
|
||||||
|
OutboundTraceLog outboundLog =
|
||||||
|
helper.createOutboundLog(txnId, requestId, apiName, uatPaymentUrl,
|
||||||
|
BBPSConstant.HTTP_POST, formPayload);
|
||||||
|
|
||||||
|
// ----------- CALL API (FORM URL-ENCODED) -----------
|
||||||
|
Map<String, String> responseMap =
|
||||||
|
httpService.postFormRequest(uatPaymentUrl, formPayload);
|
||||||
|
|
||||||
|
LOGGER.info("Payment Start Response: {}", responseMap);
|
||||||
|
|
||||||
|
int httpCode = Integer.parseInt(responseMap.getOrDefault("respCode", "500"));
|
||||||
|
String respBody = responseMap.getOrDefault("data", "");
|
||||||
|
|
||||||
|
helper.updateOutboundLogResponse(outboundLog, respBody);
|
||||||
|
|
||||||
|
// ---- HTTP FAILURE ----
|
||||||
|
if (httpCode != 200) {
|
||||||
|
helper.updateInboundLogFailure(inboundLog, respBody, String.valueOf(httpCode));
|
||||||
|
throw new CustomException("Upstream HTTP Error", "FAILED", httpCode, respBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- EMPTY RESPONSE ----
|
||||||
|
if (respBody.isEmpty()) {
|
||||||
|
helper.updateInboundLogFailure(inboundLog, "Empty response from PG", "500");
|
||||||
|
throw new CustomException("Empty response from PG", "FAILED", 500, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ❗❗ PG RETURNS HTML → NO JSON PARSING REQUIRED
|
||||||
|
helper.updateInboundLogSuccess(inboundLog, respBody, "200");
|
||||||
|
|
||||||
|
// Save record with HTML (optional)
|
||||||
|
// bbpsMapperHelper.savePaymentStartHtmlRecord(request, respBody, txnId, orderNo);
|
||||||
|
|
||||||
|
// Return HTML directly in API response
|
||||||
|
Map<String, String> result = new HashMap<>();
|
||||||
|
result.put("html", respBody);
|
||||||
|
|
||||||
|
return ResponseModel.builder()
|
||||||
|
.status("SUCCESS")
|
||||||
|
.statusCode(200)
|
||||||
|
.message("HTML Response Received")
|
||||||
|
.data(result)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,9 +20,9 @@ swagger.server.description=Local Development Server
|
|||||||
# DataSource
|
# DataSource
|
||||||
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS
|
spring.datasource.url=jdbc:postgresql://localhost:5432/BBPS
|
||||||
spring.datasource.username=postgres
|
spring.datasource.username=postgres
|
||||||
spring.datasource.password=UAT@DB_2025
|
#spring.datasource.password=UAT@DB_2025
|
||||||
|
|
||||||
#spring.datasource.password=himanshu@123
|
spring.datasource.password=himanshu@123
|
||||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||||
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
|
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user