diff --git a/src/main/java/com/main/ipks/dto/account/IpksAccountRequest.java b/src/main/java/com/main/ipks/dto/account/IpksAccountRequest.java index 3ae9899..638f414 100644 --- a/src/main/java/com/main/ipks/dto/account/IpksAccountRequest.java +++ b/src/main/java/com/main/ipks/dto/account/IpksAccountRequest.java @@ -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; } } diff --git a/src/main/java/com/main/ipks/dto/cif/IpksCustomerRequest.java b/src/main/java/com/main/ipks/dto/cif/IpksCustomerRequest.java index 06d10ce..7db98e8 100644 --- a/src/main/java/com/main/ipks/dto/cif/IpksCustomerRequest.java +++ b/src/main/java/com/main/ipks/dto/cif/IpksCustomerRequest.java @@ -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; } } diff --git a/src/main/java/com/main/ipks/service/CbsIntegrationService.java b/src/main/java/com/main/ipks/service/CbsIntegrationService.java index e6614a7..92a83ed 100644 --- a/src/main/java/com/main/ipks/service/CbsIntegrationService.java +++ b/src/main/java/com/main/ipks/service/CbsIntegrationService.java @@ -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 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 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 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 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 api2Entity = new HttpEntity<>(api2Req, headers); ResponseEntity 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 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)) { diff --git a/src/main/java/com/main/ipks/service/TokenService.java b/src/main/java/com/main/ipks/service/TokenService.java index f8b1eda..945b3dc 100644 --- a/src/main/java/com/main/ipks/service/TokenService.java +++ b/src/main/java/com/main/ipks/service/TokenService.java @@ -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 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); } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 782e408..332bd81 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 \ No newline at end of file +cedge.accountOk.url=https://142.79.251.107:443/BANCEDGEAPI/api/createDepositAccountOk \ No newline at end of file