npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nhonga-api

v1.0.0

Published

Biblioteca Node.js para integração com a API Nhonga.net

Readme

Nhonga API - Node.js Library

Biblioteca Node.js para integração com a API de pagamentos da Nhonga.net.

Instalação

npm install nhonga-api

Configuração

import { NhongaAPI } from 'nhonga-api';

const nhonga = new NhongaAPI({
  apiKey: 'SUA_CHAVE_API',
  secretKey: 'SUA_CHAVE_SECRETA', // Opcional, necessária para webhooks
  baseUrl: 'https://nhonga.net/api/' // Opcional, padrão já configurado
});

Uso

Criar Pagamento

try {
  const payment = await nhonga.createPayment({
    amount: 1500,
    context: 'Pagamento do curso de programação',
    callbackUrl: 'https://seusite.com/webhook',
    returnUrl: 'https://seusite.com/obrigado',
    currency: 'MZN',
    enviroment: 'prod'
  });

  console.log('URL de redirecionamento:', payment.redirectUrl);
  console.log('ID da transação:', payment.id);
} catch (error) {
  console.error('Erro ao criar pagamento:', error.message);
}

Verificar Status do Pagamento

try {
  const status = await nhonga.getPaymentStatus({
    id: 'txn_123456789'
  });

  console.log('Status:', status.status);
  console.log('Valor:', status.amount);
  console.log('Método:', status.method);
} catch (error) {
  console.error('Erro ao verificar status:', error.message);
}

Pagamento Direto Mobile

try {
  const mobilePayment = await nhonga.createMobilePayment({
    method: 'mpesa',
    amount: 2500,
    context: 'Recarga de saldo',
    useremail: '[email protected]',
    userwhatsApp: '841234567',
    phone: '841416077'
  });

  console.log('ID da transação:', mobilePayment.id);
} catch (error) {
  console.error('Erro no pagamento mobile:', error.message);
}

Processamento de Webhooks

import express from 'express';

const app = express();
app.use(express.json());

app.post('/webhook', (req, res) => {
  const secretKey = req.headers['secretkey'];
  const payload = req.body;

  try {
    nhonga.processWebhook(payload, secretKey, (webhookData) => {
      console.log('Pagamento confirmado:', webhookData.id);
      console.log('Valor pago:', webhookData.paid);
      console.log('Valor recebido:', webhookData.received);
      console.log('Taxa:', webhookData.fee);
      
      // Processar o pagamento confirmado
      // Atualizar banco de dados, enviar email, etc.
    });

    res.status(200).send('OK');
  } catch (error) {
    console.error('Webhook inválido:', error.message);
    res.status(400).send('Invalid webhook');
  }
});

Tipos TypeScript

A biblioteca inclui tipos TypeScript completos:

interface CreatePaymentRequest {
  amount: number;
  context: string;
  callbackUrl?: string;
  returnUrl?: string;
  currency?: 'MZN' | 'USD';
  enviroment?: 'prod' | 'dev';
}

interface PaymentStatusResponse {
  success: boolean;
  status: 'pending' | 'completed' | 'cancelled';
  amount: number;
  tax: number;
  method: string;
  currency: string;
}

interface MobilePaymentRequest {
  method: 'mpesa' | 'emola';
  amount: number;
  context: string;
  useremail: string;
  userwhatsApp: string;
  phone: string;
}

Tratamento de Erros

A biblioteca usa a classe NhongaError para erros específicos da API:

try {
  const payment = await nhonga.createPayment(paymentData);
} catch (error) {
  if (error instanceof NhongaError) {
    console.error('Erro da API Nhonga:', error.message);
    console.error('Código de status:', error.statusCode);
  } else {
    console.error('Erro inesperado:', error.message);
  }
}

Ambiente de Desenvolvimento

Para testes, use enviroment: 'dev' nas requisições de pagamento:

const payment = await nhonga.createPayment({
  amount: 1000,
  context: 'Teste de pagamento',
  enviroment: 'dev' // Não gera cobrança real
});

Suporte

Para suporte técnico, entre em contato:

Licença

MIT