added bank wise url for all the banks

This commit is contained in:
2026-06-17 17:12:29 +05:30
parent 8a3c41b3db
commit 689be386fb
5 changed files with 30 additions and 19 deletions
@@ -4,6 +4,7 @@ package com.main.ipks.dto.account;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
@@ -18,6 +19,9 @@ public class IpksAccountRequest {
@JsonAlias({"cif","custNum","cust_num"})
private String cif;
@JsonIgnore
private String bankId;
// getters/setters
@@ -25,6 +29,8 @@ public class IpksAccountRequest {
public void setCif(String cif) { this.cif = cif; }
public String getBankId() { return bankId; }
public void setBankId(String bankId) { this.bankId = bankId; }
}
@@ -1,6 +1,7 @@
package com.main.ipks.dto.cif;
import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotBlank;
@@ -133,6 +134,8 @@ public class IpksCustomerRequest {
@JsonAlias({"relative_name"})
private String relativeName;
@JsonIgnore
private String bankId;
@@ -290,6 +293,8 @@ public class IpksCustomerRequest {
public String getRelativeName() { return relativeName; }
public void setRelativeName(String relativeName) { this.relativeName = relativeName; }
public String getBankId() { return bankId; }
public void setBankId(String bankId) { this.bankId = bankId; }
}
@@ -46,7 +46,7 @@ public class CbsIntegrationService {
public CifApiResponse createCustomer(IpksCustomerRequest in) {
try {
// Token + headers (TokenFetchException handled globally -> 503)
String token = tokenService.getToken();
String token = tokenService.getToken(in.getBankId());
HttpHeaders headers = buildHeaders(token);
// Map inbound to C-EDGE payload (null-safe defaults)
@@ -57,13 +57,13 @@ public class CbsIntegrationService {
ResponseEntity<String> response;
try {
response = restTemplate.exchange(cifUrl, HttpMethod.POST, entity, String.class);
response = restTemplate.exchange(cifUrl + "/" + in.getBankId(), HttpMethod.POST, entity, String.class);
} catch (HttpStatusCodeException ex) {
if (ex.getStatusCode() == HttpStatus.UNAUTHORIZED || ex.getStatusCode() == HttpStatus.FORBIDDEN) {
log.warn("[C-EDGE] CIF call unauthorized. Refreshing token and retrying once...");
HttpEntity<CifCreateRequest> retryEntity =
new HttpEntity<>(req, buildHeaders(tokenService.refreshToken()));
response = restTemplate.exchange(cifUrl, HttpMethod.POST, retryEntity, String.class);
new HttpEntity<>(req, buildHeaders(tokenService.refreshToken(in.getBankId())));
response = restTemplate.exchange(cifUrl + "/" + in.getBankId(), HttpMethod.POST, retryEntity, String.class);
} else {
// If upstream provided a JSON body, propagate it to client (as 502)
String raw = ex.getResponseBodyAsString();
@@ -113,7 +113,7 @@ public class CbsIntegrationService {
// ---------------- Account Creation (API-1 + API-2) ----------------
public AccountCreationResponse createAccount(IpksAccountRequest reqDto) {
try {
String token = tokenService.getToken();
String token = tokenService.getToken(reqDto.getBankId());
HttpHeaders headers = buildHeaders(token);
// --- API-1 ---
@@ -126,13 +126,13 @@ public class CbsIntegrationService {
ResponseEntity<String> api1Raw;
try {
api1Raw = restTemplate.exchange(accountUrl, HttpMethod.POST, api1Entity, String.class);
api1Raw = restTemplate.exchange(accountUrl + "/" + reqDto.getBankId(), HttpMethod.POST, api1Entity, String.class);
} catch (HttpStatusCodeException ex) {
if (ex.getStatusCode() == HttpStatus.UNAUTHORIZED || ex.getStatusCode() == HttpStatus.FORBIDDEN) {
log.warn("[C-EDGE] API-1 unauthorized. Refresh + retry once");
HttpEntity<CreateAccountRequest> retryEntity =
new HttpEntity<>(api1Req, buildHeaders(tokenService.refreshToken()));
api1Raw = restTemplate.exchange(accountUrl, HttpMethod.POST, retryEntity, String.class);
new HttpEntity<>(api1Req, buildHeaders(tokenService.refreshToken(reqDto.getBankId())));
api1Raw = restTemplate.exchange(accountUrl + "/" + reqDto.getBankId(), HttpMethod.POST, retryEntity, String.class);
} else {
String raw = ex.getResponseBodyAsString();
if (raw != null && !raw.isBlank() && looksJson(raw)) {
@@ -182,13 +182,13 @@ public class CbsIntegrationService {
HttpEntity<CreateDepositAccountOkRequest> api2Entity = new HttpEntity<>(api2Req, headers);
ResponseEntity<String> api2Raw;
try {
api2Raw = restTemplate.exchange(accountOkUrl, HttpMethod.POST, api2Entity, String.class);
api2Raw = restTemplate.exchange(accountOkUrl + "/" + reqDto.getBankId(), HttpMethod.POST, api2Entity, String.class);
} catch (HttpStatusCodeException ex) {
if (ex.getStatusCode() == HttpStatus.UNAUTHORIZED || ex.getStatusCode() == HttpStatus.FORBIDDEN) {
log.warn("[C-EDGE] API-2 unauthorized. Refresh + retry once");
HttpEntity<CreateDepositAccountOkRequest> retryEntity =
new HttpEntity<>(api2Req, buildHeaders(tokenService.refreshToken()));
api2Raw = restTemplate.exchange(accountOkUrl, HttpMethod.POST, retryEntity, String.class);
new HttpEntity<>(api2Req, buildHeaders(tokenService.refreshToken(reqDto.getBankId())));
api2Raw = restTemplate.exchange(accountOkUrl + "/" + reqDto.getBankId(), HttpMethod.POST, retryEntity, String.class);
} else {
String raw = ex.getResponseBodyAsString();
if (raw != null && !raw.isBlank() && looksJson(raw)) {
@@ -30,7 +30,7 @@ public class TokenService {
this.restTemplate = restTemplate;
}
public String getToken() {
public String getToken(String bankId) {
long now = System.currentTimeMillis();
if (cachedToken != null && now < tokenExpiryTimeMillis) {
return cachedToken;
@@ -48,7 +48,7 @@ public class TokenService {
log.info("Fetching new C-EDGE token (attempt {}/2)", attempt);
ResponseEntity<TokenResponse> resp =
restTemplate.getForEntity(tokenUrl, TokenResponse.class);
restTemplate.getForEntity(tokenUrl + "/" + bankId, TokenResponse.class);
TokenResponse body = resp.getBody();
@@ -118,11 +118,11 @@ public class TokenService {
* Force refresh token: clear cache and fetch again (with 2 attempts total).
* Used when C-EDGE returns 401/403 unauthorized.
*/
public String refreshToken() {
public String refreshToken(String bankId) {
synchronized (tokenLock) {
cachedToken = null;
tokenExpiryTimeMillis = 0L;
}
return getToken();
return getToken(bankId);
}
}
+4 -4
View File
@@ -7,16 +7,16 @@ logging.level.com.main.ipks.service=DEBUG
# TOKEN
cedge.token.url=https://142.79.251.107:443/BANCEDGEAPI/api/getToken/HASAN
cedge.token.url=https://142.79.251.107:443/BANCEDGEAPI/api/getToken
# Api for CIF-Creation
cedge.cif.url=https://142.79.251.107:443/BANCEDGEAPI/api/cifCreation/HASAN
cedge.cif.url=https://142.79.251.107:443/BANCEDGEAPI/api/cifCreation
# Api for account creation
# API1
cedge.account.url=https://142.79.251.107:443/BANCEDGEAPI/api/depositsCreateDepositAccount/HASAN
cedge.account.url=https://142.79.251.107:443/BANCEDGEAPI/api/depositsCreateDepositAccount
# API2
cedge.accountOk.url=https://142.79.251.107:443/BANCEDGEAPI/api/createDepositAccountOk/HASAN
cedge.accountOk.url=https://142.79.251.107:443/BANCEDGEAPI/api/createDepositAccountOk