API Reference

This guide will help you understand how momofy can be used.

Using the Momofy Node JS Software Development Kit (SDK)

Momofy Node JS SDK

Officially supported momofy package for node Js applications.

Some useful resources

Goto the Dashboard

Installation

To install this package run

  npm install  @momofy/sdk
  yarn add  @momofy/sdk

Environment Variables

To be able to perform transactions using this SDK you need to get your API Secret Key from your Momofy Dashboard.

eg. secret_test_01HPH70VG02DAYJ1N70NP4QWKV

Envronment Types

ExampleDescription
Testsecret_test_01HPH70VG02DAYJ1N70NP4QWKVUse test enviroment during project development
Productionsecret_prod_01HPH70VG02DAYJ1N70NP4QWKVUse production enviroment for live application

Usage

Initiate Transaction

Request a checkout url to received payment from customers

import { Momofy } from "@momofy/sdk"

const momofy = new Momofy("secret_test_01HPH70VG02DAYJ1N70NP4QWKV");

let response = await momofy.transaction.checkout({
    amount: 30,
    redirectUrl: "https://example.com/verify-transaction",
    referenceCode: "",
    transactionNote: "Payment of bills",
  });

Request Response

    {
     success: true,
     message: 'Checkout created successful',
     result: {
       transaction_ref: '00d67012-90b9-45c1-be9f-06ec8d813ddb',
       checkout_url: 'https://app.momofy.com/checkout/c4e1a0e0-80bd-4925-b7bd-c36e48979f13'
    },
    meta: {}
   }

options

ParamsExample valuesDescription
amount20 or "30"Amount to be requested from customer
redirectUrlhttps://example.com/verify-transactionA url to be redirected to after successful / failed transaction
reference_codeunique uuidv4 stringReference code ( will be auto generated when not provided )
transaction_noteMessage for transactionNote to display to user when requesting for payment.

Request Payment

Request payment from your customers

import { Momofy } from "@momofy/sdk"

const momofy = new Momofy("secret_test_01HPH70VG02DAYJ1N70NP4QWKV");

let response = await momofy.transaction.requestPayment({
    amount: 30,
    channel: "mobile_money",
    currency: "GHS",
    customer: {
      email: "[email protected]",
      name: "Test User",
      phone_number: "024777777",
    },
    provider: "MTN",
    reference_code: "",
    transaction_note: "Payment for DSTV Bill",
  });

Request Response

    {
     success: true,
     message: 'Transaction has been initiated',
     result: { reference_code: 'dee67adb-bcfc-416b-b08b-b7dbb211a210' },
     meta: {}
   }

options

ParamsExample valuesDescription
amount20 or "30"Amount to be requested from customer
channelmobile_moneyOnly mobile money channel is currently being supported
currencyGHSThe supported currency from the provider
customerCustomer ObjectThe customer information
providerMTN or VODAFONENetwork Provider code ( get this from the docs )
reference_codeunique uuidv4 stringReference code ( will be auto generated when not provided )
transaction_noteMessage for transactionNote to display to user when requesting for payment.

Customer Object

ParamsRequiredDescription
nameYesName of the customer
phone_numberYesMomo number of customer to be charged.
emailYesEmail of the customer (if not available provide organisation email)

Verify Transaction Status

Verify your transaction by providing the transaction ref ID.

import { Momofy } from "@momofy/sdk"

const momofy = new Momofy("secret_test_01HPH70VG02DAYJ1N70NP4QWKV");

let response = await momofy.transaction.verify("dee67adb-bcfc-416b-b08b-b7dbb211a210");

Verification Response

{
  success: true,
  message: 'Transaction retrieved',
  result: {
    id: 17,
    channel: 'mobile_money',
    message: 'Payment for DSTV Bill',
    currency: 'GHS',
    payment_phone: '024777777',
    reference_code: 'a8735819-dbdd-4bf8-a075-8236660ba9d7',
    gateway_status: 'waiting',
    meta_data: null,
    amount: 30,
    status: 'initiated',
    environment: 'test',
  },
  meta: {}
}

Transaction Status Type

StatusDescription
initiatedTransaction has been initiated
pendingTransaction has been successfully sent to the provider
successTransaction was process successfully
failedTransaction has failed means (may be the user declined the payment request or something bad has happened )

Feedback

If you have any feedback, please feel free to Submit an Issue