I'm always excited to take on new projects and collaborate with innovative minds.

Phone

+234 8140152497

Email

templeok.ok@gmail.com

Website

https://portfolio.templeedgeplatforms.com/

Address

16 Ola Adigun St, Ikate Lekki Lagos

Social Links

Collaborations

How to Integrate APIs in Node.js for Your Next Project

Learn how to seamlessly integrate third-party APIs in your Node.js applications for powerful data access and functionality.

How to Integrate APIs in Node.js for Your Next Project

Β 


How I Integrated Wema Bank API in a Real Node.js E-commerce Project

πŸ“Œ Project Overview

This integration was implemented in a production e-commerce platform for Gift Deevah Ltd. The goal was to enable secure online payments directly on the platform using Wema Bank API, ensuring automated transaction processing, verification, and order confirmation without manual intervention.

πŸ‘‰ You can view the live project here: https://giftdeevah.com

This system handles real customer transactions, meaning every part of the integration had to be secure, reliable, and production ready.


βš™οΈ System Architecture

The payment system was built using a Node.js backend that acts as the central layer between the frontend checkout flow and Wema Bank API services.

Flow of the system:

  1. User places an order on the frontend
  2. Backend initializes payment request to Wema Bank API
  3. User completes payment on bank gateway
  4. Wema Bank sends webhook response to backend
  5. Backend verifies transaction
  6. Order status is updated in database
  7. Customer receives confirmation

🧠 Tech Stack

Frontend
HTML5
CSS3
JavaScript
Bootstrap

Backend
Node.js
Express.js

Database
MySQL

API Integration
Wema Bank Payment API
Webhook event handling
RESTful architecture

Tools
Postman for testing
Git for version control
Environment variables for security


πŸ’³ Payment Initialization (Backend Logic)

When a user checks out, the backend sends a request to Wema Bank to initialize the transaction.

const axios = require("axios");

async function initializePayment(order) {
  try {
    const response = await axios.post(
      "https://api.wemabank.com/payment/initiate",
      {
        amount: order.amount,
        email: order.customerEmail,
        reference: order.referenceId,
        callback_url: "https://giftdeevah.com/payment/callback"
      },
      {
        headers: {
          Authorization: `Bearer ${process.env.WEMA_SECRET_KEY}`
        }
      }
    );

    return response.data;
  } catch (error) {
    console.error("Payment Init Error:", error.message);
  }
}

This step generates a payment session and returns authorization details to the frontend.


πŸ” Webhook Verification (Critical Part)

After payment is completed, Wema Bank sends a webhook to confirm the transaction status.

app.post("/webhook/wema", async (req, res) => {
  try {
    const event = req.body;

    if (event.status === "success") {
      const reference = event.reference;

      await db.query(
        "UPDATE orders SET status = ? WHERE reference = ?",
        ["paid", reference]
      );

      console.log("Payment verified and order updated");
    }

    res.sendStatus(200);
  } catch (error) {
    console.error("Webhook Error:", error.message);
    res.sendStatus(500);
  }
});

This ensures only verified payments update the system.


πŸ“Š Order Update Logic

After verification, the order is automatically updated:

async function updateOrderStatus(reference, status) {
  await db.query(
    "UPDATE orders SET payment_status = ? WHERE reference_id = ?",
    [status, reference]
  );
}

This removes manual intervention and ensures accuracy.


🧩 Key Challenges Solved

1. Payment State Handling

Handled multiple states like pending, failed, and successful transactions to avoid inconsistent order records.

2. Webhook Security

Implemented validation checks to ensure only authentic requests from Wema Bank update the database.

3. Transaction Consistency

Ensured every payment has a unique reference ID to avoid duplication or mismatch in orders.

4. Error Handling

Built fallback logic for failed API requests and network issues to maintain system stability.


πŸ”’ Security Practices

  • API keys stored in environment variables
  • No sensitive data exposed on frontend
  • Webhook validation before updating database
  • Secure server-side transaction handling

πŸš€ Project Impact

This integration transformed the e-commerce system into a fully automated payment platform. Customers can now complete purchases seamlessly, while the business receives instant payment verification and order updates.

It improved operational efficiency, reduced manual work, and increased trust in the platform’s payment system.


πŸ’‘ Final Insight

This project demonstrates my ability to build real-world financial integrations using Node.js, combining backend architecture, API communication, security practices, and business logic into a production-ready system.


πŸ‘‰ Visit the live system here: https://giftdeevah.com


Full Stack Development, API Development, Botble CMS
3 min read
Dec 25, 2024
By Temple Henley
Share

Leave a comment

Your email address will not be published. Required fields are marked *

Related posts

Aug 27, 2025 β€’ 2 min read
Why I Love Contributing to Open Source Projects

A deep dive into why open source matters to me, how it helped me grow...

Apr 11, 2025 β€’ 3 min read
5 Essential Tools for Web Developers in 2026

Discover the top 5 tools that are essential for web developers in 2026...

Dec 23, 2024 β€’ 3 min read
Exploring the Benefits of MySQL for Large-Scale Projects

An exploration of why MySQL is a great choice for large-scale projects...

Your experience on this site will be improved by allowing cookies. Cookie Policy