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

tranzak-node

v3.1.3

Published

TRANZAK API client for Nodejs

Downloads

333

Readme

TRANZAK Nodejs API client

This client allows the use of TRANZAK APIs via Nodejs.

The documentation for the REST APIs, can be found here.

Payment

Just flow with the code-completion.

For example

    import TRANZAK from 'tranzak-node'
    const client = new TRANZAK(
        {
            appId: 'aprb1ozfx10r31',
            appKey: '939AC5BF3348EA37FC24C34209AF71DC',
            mode: 'sandbox', // You can as well use 'live', or leave it blank. Leaving blank, also means, 'live'
        }
    )

    
    const transaction = await client.payment.collection.simple.chargeMobileMoney(
        {
            amount: 27_000,
            currencyCode: 'XAF',
            description: `Payment for shoes`,
            payerNote: `Payment for shoes.`,
            mchTransactionRef: shortUUID.generate(),
            mobileWalletNumber: `237677683958`,
        }
    )
    // Some time later
    await transaction.refresh()


    if (transaction.data.status === 'SUCCESSFUL') {
        console.log(`Our client just confirmed the transaction.\nHow sweet!`)

        // And later

        //Let's send the money to the payout account
        const collectionAccount = (await client.account.list()).find(acc => acc.data.accountId === transaction.data.merchant.accountId)

        await client.payment.transfer.simple.toPayoutAccount(
            {
                amount: 25_200,
                currencyCode: 'XAF',
                customTransactionRef: collectionAccount.data.accountId,
                description: `For payouts`,
                payeeNote: 'For payouts.',
                fundingAccountId: collectionAccount.data.accountId
            }
        )


        await client.payment.transfer.simple.toMobileMoney(
            {
                payeeAccountId: '237677683958',
                amount: 25_100,
                currencyCode: 'XAF',
                customTransactionRef: shortUUID.generate(),
                description: `For procurement of materials.`,
                payeeNote: `Procument of materials`,
            }
        )

        console.log(`Money successfully transferred to the procurement officer.`)

    }

    // Or, for other non-direct payment methods, use web redirect.
    const transaction = await client.payment.collection.simple.chargeByWebRedirect(
        {
            mchTransactionRef: shortUUID.generate()
        }
    )

    console.log(`Dear client, go to `, transaction.links.paymentAuthUrl)

Also, you can use the package in commonjs fashion; like so

    const tranzak_node = require('tranzak-node')
    // bla bla bla

Payment Methods

All other payments such as card, and bank, are handle via web redirect.

Webhooks

This library also comes with functionality to help you process webhooks. Use the client.webhook property, to access those features.

When data is processed, the processor emits an event with fully qualified transaction information.

For example:


    import TRANZAK from 'tranzak-node'
    const client = new TRANZAK(
        {
            appId: 'aprb1ozfx10r31',
            appKey: '939AC5BF3348EA37FC24C34209AF71DC',
            mode: 'sandbox',
        }
    );

    // Whenever a transaction is complete, we'll receive the event here
    client.webhook.addListener('payment.collection.completed', (transaction) => { // remember to flow with the auto-complete
        console.log(`Dear user, transaction complete. ID: `, transaction.data.requestId)
    })

    // And whenever a transaction is canceled, we'll know from here
    client.webhook.addListener('payment.collection.canceled', (transaction) => { // remember to flow with the auto-complete
        console.log(`Dear user, the transaction was canceled. ID: `, transaction.data.requestId)
    })

    // Now, go to the developer portal (https://developer.tranzak.me), and configure webhooks.

Whenever you receive HTTP data via the server you've configured, parse the body in JSON, and send the object to the webhook processor like so...


    const somedata = JSON.parse(someRequestBody)

    try {
        let status = await client.webhook.process(somedata)

        if (status == false) {
            // Someone tried to lie to you, by using fake webhook data. Ignore it
        }

        if (status == true) {
            // The data was true, and an event has been emited
        }
        
    } catch (error){
        // There was actually a problem with the API, not your webhook message. Perhaps try again later.
    }

SMS

Sending SMS messages is quite simple.

Just call client.sms.send()

For example

    const reply = await client.sms.send({
        phones: ['+237677683958', '+237682477786', '+237676318634'], // Array of phone numbers
        msg: "Dear team, let's begin." // ASCII characters of text.
    })
    console.log(`API server said:\n`, reply)

NOTE:

The phone numbers should be formatted according to international standards.
Before you send SMS, top-up your SMS balance from the partner portal.
An SMS is allowed up to 160 characters. Sending an SMS with more characters, would have you billed accordingly. For example, 320 characters would be two (2) messages. Check the response of the API server to know how you were billed.

Proudly created, and maintained by HolyCorn Software.