Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result_url and return_url #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Paynow Zimbabwe Python SDK

Python SDK for Paynow Zimbabwe's API
- Python SDK for Paynow Zimbabwe's API

# Prerequisites

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

1. requests

# Installation

Install the library using pip
- Install the library using pip

```sh
$ pip install paynow
$ pip3 install paynow
```

and import the Paynow class into your project
- import the Paynow class into your project

```python
from paynow import Paynow
Expand All @@ -34,8 +34,8 @@ Create an instance of the Paynow class optionally setting the result and return
paynow = Paynow(
'INTEGRATION_ID',
'INTEGRATION_KEY',
'http://google.com',
'http://google.com'
'http://yourweb.com/returnurl', # merchant return url
'http://yourweb.com/results', # merchant result url
)
```

Expand All @@ -60,7 +60,7 @@ When you're finally ready to send your payment to Paynow, you can use the `send`
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
The response from Paynow will be having 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

Expand Down Expand Up @@ -118,12 +118,11 @@ else :
```python
from paynow import Paynow


paynow = Paynow(
'INTEGRATION_ID',
'INTEGRATION_KEY',
'http://google.com',
'http://google.com'
'http://yourweb.com/returnurl', # merchant return url
'http://yourweb.com/results', # merchant result url
)

payment = paynow.create_payment('Order', 'test@example.com')
Expand Down
24 changes: 20 additions & 4 deletions paynow/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,30 @@ class InitResponse:
"""

def __init__(self, data):
# TODO return dict of kwargs

self.status = data['status']
self.success = data['status'].lower() != 'error'
self.has_redirect = 'browserurl' in data
self.hash = 'hash' in data

if not self.success:
self.error = data['error']
return

self.poll_url = data['pollurl']

if not self.success:
self.error = data['error']

if self.has_redirect:
self.redirect_url = data['browserurl']

if 'instructions' in data:
self.instruction = data['instructions']

def __repr__(self):
'''Print friendly message, especially on errors'''

return data['status']


class Payment:
"""Helper class for building up a transaction before sending it off to Paynow
Expand Down Expand Up @@ -191,6 +196,11 @@ def info(self):
out += (item[0] + ", ")
return out

def __repr__(self):
# TODO: how woll this be presented when printed
# information is too vague
pass


class Paynow:
"""Contains helper methods to interact with the Paynow API
Expand Down Expand Up @@ -238,8 +248,14 @@ class Paynow:
"""
str: Merchant's result url
"""
# is it necessary to have return and results url ?
# why not just combine these two; kill two birds with one stone
# Leave the autonomy to the merchant ie merchant knows what to do with
# a successful payment else its an error, merchant will debug, paynow
# provides information about error

def __init__(self, integration_id, integration_key, return_url, result_url):
def __init__(self, integration_id, integration_key,
return_url='http://', result_url='http://):
self.integration_id = integration_id
self.integration_key = integration_key
self.return_url = return_url
Expand Down