Quick Start Guide

Get up and running with SwiftWallet in minutes.

1

Create an Account

Sign up at swiftwallet.co.ke or use the Account API

JavaScript
// Create account
const response = await fetch('https://swiftwallet.co.ke/v3/account/', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    username: 'myapp',
    email: '[email protected]',
    password: 'SecurePass123',
    first_name: 'Developer',
    last_name: 'Account'
  })
});
const { data: { api_key } } = await response.json();
console.log('Your API Key:', api_key);
2

Configure Payment Channel

Set up where payments should be routed

JavaScript
// Add a paybill channel
const response = await fetch('https://swiftwallet.co.ke/v3/channels/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    action: 'add',
    channel_name: 'My Paybill',
    channel_type: 'paybill',
    paybill_number: '174379',
    account_number: 'ACC001',
    account_name: 'My Business',
    is_default: true
  })
});
3

Collect Your First Payment

Initiate an STK Push to your customer

JavaScript
// Send STK Push
const response = await fetch('https://swiftwallet.co.ke/v3/stk-initiate/', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    amount: 100,
    phone_number: '254712345678',
    external_reference: 'ORDER-001',
    callback_url: 'https://myapp.com/payment-callback'
  })
});

const result = await response.json();
console.log('Transaction ID:', result.transaction_id);
console.log('Checkout Request ID:', result.checkout_request_id);
4

Handle the Callback

Process the payment result in your callback endpoint

JavaScript
// Express.js callback handler example
app.post('/payment-callback', (req, res) => {
  const { success, transaction_id, status, result } = req.body;
  
  if (success && status === 'completed') {
    console.log(`Payment successful! Receipt: ${result.MpesaReceiptNumber}`);
    console.log(`Amount: ${result.Amount}, Phone: ${result.Phone}`);
    // Update your order status
  } else {
    console.log(`Payment failed: ${result.ResultDesc}`);
  }
  
  res.status(200).send('OK');
});