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 🙏

© 2024 – Pkg Stats / Ryan Hefner

selcomussdclient

v1.0.5

Published

Selcom Push USSD client

Downloads

11

Readme

selcomussdclient

selcomussdclient is a TypeScript package for interacting with the Selcom API. It provides an easy-to-use interface for creating orders, processing payments, and managing transactions.

Installation

npm install selcomussdclient

Usage

Initializing the Client

import SelComClient, { BASE_URL_ENUM } from 'selcomussdclient';

const client = new SelComClient(
  BASE_URL_ENUM.BASE_URL,
  'your-api-key',
  'your-api-secret'
);

Creating a Minimal Order

import { MAIN_PATH_ENUM, minimalOrderPayLoadInterface } from 'selcom-client';

const orderPayload: minimalOrderPayLoadInterface = {
  vendor: 'your-vendor-id',
  order_id: 'unique-order-id',
  buyer_email: '[email protected]',
  buyer_name: 'John Doe',
  buyer_phone: '255123456789',
  amount: 10000, // Amount in cents
  currency: 'TZS',
  buyer_remarks: 'Purchase of Product X',
  merchant_remarks: 'Internal reference: ABC123',
  no_of_items: 1
};

const response = await client.post(MAIN_PATH_ENUM.MINIMUM_ORDER_PATH, orderPayload);
console.log(response);

Initiating USSD Push Payment

Important Note: The order_id used in this step should be the same as the one used when creating the minimal order. This ensures that the payment is associated with the correct order.

import { MAIN_PATH_ENUM, uSSDPaymentPayloadInterface } from 'selcom-client';

const ussdPayload: uSSDPaymentPayloadInterface = {
  transid: 'unique-transaction-id',
  order_id: 'unique-order-id', // This should match the order_id used in Creating a Minimal Order
  msisdn: '255123456789'
};

const response = await client.post(MAIN_PATH_ENUM.USSD_PUSH_PATH, ussdPayload);
console.log(response);

Listing Orders

import { URL_LIST_ORDER_PATH_ENUM, ordersListPayloadInterface } from 'selcom-client';

const listOrdersPayload: ordersListPayloadInterface = {
  fromdate: '2024-01-01',
  todate: '2024-01-31'
};

const response = await client.getOrderList(URL_LIST_ORDER_PATH_ENUM.LIST_ORDERS, listOrdersPayload);
console.log(response);

Cancelling an Order

import { URL_CANCEL_ORDER_PATH_ENUM, orderCancelPayloadInterface } from 'selcom-client';

const cancelOrderPayload: orderCancelPayloadInterface = {
  order_id: 'existing-order-id'
};

const response = await client.cancelOrder(URL_CANCEL_ORDER_PATH_ENUM.CANCEL_ORDER, cancelOrderPayload);
console.log(response);

Enum Structures

The package uses several enums to organize API endpoints and base URLs:

export enum BASE_URL_ENUM {
    BASE_URL = 'https://apigw.selcommobile.com/v1',
}

export enum MAIN_PATH_ENUM {
    MINIMUM_ORDER_PATH = '/checkout/create-order-minimal',
    USSD_PUSH_PATH = '/checkout/wallet-payment',
}

export enum URL_LIST_ORDER_PATH_ENUM {
    LIST_ORDERS = '/checkout/list-orders',
}

export enum URL_CANCEL_ORDER_PATH_ENUM {
    CANCEL_ORDER = '/v1/checkout/cancel-order',
}

Interface Structures

The package includes several interfaces for request payloads and response data:

interface paymentResponseInterface {
    result: 'SUCCESS' | 'FAILURE'; // Assuming these are the possible values
    resultcode: string;
    order_id: string;
    transid: string;
    reference: string;
    channel: string;
    amount: string;
    phone: string;
    payment_status: 'COMPLETED' | 'PENDING' | 'FAILED'; // Assuming these are the possible values
}

export interface minimalOrderPayLoadInterface {
    vendor: string;
    order_id: string;
    buyer_email: string;
    buyer_name: string;
    buyer_phone: string;
    amount: number;
    currency: string;
    buyer_remarks: string;
    merchant_remarks: string;
    no_of_items: number;
}

export interface uSSDPaymentPayloadInterface {
    transid: string;
    order_id: string;
    msisdn: string;
}

export interface ordersListPayloadInterface {
    fromdate: string;
    todate: string;
}

export interface orderCancelPayloadInterface {
    order_id: string;
}

export interface minimalOrderResponseInterface {
    reference: string;
    resultcode: string;
    result: 'SUCCESS' | 'FAIL';
    message: string;
    data: minimalOrderData[];
}

export interface ussdPushResponseInterface {
    reference: string;
    resultcode: string;
    result: 'SUCCESS' | 'FAIL';
    message: string;
    data: [];
}

export interface OrderListResponseInterface {
    reference: string;
    resultcode: string;
    result: 'FAIL' | 'SUCCESS' | 'PENDING';
    message: string;
    data: orderData[];
}

export interface orderCancelResponseInterface {
    reference: string;
    resultcode: string;
    result: 'SUCCESS' | 'FAIL';
    message: string;
    data: [];
}

Error Handling

The SelComClient methods return the API response data. In case of an error, they return the error response data. Always check the result field in the response to determine if the operation was successful.

const response = await client.post(MAIN_PATH_ENUM.MINIMUM_ORDER_PATH, orderPayload);
if (response.result === 'SUCCESS') {
  console.log('Order created successfully:', response.data);
} else {
  console.error('Error creating order:', response.message);
}

License

This project is licensed under the MIT License.