diff --git a/README.md b/README.md index c247712..193d58a 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ) ``` @@ -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 @@ -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') diff --git a/paynow/model.py b/paynow/model.py index 8c66f29..8a082d2 100644 --- a/paynow/model.py +++ b/paynow/model.py @@ -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 @@ -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 @@ -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