Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/dev-otc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}

- name: Fetch partners config
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}
# cache: maven
- name: Build
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/main-otc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
uses: actions/checkout@v2

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}

- name: Fetch partners config
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}
# cache: maven
- name: Build
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}
# cache: maven
- name: Build
run: mvn -B clean install -Potc
run: mvn -B clean install -Potc
- name: Run Tests
run: mvn -B -Dskip.unit.tests=false surefire:test
run: mvn -B -Dskip.unit.tests=false surefire:test

- name: Build Docker images
env:
TAG: pr
run: docker compose -f docker-compose.build.yml build
run: docker compose -f docker-compose.build.yml build
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-package: jdk
distribution: temurin
java-version: ${{ matrix.java }}
# cache: maven
- name: Build
Expand Down
3 changes: 2 additions & 1 deletion common/src/main/kotlin/co/nilin/opex/common/OpexError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ enum class OpexError(val code: Int, val message: String?, val status: HttpStatus
CardIbanInfoInquiryError(13045, "Card-IBAN info inquiry failed", HttpStatus.INTERNAL_SERVER_ERROR),
BankAccountAlreadyExist(13046, "Bank account already exist", HttpStatus.BAD_REQUEST),
BankAccountNotFound(13047, "Bank account not found", HttpStatus.NOT_FOUND),
AddressBookNotFound(13048, "Address book not found", HttpStatus.NOT_FOUND)
AddressBookNotFound(13048, "Address book not found", HttpStatus.NOT_FOUND),
InvalidProfileData(13049, "Invalid profile data", HttpStatus.BAD_REQUEST)
;

override fun code() = this.code
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ services:
- ADMIN_APPROVAL_PROFILE_COMPLETION_REQUEST=${ADMIN_APPROVAL_PROFILE_COMPLETION_REQUEST}
- ADMIN_APPROVAL_BANK_ACCOUNT=${ADMIN_APPROVAL_BANK_ACCOUNT}
- TOKEN_ISSUER_URL=${KC_ISSUER_URL}
- MOBILE_IDENTITY_INQUIRY=${MOBILE_IDENTITY_INQUIRY}
- PERSONAL_IDENTITY_INQUIRY=${PERSONAL_IDENTITY_INQUIRY}
depends_on:
- kafka-1
- kafka-2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import co.nilin.opex.profile.core.data.profile.*
import co.nilin.opex.profile.core.spi.*
import co.nilin.opex.profile.core.utils.handleComparativeError
import co.nilin.opex.profile.core.utils.handleShahkarError
import co.nilin.opex.utility.error.data.OpexException
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.reactive.awaitFirst
import org.slf4j.LoggerFactory
Expand All @@ -29,10 +30,10 @@ class ProfileManagement(
private val otpProxy: OtpProxy,
private val inquiryProxy: InquiryProxy,

@Value("\${app.inquiry.mobile-indentiy}")
@Value("\${app.inquiry.mobile-identity}")
private var mobileIdentityEnabled: Boolean,

@Value("\${app.inquiry.personal-indentiy}")
@Value("\${app.inquiry.personal-identity}")
private var personalIdentityEnabled: Boolean,

@Value("\${app.admin-approval.profile-completion-request}")
Expand Down Expand Up @@ -164,16 +165,32 @@ class ProfileManagement(
)
)

validateInquiryResponses(shahkarResponse, comparativeResponse)
try {
validateInquiryResponses(shahkarResponse, comparativeResponse)
} catch (e: OpexException) {
if (!isAdminApprovalRequired ||
(e.error != OpexError.ShahkarInquiryError && e.error != OpexError.ComparativeInquiryError)
) throw e
}

val shahkarRequested = isIranian && mobileIdentityEnabled
val comparativeRequested = isIranian && personalIdentityEnabled

if (isIranian && !isAdminApprovalRequired)
return approveProfileAutomatically(userId, completedProfile)
val shahkarOk = !shahkarRequested || (shahkarResponse != null && !shahkarResponse.isError())
val comparativeOk = !comparativeRequested || (comparativeResponse != null && !comparativeResponse.isError())

return requestAdminApproval(userId)
val allRequestedInquiriesOk = shahkarOk && comparativeOk
val anyInquiryRequested = shahkarRequested || comparativeRequested

return when {
!isAdminApprovalRequired -> approveProfileAutomatically(userId, completedProfile)
isAdminApprovalRequired && !anyInquiryRequested -> requestAdminApproval(userId)
isAdminApprovalRequired && allRequestedInquiriesOk -> approveProfileAutomatically(userId, completedProfile)
else -> requestAdminApproval(userId) // At least one active inquiry has failed.
}
}

private suspend fun approveProfileAutomatically(userId: String, completedProfile: Profile): Profile {
private suspend fun approveProfileAutomatically(userId: String, completedProfile: Profile): Profile {
kycLevelUpdatedPublisher.publish(
KycLevelUpdatedEvent(userId, KycLevel.LEVEL_2, LocalDateTime.now())
)
Expand Down
4 changes: 2 additions & 2 deletions profile/profile-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ app:
auth-gateway:
url: lb://opex-auth-gateway
inquiry:
mobile-indentiy: true
personal-indentiy: false
mobile-identity: ${MOBILE_IDENTITY_INQUIRY}
personal-identity: ${PERSONAL_IDENTITY_INQUIRY}
url: ${JIBIT_URL}
api-key: ${JIBIT_API_KEY}
secret-key: ${JIBIT_SECRET_KEY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ProfileApprovalRequestRepository : ReactiveCrudRepository<ProfileAppro
fun findByUserIdAndStatus(
userId: String,
status: ProfileApprovalRequestStatus
): Mono<ProfileApprovalAdminResponse>
): Mono<ProfileApprovalRequestModel>

@Query(
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ interface ProfileRepository : ReactiveCrudRepository<ProfileModel, Long> {

fun findByUserId(userId: String): Mono<ProfileModel>

@Query("select * from profile where identifier = :identifier order by last_update_date desc limit 1")
fun findLatestByIdentifier(identifier: String ): Mono<ProfileModel>

@Query(
"""
SELECT *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import co.nilin.opex.profile.ports.postgres.model.entity.ProfileModel
import co.nilin.opex.profile.ports.postgres.utils.RegexPatterns
import co.nilin.opex.profile.ports.postgres.utils.toProfileModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.reactive.awaitFirstOrNull
Expand Down Expand Up @@ -52,6 +51,12 @@ class ProfileManagementImp(
val existingProfile = profileRepository.findByUserId(id)?.awaitFirstOrNull()
?: throw OpexError.ProfileNotfound.exception()

val latestProfileByIdentifier = profileRepository.findLatestByIdentifier(data.identifier).awaitFirstOrNull()
if (latestProfileByIdentifier != null && (latestProfileByIdentifier.status !=
ProfileStatus.PROFILE_COMPLETED && latestProfileByIdentifier.status !=
ProfileStatus.ADMIN_REJECTED)
) throw OpexError.InvalidProfileData.exception()

val newProfileModel = data.toProfileModel(
existing = existingProfile,
mobileMatch = mobileIdentityMatch,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE profile
DROP CONSTRAINT unique_identifier;
Loading