Skip to content

Commit

Permalink
feat: check user verification status on onboarding request (#1846)
Browse files Browse the repository at this point in the history
* feat: check user verification status on onboarding request

* test: change response on iframeurl

* fix: format
  • Loading branch information
dragosp1011 authored Nov 27, 2024
1 parent 34297b2 commit 9234039
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
13 changes: 12 additions & 1 deletion packages/wallet/backend/src/gatehub/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ export class GateHubController implements IGateHubController {
try {
const userId = req.session.user.id
const iframeType: IFRAME_TYPE = req.params.type as IFRAME_TYPE
const url = await this.gateHubService.getIframeUrl(iframeType, userId)
const { url, isApproved, customerId } =
await this.gateHubService.getIframeUrl(iframeType, userId)

if (isApproved) {
req.session.user.needsIDProof = false

if (customerId) {
req.session.user.customerId = customerId
}

await req.session.save()
}
res.status(200).json(toSuccessResponse({ url }))
} catch (e) {
next(e)
Expand Down
24 changes: 21 additions & 3 deletions packages/wallet/backend/src/gatehub/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IFRAME_TYPE } from '@wallet/shared/src'
import { User } from '@/user/model'
import { NotFound } from '@shared/backend'
import {
IAddUserToGatewayResponse,
ICardTransactionWebhookData,
IDepositWebhookData,
IWebhookData
Expand Down Expand Up @@ -30,18 +31,35 @@ export class GateHubService {
private emailService: EmailService
) {}

async getIframeUrl(iframeType: IFRAME_TYPE, userId: string): Promise<string> {
async getIframeUrl(
iframeType: IFRAME_TYPE,
userId: string
): Promise<{ url: string; isApproved?: boolean; customerId?: string }> {
const user = await User.query().findById(userId)
if (!user || !user.gateHubUserId) {
throw new NotFound()
}

let addUserToGatewayResponse = {}
if (iframeType === 'onboarding' && !this.gateHubClient.isProduction) {
const userState = await this.gateHubClient.getUserState(
user.gateHubUserId
)

if (userState.verifications[0]?.status === 1) {
addUserToGatewayResponse = await this.addUserToGateway(userId)
}
}

const url = await this.gateHubClient.getIframeUrl(
iframeType,
user.gateHubUserId
)

return url
return {
url,
...addUserToGatewayResponse
}
}

async handleWebhook(data: IWebhookData) {
Expand Down Expand Up @@ -203,7 +221,7 @@ export class GateHubService {
async addUserToGateway(
userId: string,
isApproved = false
): Promise<{ isApproved: boolean; customerId?: string }> {
): Promise<IAddUserToGatewayResponse> {
const user = await User.query().findById(userId)
if (!user || !user.gateHubUserId) {
throw new NotFound()
Expand Down
13 changes: 13 additions & 0 deletions packages/wallet/backend/src/gatehub/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ export interface ICreateManagedUserResponse {
managedBy: string
}

interface IVerification {
uuid: string
status: number
state: number
provider_type: 'sumsub'
}

export interface IGetUserStateResponse {
profile: {
first_name: string
Expand All @@ -53,6 +60,7 @@ export interface IGetUserStateResponse {
address_street1: string
address_street2: string
}
verifications: IVerification[]
}

export interface ICreateWalletRequest {
Expand Down Expand Up @@ -170,3 +178,8 @@ export interface IDepositWebhookData {
deposit_type: DepositTypeEnum
message?: string
}

export interface IAddUserToGatewayResponse {
isApproved: boolean
customerId?: string
}
4 changes: 3 additions & 1 deletion packages/wallet/backend/tests/gatehub/controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ describe('GateHub Controller', () => {
type: 'withdrawal'
}
const mockedIframeUrl = 'URL'
mockGateHubService.getIframeUrl.mockResolvedValue(mockedIframeUrl)
mockGateHubService.getIframeUrl.mockResolvedValue({
url: mockedIframeUrl
})

await gateHubController.getIframeUrl(req, res, next)

Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/backend/tests/gatehub/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('GateHub Service', (): void => {
mockGateHubClient.getIframeUrl.mockReturnValue(mockedIframeUrl)

const result = await gateHubService.getIframeUrl('withdrawal', user.id)
expect(result).toMatch(mockedIframeUrl)
expect(result).toMatchObject({ url: mockedIframeUrl })
})

it('should return NotFound if no user found', async () => {
Expand Down

0 comments on commit 9234039

Please sign in to comment.