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