Skip to main content

Complete Integration Example

Here's a implementation combining all concepts:

class AccrueOnboarding {
constructor(config) {
this.config = config;
this.kycRequiredOps = [
'deposit_funds',
'create_payment',
'withdraw_funds'
];
}

// Phase 1: Instant onboarding
async quickStart(customer, internalId) {
try {
// Create user and wallet immediately
const userId = await this.createUser(customer);
const walletId = await this.createWallet(userId);

// User can now link accounts and receive rewards
await this.saveToDatabase({
internalId,
accrueUserId: userId,
walletId,
kycStatus: 'NotStarted',
phase: 'quick_start_complete'
});

return {
success: true,
userId,
walletId,
capabilities: {
canLinkAccounts: true,
canReceiveRewards: true,
canDeposit: false, // Requires KYC
canPurchase: false // Requires KYC
}
};
} catch (error) {
return this.handleError(error);
}
}

// Phase 2: Enable banking when needed
async enableBanking(userId, triggeredBy) {
// Check if already verified
const status = await this.getKycStatus(userId);
if (status === 'Approved') {
return { alreadyEnabled: true };
}

// Start KYC process
await this.acceptDisclosures(userId);

return {
kycInitiated: true,
triggeredBy,
message: 'Complete verification in your wallet to continue',
estimatedTime: '2-5 minutes'
};
}

// Smart operation handler
async performOperation(userId, operation, params) {
// Check if this operation needs KYC
if (this.kycRequiredOps.includes(operation)) {
const status = await this.getKycStatus(userId);

if (status !== 'Approved') {
// Trigger Phase 2
const result = await this.enableBanking(userId, operation);
return {
success: false,
requiresKyc: true,
kycStatus: status,
...result
};
}
}

// Perform the operation
return await this.executeOperation(operation, params);
}

// Webhook handler for status updates
async handleWebhook(event) {
const userId = event.included[0].id;
const topic = event.attributes.topic;

const handlers = {
ApplicationApproved: () => this.onKycApproved(userId),
ApplicationDeclined: () => this.onKycDenied(userId),
ApplicationAwaitingDocuments: () => this.onDocumentsNeeded(userId)
};

const handler = handlers[topic];
if (handler) await handler();
}

async onKycApproved(userId) {
await this.updateStatus(userId, 'Approved');
await this.enableAllFeatures(userId);
await this.notifyUser(userId, {
title: '✓ Verification Complete',
message: 'You can now deposit funds and make purchases!',
features: ['deposit', 'purchase', 'withdraw']
});
}
}

Key Concepts

This implementation demonstrates the two-phase onboarding strategy:

  1. Phase 1: Quick Start - Users can immediately create accounts, link payment methods, and receive rewards without any verification
  2. Phase 2: Enable Banking - KYC verification is triggered only when users attempt money movement operations

Integration Points

  • User Creation: Instant user and wallet creation
  • KYC Detection: Smart operation handler checks KYC requirements
  • Webhook Processing: Real-time status updates via webhooks
  • Error Handling: Graceful handling of common scenarios

Next Steps