Skip to content
Merged
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
61 changes: 61 additions & 0 deletions packages/anchor-service/src/anchor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -44,6 +45,7 @@ export class AnchorService {
private readonly payments = new Map<string, Sep31PaymentRecord>();
private readonly transactions = new Map<string, AnchorTransaction>();
private readonly customers = new Map<string, CustomerRecord>();
private readonly accountLinks = new Map<string, string>();

// ---------------------------------------------------------------------------
// SEP-31 Direct Payment
Expand Down Expand Up @@ -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<KycStatusResponse> {
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
// ---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/anchor-service/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
7 changes: 7 additions & 0 deletions packages/anchor-service/src/interfaces/kyc.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface KycStatusResponse {
accountId: string;
status: 'pending' | 'approved' | 'rejected';
customerId?: string;
message?: string;
checkedAt: string;
}
Loading