# Node.js SDK

## Installation

```bash
npm install payfet-sdk
```

## Quick start

```js
const Payfet = require('payfet-sdk');

// Initialize the client with your API key
const client = new Payfet({
  apiKey: 'your_api_key_here',
  environment: 'production' // or 'sandbox'
});

// Process a bill payment
client.payBill({
  phone: '08012345678',
  amount: 500,
  billType: 'electricity'
})
.then(response => {
  console.log('Payment successful:', response);
})
.catch(error => {
  console.error('Payment failed:', error);
});
```

Keep the API key on your server. A key shipped to a browser is a key anyone can
read and spend.

## TypeScript

```ts
import Payfet from 'payfet-sdk';

interface PaymentRequest {
  phone: string;
  amount: number;
  billType: string;
}

const client = new Payfet({
  apiKey: process.env.PAYFET_API_KEY!,
  environment: 'production'
});

async function processPayment(request: PaymentRequest) {
  try {
    const response = await client.payBill(request);
    console.log('Transaction ID:', response.transactionId);
    return response;
  } catch (error) {
    console.error('Payment failed:', error);
    throw error;
  }
}
```

## Common operations

```js
// Top up airtime
await client.topupAirtime({
  phone: '08012345678',
  amount: 1000,
  provider: 'MTN'
});

// Check transaction status
const status = await client.getTransactionStatus('txn_123456');
console.log('Status:', status.status);

// Retrieve account balance
const balance = await client.getBalance();
console.log('Available balance:', balance.amount);
```

## Taking payments from your customers

The SDK covers bills, airtime and account operations. To charge your own
customers on your website, use the checkout API — see
[Accept payments on your site](/docs/inline).

## Need help?

Email [support@payfet.org](mailto:support@payfet.org).
