From d60f000e74cbb8e898ef9119b7f47606e2372c57 Mon Sep 17 00:00:00 2001 From: Bernard Ojengwa Date: Wed, 24 Feb 2016 02:29:02 +0100 Subject: [PATCH] add web authorization method --- README.md | 5 +++-- README.rst | 5 +++-- paystack/resource.py | 27 +++++++++++++++++++++------ paystack/version.py | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index ff22f0f..dc68957 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,9 @@ def main(): test_email, plan) print(response) - verify = client.verify() + client.authorize() # Will open a browser window for client to enter card details + verify = client.verify() # Verify client credentials print(verify) - print(client.charge()) + print(client.charge()) # Charge an already exsiting client ``` diff --git a/README.rst b/README.rst index 741edac..cac8639 100644 --- a/README.rst +++ b/README.rst @@ -111,9 +111,10 @@ Example test_email, plan) print(response) - verify = client.verify() + client.authorize() # Will open a browser window for client to enter card details + verify = client.verify() # Verify client credentials print(verify) - print(client.charge()) + print(client.charge()) # Charge an already exsiting client .. _nose: http://nose2.readthedocs.org/en/latest/ diff --git a/paystack/resource.py b/paystack/resource.py index 7d6287f..ca35331 100644 --- a/paystack/resource.py +++ b/paystack/resource.py @@ -32,6 +32,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ +import webbrowser + from paystack.client import RequestsClient from paystack import error from paystack import util @@ -184,13 +186,13 @@ def verify(self, ref=None): # pragma no cover return response - def charge(self, authorization_code=None, amount=None, + def charge(self, auth_code=None, amount=None, email=None, reference=None): # pragma no cover endpoint = '/charge_authorization' method = 'POST' - if not authorization_code and not self.authorization_code: + if not auth_code and not self.authorization_code: raise error.ValidationError('This transaction object does not' ' have an authorization code.You must' ' provide an authorization code for' @@ -205,7 +207,7 @@ def charge(self, authorization_code=None, amount=None, authorization_code = ( lambda auth_code: auth_code if auth_code else self - .authorization_code)(authorization_code) + .authorization_code)(auth_code) email = ( lambda email: email if email else self.email)(email) @@ -233,9 +235,22 @@ def charge(self, authorization_code=None, amount=None, return response - @property - def payment_url(self): - return(self.authorization_url) + def authorize(self, auth_url=None): + if not auth_url and not self.authorization_url: + raise error.ValidationError('This transaction object does not' + ' have an authorization url.You must' + ' provide an authorization url or' + 'for call the `initialize` method' + ' this transaction first.') + + authorization_url = ( + lambda auth_url: auth_url if auth_url else self + .authorization_url)(auth_url) + + try: + webbrowser.open_new_tab(authorization_url) + except webbrowser.Error as e: + raise e class PlanResource(BaseAPIResource): # pragma: no cover diff --git a/paystack/version.py b/paystack/version.py index 6045236..c1d1d6c 100644 --- a/paystack/version.py +++ b/paystack/version.py @@ -1 +1 @@ -VERSION = '1.3.5' +VERSION = '1.3.6'