Top

Code Examples

Ready-to-use code samples and tutorials for common B21 integration scenarios

Process a Payment

Create and process a payment using the B21 API with proper error handling.

JavaScript
// JavaScript Example
const payment = await b21.payments.create({
  amount: '10000',
  currency: 'NGN',
  customer: {
    email: 'customer@example.com',
    name: 'John Doe'
  }
});
JavaScript Payments

Transfer Money

Send money to a bank account using the transfers API.

PHP
// PHP Example
$transfer = $client->transfers->create([
    'amount' => '50000',
    'currency' => 'NGN',
    'recipient' => [
        'account_number' => '1234567890',
        'bank_code' => '044'
    ]
]);
PHP Transfers

Handle Webhooks

Set up a webhook endpoint to receive real-time event notifications.

Node.js
// Node.js Example
app.post('/webhook', (req, res) => {
  const event = req.body;

  switch (event.type) {
    case 'payment.succeeded':
      handlePaymentSuccess(event.data);
      break;
  }

  res.status(200).send('OK');
});
Node.js Webhooks