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

@tecafrik/africa-payment-sdk

v1.1.2

Published

A single SDK to integrate all african payment providers seamlessly

Downloads

105

Readme

Synopsis

Payment methods in Africa are fragmented and payment providers are even more fragmented, but your software does not have to be. This SDK aims to provide a unified API to talk to any payment provider in the continent so you can focus on making your product better.

You will still need an account with any providers you intend to use, the SDK only acts as a bridge to the provider.

Quick Start

  • Install the SDK from npm
npm i @tecafrik/africa-payment-sdk
  • Instantiate the SDK with one of the providers
import AfricaPayments, {
  PaydunyaPaymentProvider,
} from "@tecafrik/africa-payment-sdk";

const africaPayments = new AfricaPayments(
  new PaydunyaPaymentProvider({
    masterKey: "<<YOUR_PAYDUNYA_MASTER_KEY>>",
    privateKey: "<<YOUR_PAYDUNYA_PRIVATE_KEY>>",
    publicKey: "<<YOUR_PAYDUNYA_PUBLIC_KEY>>",
    token: "<<YOUR_PAYDUNYA_TOKEN>>",
    mode: "live",
    store: {
      name: "Electronics Shop",
    },
  })
);
  • Checkout so your users can pay
const checkoutResult = await africaPayments.checkout({
  paymentMethod: PaymentMethod.WAVE,
  amount: 500,
  description: "Achat de téléphone",
  currency: Currency.XOF,
  customer: {
    firstName: "Mamadou",
    lastName: "Diop",
    phoneNumber: "+221771234567",
  },
  transactionId: "12314214",
  metadata: {
    orderId: "321421",
  },
});

Depending on the provider, the checkoutResult may contain a redirectUrl that you will need to redirect the user to in order to finish the payment

  • Handle webhooks and listen for events
// body comes from the raw request body (buffer or string) sent by the provider to your webhook endpoint
// you will need to configure that endpoint in the provider's interface most likely
africaPayments.handleWebhook(body);
africaPayments.on(PaymentEventType.PAYMENT_SUCCESSFUL, async (event) => {
  const orderId = event.metadata?.orderId;
  if (!orderId) {
    return;
  }
  await Order.update(
    {
      id: orderId,
    },
    {
      status: "PAID",
      transactionReference: event.transactionReference,
    }
  );
});

Test with the bogus payment provider

In a testing environment, you do not want to make actual payments. Not all payment providers provide a sandbox mode and even when they do, not all of the features in the sandbox are testable. For integration tests you most likely don't want to involve external APIs, even sandbox ones.

That's why we made a BogusPaymentProvider that fakes all the checkout methods and webhook handling logic. It follows simple rules:

  • For mobile money checkout, any phone number that ends with 13 will trigger a payment failure event and redirect to the failure url
  • For credit card checkout, any card number that ends with 13 will trigger a payment failure event and redirect to the failure url
  • For redirect checkout, any email that ends with @failure.com will trigger a payment failure event and redirect to the failure url
  • Anything else will trigger a success event and redirect to the success url

This is when the instantEvents config is set to true. You can however opt into a more manual success/failure trigger mechanism by calling handleWebhook with various body payloads. The schema for the body can be found under the typescript type BogusPaymentProviderWebhookBody.

API Reference

Coming soon. The project is written in TypeScript so feel free to browse the API via your IDE's intellisense features.