Swipelux

End-User Custodial Wallet + On-Ramp Checkout

Detailed implementation example of custodial wallets with on-ramp checkout for a digital media platform

Scenario: Digital Media Platform

Business Context

A digital media platform wants to enable users to purchase premium content using cryptocurrency while maintaining a simple user experience similar to traditional payment methods.

Requirements

  • Users should have wallets created automatically upon registration
  • Seamless funding through credit card to USDC conversion
  • Real-time balance display for purchasing decisions
  • One-click content purchases using wallet balance

Implementation Example

1. User Registration & Wallet Creation

// When user completes registration
const handleUserRegistration = async (userData) => {
  // Create platform user account
  const user = await createPlatformUser(userData);
  
  // Automatically create embedded crypto account
  const customer = await createCustomer({
    externalCustomerId: user.id,
    email: user.email,
    metadata: {
      platformUserId: user.id,
      registrationDate: new Date().toISOString(),
      accountType: 'premium_user'
    }
  });
  
  // Link customer ID to user profile
  await updateUserProfile(user.id, {
    embeddedAccountId: customer.id
  });
  
  return { user, customer };
};

2. Wallet Funding Flow

// When user wants to add funds
const initiateWalletFunding = async (userId, amount) => {
  const user = await getUserProfile(userId);
  
  // Create checkout session
  const checkoutUrl = await createHostedCheckout({
    customerId: user.embeddedAccountId,
    amount: amount,
    currency: 'USD',
    targetCurrency: 'USDC',
    successUrl: `${platformUrl}/wallet/success`,
    cancelUrl: `${platformUrl}/wallet/cancel`
  });
  
  return checkoutUrl;
};

3. Real-time Balance Integration

// Display user's USDC balance in platform UI
const getUserWalletBalance = async (userId) => {
  const user = await getUserProfile(userId);
  
  const balance = await getCustomerBalance(user.embeddedAccountId);
  
  return {
    amount: balance.amount,
    currency: balance.currency,
    formattedAmount: formatCurrency(balance.amount, 'USDC')
  };
};
 
// Real-time balance updates via webhooks
const handleBalanceUpdate = async (webhookEvent) => {
  if (webhookEvent.type === 'customer.balance.updated') {
    const customerId = webhookEvent.data.customerId;
    const user = await getUserByEmbeddedAccountId(customerId);
    
    // Push real-time update to user's browser
    await sendRealtimeUpdate(user.id, 'balance_updated', {
      newBalance: webhookEvent.data.balance
    });
  }
};

4. Content Purchase Implementation

// Purchase premium content using wallet balance
const purchaseContent = async (userId, contentId) => {
  const user = await getUserProfile(userId);
  const content = await getContent(contentId);
  
  // Check wallet balance
  const balance = await getCustomerBalance(user.embeddedAccountId);
  
  if (balance.amount < content.price) {
    throw new Error('Insufficient wallet balance');
  }
  
  // Create internal transfer to merchant account
  const transfer = await createTransfer({
    fromCustomerId: user.embeddedAccountId,
    toCustomerId: platformMerchantAccountId,
    amount: content.price,
    currency: 'USDC',
    description: `Purchase: ${content.title}`
  });
  
  // Grant content access
  await grantContentAccess(userId, contentId);
  
  return {
    success: true,
    transferId: transfer.id,
    contentAccess: true
  };
};

User Experience Flow

Registration Experience

  1. User signs up for platform account
  2. Wallet automatically created in background
  3. Welcome email includes wallet funding option
  4. User guided to add funds for first purchase

Purchasing Experience

  1. User browses premium content
  2. Balance displayed prominently in UI
  3. "Add Funds" button when balance insufficient
  4. One-click purchases when balance sufficient

Funding Experience

  1. User clicks "Add Funds" from any page
  2. Redirected to hosted checkout
  3. Enters credit card details
  4. Returns to platform with updated balance

Success Metrics

Technical Metrics

  • Wallet creation success rate: 99.8%
  • Average funding time: 45 seconds
  • Purchase completion rate: 94%

Business Metrics

  • User adoption of crypto payments: 67%
  • Average wallet balance maintained: $47
  • Repeat purchase rate: 78%

Lessons Learned

User Education

  • Clear messaging about USDC stability
  • Visual indicators for wallet balance
  • Educational content about crypto benefits

UX Optimizations

  • Persistent balance display
  • Smart funding suggestions
  • Simplified purchase confirmations

Technical Considerations

  • Webhook reliability crucial for real-time updates
  • Balance caching for improved performance
  • Proper error handling for edge cases