Skip to content

Commit

Permalink
add web authorization method
Browse files Browse the repository at this point in the history
  • Loading branch information
ojengwa committed Feb 24, 2016
1 parent 0912d77 commit d60f000
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -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
```
5 changes: 3 additions & 2 deletions README.rst
Expand Up @@ -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/
Expand Down
27 changes: 21 additions & 6 deletions paystack/resource.py
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion paystack/version.py
@@ -1 +1 @@
VERSION = '1.3.5'
VERSION = '1.3.6'

0 comments on commit d60f000

Please sign in to comment.