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

telebirrts

v1.0.7

Published

typescript enforced teleBirr API package

Downloads

16

Readme

telebirrts Alpha Version

Typescript enforced teleBirr API package

Installation

Install telebirrts with npm

  npm install telebirrts

Install telebirrts with yarn

  yarn add telebirrts

Usage/Examples

To use the TeleBirr API, you first need to create an instance of the Telebirr class, which encapsulates the basic configuration of the API. You can then create an instance of the H5WebPayment class, which represents a payment made using the H5WebPayment method. Finally, you can call the sendRequest method on the H5WebPayment instance to initiate the payment request.

import { Telebirr, H5WebPayment, InAppPayment,IH5webResponse, checkIfSuccess, TeleBirrError, isOfTypeH5webResponse, isOfTypeInAppResponse,IAndroidReturnApp,IIOSReturnApp } from "telebirrts";
import crypto from "crypto"
import express, { Request, Response } from 'express';

const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
    modulusLength: 4000, // key length telebirrr is 2048
});

const telebirr: Telebirr = Telebirr.fromOneValue({
    appid: "123456",
    appkey: "123456",
    publicKey: publicKey.export({ type: 'pkcs1', format: 'pem' }).toString(),
    baseUrl: "https://api.telebirr.com",
    notifyUrl: "https://www.yourApp.com/notifyUrl",
    timeoutExpress: "123456",
    receiveName: "kolo",
    shortCode: "123456",
});

const webPayment: H5WebPayment = new H5WebPayment(telebirr, "/returnUrl");

const isoReturnApp: IIOSReturnApp = {
    Identifier: "willOpenTelebirrPay",
    Schemes: "com.ethio.telebirr"
}

const andoridReturnApp: IAndroidReturnApp = {
    Activity: "cn.tydic.ethiopay",
    PackageName: "cn.tydic.ethiopay.PayForOtherAppActivity"
}

const inappPayment: InAppPayment = new InAppPayment(telebirr, isoReturnApp); // or  new InAppPayment(telebirr, andoridReturnApp);

webPayment.addTransaction({
    nonce: "123456",
    outTradeNo: "123456",
    subject: "Api",
    totalAmount: "100.0",
})

inappPayment.addTransaction({
    nonce: "654321",
    outTradeNo: "654321",
    subject: "Api2",
    totalAmount: "1000.0",
})

async function pay() {
    try {
        // const res = await inappPayment.sendRequest(); OR
        const res = await webPayment.sendRequest();
        console.log("res: ", res);
    } catch (error) {
        console.log(error)
    }
}
pay();

const app = express();

app.post(telebirr.requestReq.notifyUrl, (req: Request, res: Response) => {
    const teleNotifyResponse: any = req.body;
    if (checkIfSuccess(teleNotifyResponse)) {

        if (isOfTypeH5webResponse(teleNotifyResponse)) {
            console.log("success toPayUrl: ", teleNotifyResponse.data.toPayUrl)
            res.json({ message: "success", toPayUrl: teleNotifyResponse.data.toPayUrl })
        }
        else if (isOfTypeInAppResponse(teleNotifyResponse)) {
            console.log("success toPayMsg: ", teleNotifyResponse.data.toPayMsg)
            res.json({ message: "success", toPayMsg: teleNotifyResponse.data.toPayMsg })
        } else {
            throw new TeleBirrError("Unknown object", "-1");
        }
    }

    else {
        throw new TeleBirrError(teleNotifyResponse.message, teleNotifyResponse.code);
    }

});

In this example, we first create an instance of the Telebirr class, passing in the basic configuration options for the API. We then create an instance of the H5WebPayment class, passing in the Telebirr instance and the URL of the page to redirect the user to after the payment is completed.

We then add a transaction using the addTransaction method on the H5WebPayment instance. Finally, we call the sendRequest method on the H5WebPayment instance to initiate the payment request.

Features

  • H5WebPayment
  • InAppPayment
  • fully typed god bless typescript🤩❤️❤️

Lessons Learned

Learned Design Patterns, this libraries mostly inspired/made up of strategy and decorator pattern

Support

As you may or may not noticed it's UNtested ie. didn't have access to credentials any issues would be appreciated If you have any suggestions or find any issues with the API, please open an issue on the GitHub repository 😻

Contributing

Contributions are welcome! 🤩✌️✌️