Skip to main content

django-nmb

A Django application which assist on integration of your web application with NMB BANK Merchant payment gateway with easy step. docs

Prerequisites

  • Python 3.6+
  • Pip or Pipenv

It will Cover

  • Generate sessionID to initiate payment
  • Cover Hosted Checkout and Hosted Session on "example" module found on github here
  • Direct payment
  • Batch payment

Installation

This package is available in Python Package Index and can be installed using pip or pipenv

  1. Run pip install django-nmb
  2. Add nmb to INSTALLED_APPS
  3. Run pip install requests

Usage

Register account on NMB Ecommerce merchant by visit on NMB Branch near you and your will get the following credentials for testing

  1. MERCHANT ID
  2. MERCHANT API PASSWORD

Open "settings.py" on your project, set the following variables

  1. MERCHANT_ID = "your merchant id"
  2. API_USERNAME = "merchant.merchant_id"
  3. API_PASSWORD = "your api password"
  4. API_ADDRESS = "https://test-nmbbank.mtf.gateway.mastercard.com/api/rest/version/60/merchant/{merchant_id}/session"

After setting above,Then on your views.py file.

from django.conf import settings
from nmb.payment import APIContext, APIMethodType, APIRequest

def get_sessionID(request):

	merchant_id = settings.MERCHANT_ID
	api_password = settings.API_PASSWORD
	api_username = settings.API_USERNAME
	address = settings.API_ADDRESS

	# Create Context with API to request a Session ID
	api_context = APIContext()

	# API USERNAME
	api_context.api_username = api_username

	# API Password
	api_context.api_password = api_password

	# API address
	api_context.address = address

	# Method type (can be GET/POST)
	api_context.method_type = APIMethodType.POST

	# Define your purchaces parameters
	parameters = {
		'apiOperation': 'CREATE_CHECKOUT_SESSION',
		'interaction': {
			'operation':'PURCHASE',
		},
		'order': {
			'id': "2",
			'amount': 100.0,
			'currency': 'TZS',
			'reference': '99676542',
			'description': 'A pair of shoes'
		}
	}

	# add parameters on request session
	api_context.parameters = parameters

	#Do the API call and put result in a response packet
	api_request = APIRequest(api_context)

	result = None

	try:
		result = api_request.execute()
	except Exception as e:
		print('Call Failed:', e)

	if result is None:
		raise Exception('Call failed to get result. Please check.')

	print(result.headers)
	print(result.body)
	
	return JsonResponse(data=result.body, safe=False)

sample response

{"merchant": "993755100084", "result": "SUCCESS", "session": {"id": "SESSION0002323910607J44443070E2", "updateStatus": "SUCCESS", "version": "f7f4198201"}, "successIndicator": "6d7323cd979444f2"}

For full example on how to integrate please visit the github repo on example folder you will find all source codes here

Give it a star

If you found this repository useful, give it a star so as the whole community of Tanzania developers can get to know it.

Bug bounty?

If you encounter issue with the usage of the package, feel free raise an issue so as we can fix it as soon as possible(ASAP).

Pull Requests

If you have something to add I welcome pull requests on improvement , you're helpful contribution will be merged as soon as possible

Metadata

Release files for django-nmb 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-nmb 0.0.2
File Size Uploaded
django-nmb-0.0.2.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-nmb 0.0.2
File Interpreter ABI Platform
django_nmb-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / django-nmb-0.0.2.tar.gz

Download URL django-nmb-0.0.2.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ec4e11109a81a3437544a060113366d82569bb8156035c7ace4216c62d35990
BLAKE2b-256 checksum
How to use checksums
1c162d50de72ef214d5d6b958c7f2f620e3fdc19a2566b4710bd4a8ae1596257
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.0

Release files / django_nmb-0.0.2-py3-none-any.whl

Download URL django_nmb-0.0.2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8180724f52aec2c96d784bc6fceef2cf51bfec3ae8c242b25c1255a073a9ece8
BLAKE2b-256 checksum
How to use checksums
bf02acd17cdf7bc57e7707001dbd8d63a25c4bf2eb53f74746904d5b48e6c8dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.0

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page