diff --git a/packages/anchor-service/src/anchor.service.ts b/packages/anchor-service/src/anchor.service.ts index 88273ea..c1374f2 100644 --- a/packages/anchor-service/src/anchor.service.ts +++ b/packages/anchor-service/src/anchor.service.ts @@ -14,6 +14,7 @@ import type { CustomerStatus, IdentityDocument, } from './interfaces/customer.interface'; +import type { KycStatusResponse } from './interfaces/kyc.interface'; import type { FeeQuote, TransactionType } from './interfaces/fee.interface'; interface CustomerRecord { @@ -44,6 +45,7 @@ export class AnchorService { private readonly payments = new Map(); private readonly transactions = new Map(); private readonly customers = new Map(); + private readonly accountLinks = new Map(); // --------------------------------------------------------------------------- // SEP-31 Direct Payment @@ -304,6 +306,65 @@ export class AnchorService { return Array.from(this.customers.values()); } + // --------------------------------------------------------------------------- + // SEP-12 KYC Status + // --------------------------------------------------------------------------- + + linkAccount(accountId: string, customerId: string): void { + this.accountLinks.set(accountId, customerId); + } + + async checkKycStatus(accountId: string): Promise { + const customerId = this.accountLinks.get(accountId); + + if (!customerId) { + return { + accountId, + status: 'pending', + message: 'No KYC data found for this account. Please submit customer info first.', + checkedAt: new Date().toISOString(), + }; + } + + const customer = this.customers.get(customerId); + + if (!customer) { + this.accountLinks.delete(accountId); + return { + accountId, + status: 'pending', + message: 'Customer record not found. Please resubmit customer info.', + checkedAt: new Date().toISOString(), + }; + } + + let status: KycStatusResponse['status']; + switch (customer.status) { + case 'APPROVED': + status = 'approved'; + break; + case 'REJECTED': + status = 'rejected'; + break; + default: + status = 'pending'; + break; + } + + return { + accountId, + status, + customerId: customer.customerId, + message: + status === 'approved' + ? 'KYC approved' + : status === 'rejected' + ? 'KYC rejected' + : 'KYC is still being processed', + checkedAt: new Date().toISOString(), + }; + } + // --------------------------------------------------------------------------- // Fee Calculation // --------------------------------------------------------------------------- diff --git a/packages/anchor-service/src/index.ts b/packages/anchor-service/src/index.ts index 28d622c..3d297e9 100644 --- a/packages/anchor-service/src/index.ts +++ b/packages/anchor-service/src/index.ts @@ -17,4 +17,5 @@ export type { IdentityDocument, FileContent, } from './interfaces/customer.interface'; +export type { KycStatusResponse } from './interfaces/kyc.interface'; export type { FeeQuote, FeeBreakdown, TransactionType } from './interfaces/fee.interface'; diff --git a/packages/anchor-service/src/interfaces/kyc.interface.ts b/packages/anchor-service/src/interfaces/kyc.interface.ts new file mode 100644 index 0000000..51e3785 --- /dev/null +++ b/packages/anchor-service/src/interfaces/kyc.interface.ts @@ -0,0 +1,7 @@ +export interface KycStatusResponse { + accountId: string; + status: 'pending' | 'approved' | 'rejected'; + customerId?: string; + message?: string; + checkedAt: string; +}