Skip to content

seerbit/seerbit-nodejs-sdk-beginners-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Summary

This project demonstrates how to integrate the SeerBit Standard Checkout payment flow in a Node.js + Express API. It loads configuration from environment variables, initializes the SeerBit SDK, exposes a /api/standard-checkout endpoint to create payment links, and includes built‑in health checks and error handling. Follow the sections below to get started quickly.

Table of Contents

Features

  • SeerBit Standard Checkout integration for secure payment link generation (GitHub)
  • Express.js REST API with JSON parsing and CORS support (Express)
  • Environment‑based configuration using dotenv (GitHub)
  • Health‑check endpoint (GET /) to verify server status (Express)
  • Global error handler for consistent HTTP 500 responses (GitHub)

Prerequisites

  • Node.js v14+ and npm installed on your machine (GitHub)
  • A SeerBit merchant account with your Public & Secret keys and Bearer Token (doc.seerbit.com)
  • Git for version control (optional)

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/your-repo.git
    cd your-repo
  2. Install dependencies

    npm install express cors dotenv seerbit-nodejs
    • express for the web framework (Express)
    • cors for Cross‑Origin Resource Sharing (npm)
    • dotenv to load .env files (GitHub)
    • seerbit-nodejs for SeerBit SDK (GitHub)

Configuration

Create a .env file in the project root with the following variables:

PUBLIC_KEY=sbpub_xxx
SECRET_KEY=sbsec_xxx
BEARER_TOKEN=eyJhbGci…
PORT=8000
  • PUBLIC_KEY, SECRET_KEY, and BEARER_TOKEN come from your SeerBit dashboard (GitHub)
  • PORT defines which port the server listens on (default: 8000)

Running the Server

Start the Express server:

node app.js

You should see:

✅ Listening on port 8000

To auto‑reload on changes during development, use nodemon:

npx nodemon app.js
``` :contentReference[oaicite:12]{index=12}  


## API Endpoints

### Health‑Check  
```http
GET /

Response:

  • 200 OK with body "Server is up and running" (Express)

Standard Checkout

POST /api/standard-checkout
Content-Type: application/json

Body Parameters:

  • fullName (string)
  • amount (number)
  • currency (string, e.g., NGN)
  • country (string, ISO code)
  • email (string)

Success (201):

{ "response": { /* SeerBit API response */ } }

Under the hood, this uses SeerBit’s /payment/initialize endpoint to generate a checkout link (doc.seerbit.com).

Error Handling

  • SDK Initialization Errors log “⛔ SDK init failed” and exit if configuration is invalid.
  • Route Errors bubble up to a global handler that returns 500 Internal Server Error with a generic message.
  • Unhandled Routes return 404 Not Found. (You can add a catch‑all middleware if desired.) (GitHub)

Contributing

  1. Fork the repo
  2. Create a feature branch: git checkout -b feature/awesome-feature
  3. Commit your changes: git commit -m "Add awesome feature"
  4. Push to your branch: git push origin feature/awesome-feature
  5. Open a Pull Request

Please ensure all new code is covered by tests and follows existing style conventions.

License

This project is licensed under the MIT License. See the LICENSE file for details. (GitHub)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published