Skip to main content

Paynow Python SDK

Project description

Paynow Zimbabwe Python SDK

Python SDK for Paynow Zimbabwe's API

Prerequisites

This library has a set of prerequisites that must be met for it to work

  1. requests

Installation

Install the library using pip

$ pip install paynow

and import the Paynow class into your project

	from paynow import Paynow

	# Do stuff

Usage example

Create an instance of the Paynow class optionally setting the result and return url(s)

paynow = Paynow(
	'INTEGRATION_ID',
	'INTEGRATION_KEY',
	'https://example.com/paynow/return', # Return url
        'https://example.com/paynow/result/update' # Result url 

	)

Create a new payment passing in the reference for that payment (e.g invoice id, or anything that you can use to identify the transaction and the user's email address

payment = paynow.create_payment('Order #100', 'test@example.com')

You can then start adding items to the payment

# Passing in the name of the item and the price of the item
payment.add('Bananas', 2.50)
payment.add('Apples', 3.40)

When you're finally ready to send your payment to Paynow, you can use the send method in the paynow object.

# Save the response from paynow in a variable
response = paynow.send(payment)

The response from Paynow will b have some useful information like whether the request was successful or not. If it was, for example, it contains the url to redirect the user so they can make the payment. You can view the full list of data contained in the response in our wiki

If request was successful, you should consider saving the poll url sent from Paynow in the database

if response.success:

    # Get the link to redirect the user to, then use it as you see fit
	link = response.redirect_url

	# Get the poll url (used to check the status of a transaction). You might want to save this in your DB
	pollUrl = response.poll_url

Mobile Transactions

If you want to send an express (mobile) checkout request instead, the only thing that differs is the last step. You make a call to the send_mobile in the paynow object instead of the send method.

The send_mobile method unlike the send method takes in two additional arguments i.e The phone number to send the payment request to and the mobile money method to use for the request. Note that currently only ecocash is supported

# Save the response from paynow in a variable
response = paynow.send_mobile(payment, '0777777777', 'ecocash')

The response object is almost identical to the one you get if you send a normal request. With a few differences, firstly, you don't get a url to redirect to. Instead you instructions (which ideally should be shown to the user instructing them how to make payment on their mobile phone)

if(response.success) :
	# Get the poll url (used to check the status of a transaction). You might want to save this in your DB
    poll_url = response.poll_url

    instructions = response.instructions

Checking transaction status

The SDK exposes a handy method that you can use to check the status of a transaction. Once you have instantiated the Paynow class.

# Check the status of the transaction with the specified poll url
# Now you see why you need to save that url ;-)
status = paynow.check_transaction_status(poll_url)

if status.paid :
	# Yay! Transaction was paid for. Update transaction?
else :
	# Handle that

Full Usage Example

from paynow import Paynow


paynow = Paynow(
	'INTEGRATION_ID',
	'INTEGRATION_KEY',
	'https://example.com/paynow/return', # Return url
        'https://example.com/paynow/result/update' # Result url 
	)

payment = paynow.create_payment('Order', 'test@example.com')

payment.add('Payment for stuff', 1)

response = paynow.send_mobile(payment, '0777832735', 'ecocash')


if(response.success):
    poll_url = response.poll_url

    print("Poll Url: ", poll_url)

    status = paynow.check_transaction_status(poll_url)

    time.sleep(30)

    print("Payment Status: ", status.status)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paynow-1.0.8.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

paynow-1.0.8-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file paynow-1.0.8.tar.gz.

File metadata

  • Download URL: paynow-1.0.8.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for paynow-1.0.8.tar.gz
Algorithm Hash digest
SHA256 d3a7d4e01e53d59075e915fe831d3cba255da112a284edafbbd674de099ebd6d
MD5 cc71142c98e8b16c5b6ef15ecb2357d7
BLAKE2b-256 a492f4d160f755a53049932827377d0f7aa974e54d1fa6ef4d9cd6cee3177ffc

See more details on using hashes here.

File details

Details for the file paynow-1.0.8-py2.py3-none-any.whl.

File metadata

  • Download URL: paynow-1.0.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for paynow-1.0.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1e925deabbdc32fe16c93c031f16e2f804bb19934f60830e3043805fa8634c83
MD5 ad7c9a4b60429165d1b3375c48aaf2c4
BLAKE2b-256 eaff566d37ea83857b8e3c6268d0a3b6966993b5e18ea2a9bdb76ab69830f569

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page