-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet/backend): add view card details endpoint (#1633)
* Add view card details endpoint * Prettier * Fix backend tests * Add endpoint for masked details * Small refactor * Prettier * Add migrations and check for WA mapping to card * Add tests * Update endpoints * Update getCardDetails request with URL * Address comments * Remove duplicate card app id header
- Loading branch information
Showing
16 changed files
with
583 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/wallet/backend/migrations/20240923105930_update_wallet_addresses.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
exports.up = function (knex) { | ||
return knex.schema.table('walletAddresses', function (table) { | ||
table.string('cardId').unique().nullable() | ||
}) | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.table('walletAddresses', function (table) { | ||
table.dropColumn('cardId') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Request, Response, NextFunction } from 'express' | ||
import { Controller } from '@shared/backend' | ||
import { CardService } from '@/card/service' | ||
import { toSuccessResponse } from '@shared/backend' | ||
import { | ||
ICardDetailsRequest, | ||
ICardDetailsResponse, | ||
ICardResponse | ||
} from './types' | ||
import { validate } from '@/shared/validate' | ||
import { getCardsByCustomerSchema, getCardDetailsSchema } from './validation' | ||
|
||
export interface ICardController { | ||
getCardsByCustomer: Controller<ICardDetailsResponse[]> | ||
getCardDetails: Controller<ICardResponse> | ||
} | ||
|
||
export class CardController implements ICardController { | ||
constructor(private cardService: CardService) {} | ||
|
||
public getCardsByCustomer = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const { params } = await validate(getCardsByCustomerSchema, req) | ||
const { customerId } = params | ||
|
||
const cards = await this.cardService.getCardsByCustomer(customerId) | ||
res.status(200).json(toSuccessResponse(cards)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
|
||
public getCardDetails = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const userId = req.session.user.id | ||
const { params, body } = await validate(getCardDetailsSchema, req) | ||
const { cardId } = params | ||
const { publicKeyBase64 } = body | ||
|
||
const requestBody: ICardDetailsRequest = { cardId, publicKeyBase64 } | ||
const cardDetails = await this.cardService.getCardDetails( | ||
userId, | ||
requestBody | ||
) | ||
res.status(200).json(toSuccessResponse(cardDetails)) | ||
} catch (error) { | ||
next(error) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { WalletAddressService } from '@/walletAddress/service' | ||
import { GateHubClient } from '../gatehub/client' | ||
import { | ||
ICardDetailsRequest, | ||
ICardDetailsResponse, | ||
ICardResponse | ||
} from './types' | ||
import { NotFound } from '@shared/backend' | ||
|
||
export class CardService { | ||
constructor( | ||
private gateHubClient: GateHubClient, | ||
private walletAddressService: WalletAddressService | ||
) {} | ||
|
||
async getCardsByCustomer(customerId: string): Promise<ICardResponse[]> { | ||
return this.gateHubClient.getCardsByCustomer(customerId) | ||
} | ||
|
||
async getCardDetails( | ||
userId: string, | ||
requestBody: ICardDetailsRequest | ||
): Promise<ICardDetailsResponse> { | ||
const { cardId } = requestBody | ||
|
||
const walletAddress = await this.walletAddressService.getByCardId( | ||
userId, | ||
cardId | ||
) | ||
if (!walletAddress) { | ||
throw new NotFound('Card not found or not associated with the user.') | ||
} | ||
|
||
return this.gateHubClient.getCardDetails(requestBody) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
export interface ICardDetailsRequest { | ||
cardId: string | ||
publicKeyBase64: string | ||
} | ||
|
||
export interface ICardDetailsResponse { | ||
cipher: string | null | ||
} | ||
|
||
export interface ILinksResponse { | ||
token: string | null | ||
links: Array<{ | ||
href: string | null | ||
rel: string | null | ||
method: string | null | ||
}> | null | ||
} | ||
|
||
export interface ICreateCustomerRequest { | ||
emailAddress: string | ||
account: { | ||
productCode: string | ||
} | ||
card: { | ||
productCode: string | ||
} | ||
user: { | ||
firstName: string | ||
lastName: string | ||
mobileNumber?: string | ||
nationalIdentifier?: string | ||
} | ||
identification: { | ||
documents: Array<{ | ||
type: string | ||
file: string // Base64-encoded file content | ||
}> | ||
} | ||
address: { | ||
addressLine1: string | ||
addressLine2?: string | ||
city: string | ||
region?: string | ||
postalCode: string | ||
countryCode: string | ||
} | ||
} | ||
|
||
export interface ICreateCustomerResponse { | ||
customerId: string | ||
accountId: string | ||
cardId: string | ||
} | ||
|
||
export interface ICardResponse { | ||
sourceId: string | ||
nameOnCard: string | ||
productCode: string | ||
id: string | ||
accountId: string | ||
accountSourceId: string | ||
maskedPan: string | ||
status: string | ||
statusReasonCode: string | null | ||
lockLevel: string | null | ||
expiryDate: string | ||
customerId: string | ||
customerSourceId: string | ||
} | ||
|
||
export type CardLimitType = | ||
| 'perTransaction' | ||
| 'dailyOverall' | ||
| 'weeklyOverall' | ||
| 'monthlyOverall' | ||
| 'dailyAtm' | ||
| 'dailyEcomm' | ||
| 'monthlyOpenScheme' | ||
| 'nonEUPayments' | ||
|
||
export interface ICardProductLimit { | ||
type: CardLimitType | ||
currency: string | ||
limit: string | ||
isDisabled: boolean | ||
} | ||
|
||
export interface ICardProductResponse { | ||
cardProductLimits: ICardProductLimit[] | ||
deletedAt: string | null | ||
uuid: string | ||
accountProductCode: string | ||
code: string | ||
name: string | ||
cost: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { z } from 'zod' | ||
|
||
export const getCardsByCustomerSchema = z.object({ | ||
params: z.object({ | ||
customerId: z.string() | ||
}) | ||
}) | ||
|
||
export const getCardDetailsSchema = z.object({ | ||
params: z.object({ | ||
cardId: z.string() | ||
}), | ||
body: z.object({ | ||
publicKeyBase64: z.string() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.