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 🙏

© 2026 – Pkg Stats / Ryan Hefner

moosyl-sdk

v1.0.12

Published

integrating payment solutions with Mauritania's popular banking apps

Readme

Moosyl JavaScript SDK

npm version

The Moosyl JavaScript SDK helps you integrate payment solutions with Mauritania's popular banking apps—such as Bankily, Sedad, and Masrivi—in Node.js or the browser. Use it to fetch available payment methods, payment request details, and process payments via the Moosyl API.


Features

  • Payment methods: Fetch available payment methods (including testing mode).
  • Payment request: Get payment request details by transaction ID.
  • Pay: Process payments (e.g. Bankily).
  • Checkout session: Create a hosted checkout session from your backend.
  • Webhook verification: Verify webhook signatures (HMAC-SHA256) like Stripe.
  • Lightweight: No UI; use your own front end or backend flows.
  • ESM: Native ES modules (import).

Getting Started

Installation

Install the package:

npm install moosyl

Create a Moosyl instance

Create a single client with your publishable API key. All operations use this instance:

import { Moosyl, PaymentMethodTitles } from "moosyl";

const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");

Usage

All functionality is available on the Moosyl instance: moosyl.getPaymentMethods(), moosyl.getPaymentRequest(), moosyl.pay(), moosyl.createCheckoutSession().

Fetch payment methods

Get the list of payment methods (e.g. to show options to the user):

import { Moosyl, PaymentMethodTitles } from "moosyl";

const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
const methods = await moosyl.getPaymentMethods(true); // true = testing mode

methods.forEach((m) => {
  const title = PaymentMethodTitles[m.method] ?? m.method;
  console.log(title, m.type, m.id);
  // Bankily/Sedad/etc. may expose m.bPayNumber or m.merchantCode
});

Fetch payment request details

Get details for a given transaction (after creating a payment request from your backend):

import { Moosyl } from "moosyl";

const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");
const request = await moosyl.getPaymentRequest("TRANSACTION_ID");

console.log(request.id, request.amount, request.phoneNumber);

Create a payment request (backend)

Payment requests are created on your backend with your secret API key. The SDK does not create them; it only fetches payment methods and payment request details. Example with cURL:

curl -X POST https://api.moosyl.com/payment-request \
  -H "Authorization: YOUR_SECRET_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "phoneNumber": "+22212345678",
    "transactionId": "your-unique-transaction-id",
    "amount": 5000
  }'

Once created, use the returned transactionId with moosyl.getPaymentRequest() and your payment flow.

Create checkout session (backend only)

This endpoint requires your secret API key and must be called from your backend only. Do not expose your secret key in frontend code.

import { Moosyl } from "moosyl";

const moosyl = new Moosyl("YOUR_SECRET_API_KEY");

const response = await moosyl.createCheckoutSession({
  paymentRequestId: "123e4567-e89b-12d3-a456-426614174000",
  transactionId: "your-unique-transaction-id",
  amount: 5000,
  phoneNumber: "+22212345678",
  successUrl: "https://example.com/success",
  cancelUrl: "https://example.com/cancel",
  expiresInMinutes: 5,
});

console.log(response.data.id);
console.log(response.checkoutUrl);

Equivalent cURL:

curl https://api.moosyl.com/checkout-session \
  --request POST \
  --header 'Authorization: YOUR_SECRET_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "paymentRequestId": "",
  "transactionId": "",
  "amount": 0,
  "phoneNumber": "",
  "successUrl": "",
  "cancelUrl": "",
  "expiresInMinutes": 5
}'

Process payment

For payment methods (e.g. Bankily):

import { Moosyl } from "moosyl";

const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");

await moosyl.pay(
  "TRANSACTION_ID",
  "+22212345678",
  "PASSCODE",
  "PAYMENT_METHOD_ID", // configuration ID from getPaymentMethods()
);

Verify webhooks

Use the raw request body (before JSON parsing) and the x-webhook-signature header. Requires your webhook secret (server-side only). constructWebhookEvent returns a type-safe { event, data } so data is narrowed by event.

import { Moosyl, WebhookSignatureError } from "moosyl";

const moosyl = new Moosyl("YOUR_PUBLISHABLE_API_KEY");

app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => {
  const signature = req.headers["x-webhook-signature"];
  const rawBody = req.body;

  try {
    const { event, data } = moosyl.constructWebhookEvent(
      rawBody,
      signature,
      process.env.WEBHOOK_SECRET,
    );
    switch (event) {
      case "payment-created":
      case "payment-updated":
        handlePayment(data);
        break;
      case "payment-request-created":
      case "payment-request-updated":
        handlePaymentRequest(data);
        break;
    }
    res.json({ received: true });
  } catch (e) {
    if (e instanceof WebhookSignatureError) {
      return res.status(401).json({ error: "Invalid signature" });
    }
    throw e;
  }
});

To only verify without parsing: moosyl.verifyWebhookSignature(rawBody, signature, secret) returns true or false.


Configuration

  • API key: Use your publishable API key when creating new Moosyl(apiKey). Get keys at moosyl.com.
  • Secret API key: createCheckoutSession() uses the key passed to new Moosyl(apiKey). For this method, initialize Moosyl with your secret key and run only on trusted backend infrastructure.
  • Webhook secret: Use your webhook signing secret with moosyl.constructWebhookEvent() / moosyl.verifyWebhookSignature(); keep it server-side only.
  • Testing mode: Pass true to moosyl.getPaymentMethods(true) for test configuration.

Documentation

For more guides and API details, see docs.moosyl.com.


Contributing

  1. Fork this repository.
  2. Create a feature branch (git checkout -b feature-name).
  3. Commit your changes (git commit -m 'Add feature').
  4. Push to your branch (git push origin feature-name).
  5. Open a pull request.

Support


License

This project is licensed under the ISC License. See the LICENSE file for details.


Integrate Moosyl into your Node or web app.
Get started at moosyl.com.