From 18b1566a33c8cc3c9250e2c7470c757366dd88ea Mon Sep 17 00:00:00 2001 From: Confi Yobo Date: Wed, 28 Aug 2019 23:58:11 +0100 Subject: [PATCH] Add banks list --- build/lib/paystackpy/__init__.py | 6 -- build/lib/paystackpy/apiConfig.py | 72 ------------------- build/lib/paystackpy/customers.py | 63 ----------------- build/lib/paystackpy/errors.py | 26 ------- build/lib/paystackpy/misc.py | 7 -- build/lib/paystackpy/plans.py | 81 --------------------- build/lib/paystackpy/transactions.py | 102 --------------------------- build/lib/paystackpy/transfers.py | 74 ------------------- build/lib/paystackpy/utils.py | 37 ---------- build/lib/paystackpy/version.py | 5 -- paystackpy/transactions.py | 4 +- paystackpy/version.py | 2 +- 12 files changed, 4 insertions(+), 475 deletions(-) delete mode 100644 build/lib/paystackpy/__init__.py delete mode 100644 build/lib/paystackpy/apiConfig.py delete mode 100644 build/lib/paystackpy/customers.py delete mode 100644 build/lib/paystackpy/errors.py delete mode 100644 build/lib/paystackpy/misc.py delete mode 100644 build/lib/paystackpy/plans.py delete mode 100644 build/lib/paystackpy/transactions.py delete mode 100644 build/lib/paystackpy/transfers.py delete mode 100644 build/lib/paystackpy/utils.py delete mode 100644 build/lib/paystackpy/version.py diff --git a/build/lib/paystackpy/__init__.py b/build/lib/paystackpy/__init__.py deleted file mode 100644 index 9a5e04d..0000000 --- a/build/lib/paystackpy/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -from paystackpy.customers import Customer -from paystackpy.transactions import Transaction -from paystackpy.plans import Plan -from paystackpy.transfers import Transfer - -name = "paystackpy" diff --git a/build/lib/paystackpy/apiConfig.py b/build/lib/paystackpy/apiConfig.py deleted file mode 100644 index eff3643..0000000 --- a/build/lib/paystackpy/apiConfig.py +++ /dev/null @@ -1,72 +0,0 @@ -import os - -import requests -import simplejson as json - -from paystackpy.errors import * -import paystackpy.version as version - - -class APIConfig: - """ - API configuration for paystackpy API wrapper - """ - - _CONTENT_TYPE = "application/json" - _API_END_POINT = "https://api.paystack.co" - - def __init__(self, authorization_key=None): - if authorization_key: - self._PAYSTACK_AUTHORIZATION_KEY = authorization_key - else: - self._PAYSTACK_AUTHORIZATION_KEY = os.getenv('PAYSTACK_AUTHORIZATION_KEY', None) - - if not self._PAYSTACK_AUTHORIZATION_KEY: - raise MissingAuthKeyError("Missing paystack Authorization key") - - self.request_headers = { - "Authorization": "Bearer {0}".format(self._PAYSTACK_AUTHORIZATION_KEY), - "Content-Type": "application/json", - "user-agent": "PaystackPy - {0}".format(version.__version__) - } - - def _url(self, path): - return self._API_END_POINT + path - - def _parse_json(self, response_obj): - parsed_response = response_obj.json() - - status = parsed_response.get('status', None) - message = parsed_response.get('message', None) - data = parsed_response.get('data', None) - return response_obj.status_code, status, message, data - - def _handle_request(self, method, url, data=None): - - """ - Generic function to handle all API url calls - Returns a python tuple of status code, status(bool), message, data - """ - method_map = { - 'GET': requests.get, - 'POST': requests.post, - 'PUT': requests.put, - 'DELETE': requests.delete - } - - payload = json.dumps(data) if data else data - request = method_map.get(method) - - if not request: - raise InvalidMethodError("Request method not recognised or implemented") - - response = request(url, headers=self.request_headers, data=payload, verify=True) - if response.status_code == 404: - return response.status_code, False, "The object request cannot be found", None - - if response.status_code in [200, 201]: - return self._parse_json(response) - else: - body = response.json() - return {"status_code": response.status_code, "status": body.get('status'), "message": body.get('message'), - "errors": body.get('errors')} diff --git a/build/lib/paystackpy/customers.py b/build/lib/paystackpy/customers.py deleted file mode 100644 index ff1a204..0000000 --- a/build/lib/paystackpy/customers.py +++ /dev/null @@ -1,63 +0,0 @@ -from paystackpy.apiConfig import APIConfig - - -class Customer(APIConfig): - def create(self, email, first_name=None, last_name=None, phone=None): - """ - Creates a new paystack customer account - - args: - email -- Customer's email address - first_name-- Customer's first name (Optional) - last_name-- Customer's last name (Optional) - phone -- optional - """ - url = self._url("/customer/") - payload = { - "first_name": first_name, - "last_name": last_name, - "email": email, - "phone": phone - } - return self._handle_request('POST', url, payload) - - def update(self, user_id, email, first_name=None, last_name=None, phone=None): - """ - Update a customer account given the user id - - args: - user_id -- id of the customer - email -- Customer's email address - first_name-- Customer's first name (Optional) - last_name-- Customer's last name (Optional) - phone -- optional - """ - url = self._url("/customer/{}/".format(user_id)) - payload = { - "first_name": first_name, - "last_name": last_name, - "email": email, - "phone": phone - } - return self._handle_request('PUT', url, payload) - - def getall(self, pagination=10): - """ - Gets all the customers we have at paystack in steps of (default) 50 records per page. - We can provide an optional pagination to indicate how many customer records we want to fetch per time - - args: - pagination -- Count of data to return per call - """ - url = self._url("/customer/?perPage=" + str(pagination)) - return self._handle_request('GET', url) - - def getone(self, user_id): - """ - Gets the customer with the given user id - - args: - user_id -- The customer's user id - """ - url = self._url("/customer/{}/".format(user_id)) - return self._handle_request('GET', url) diff --git a/build/lib/paystackpy/errors.py b/build/lib/paystackpy/errors.py deleted file mode 100644 index 3e6cb03..0000000 --- a/build/lib/paystackpy/errors.py +++ /dev/null @@ -1,26 +0,0 @@ -class PaystackPyError(Exception): - """ - Python Paystack Error - """ - pass - - -class MissingAuthKeyError(PaystackPyError): - """ - We can't find the authentication key - """ - pass - - -class InvalidMethodError(PaystackPyError): - """ - Invalid or unrecoginised/unimplemented HTTP request method - """ - pass - - -class InvalidDataError(PaystackPyError): - """ - Invalid input recognised. Saves unecessary trip to server - """ - pass diff --git a/build/lib/paystackpy/misc.py b/build/lib/paystackpy/misc.py deleted file mode 100644 index 9524e6e..0000000 --- a/build/lib/paystackpy/misc.py +++ /dev/null @@ -1,7 +0,0 @@ -from paystackpy.apiConfig import APIConfig - - -class Misc(APIConfig): - def allbanks(self, perpage=50, page=1): - url = self._url("/bank?perPage={}&page={}".format(perpage, page)) - return self._handle_request('GET', url) diff --git a/build/lib/paystackpy/plans.py b/build/lib/paystackpy/plans.py deleted file mode 100644 index 936396b..0000000 --- a/build/lib/paystackpy/plans.py +++ /dev/null @@ -1,81 +0,0 @@ -import paystackpy.utils as utils -from paystackpy.apiConfig import APIConfig - - -class Plan(APIConfig): - def create(self, name, amount, interval, description=None, \ - send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, - currency=None): - """ - Creates a new plan. Returns the plan details created - - args: - name -- Name of the plan to create - amount -- Amount to attach to this plan - interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually' - description -- Plan Description (optional) - - """ - interval = utils.validate_interval(interval) - amount = utils.validate_amount(amount) - - url = self._url("/plan/") - payload = { - "name": name, - "amount": amount, - "interval": interval, - "currency": currency, - "send_sms": send_sms, - "description": description, - "hosted_page": hosted_page, - "send_invoices": send_invoices, - "hosted_page_url": hosted_page_url, - "hosted_page_summary": hosted_page_summary, - } - return self._handle_request('POST', url, payload) - - def update(self, plan_id, name, amount, interval, description=None, \ - send_invoices=False, send_sms=False, hosted_page=False, hosted_page_url=None, hosted_page_summary=None, - currency=None): - """ - Updates an existing plan given a plan id. Returns the plan details updated. - - args: - plan_id -- Plan Id to update - name -- New plan name - amount -- New Amount to attach to this plan - interval -- 'hourly', 'daily', 'weekly', 'monthly', 'annually' - description -- Plan Description (optional) - """ - interval = utils.validate_interval(interval) - amount = utils.validate_amount(amount) - - url = self._url("/plan/{}/".format(plan_id)) - payload = { - "name": name, - "amount": amount, - "interval": interval, - "currency": currency, - "send_sms": send_sms, - "description": description, - "hosted_page": hosted_page, - "send_invoices": send_invoices, - "hosted_page_url": hosted_page_url, - "hosted_page_summary": hosted_page_summary, - } - return self._handle_request('PUT', url, payload) - - def getall(self, pagination=10): - """ - Gets all plans - """ - url = self._url("/plan/?perPage=" + str(pagination)) - return self._handle_request('GET', url) - - def getone(self, plan_id): - """ - Gets one plan with the given plan id - Requires: plan_id - """ - url = self._url("/plan/{}/".format(plan_id)) - return self._handle_request('GET', url) diff --git a/build/lib/paystackpy/transactions.py b/build/lib/paystackpy/transactions.py deleted file mode 100644 index 652e38d..0000000 --- a/build/lib/paystackpy/transactions.py +++ /dev/null @@ -1,102 +0,0 @@ -import paystackpy.utils as utils -from paystackpy.apiConfig import APIConfig -from paystackpy.errors import InvalidDataError - - -class Transaction(APIConfig): - def getall(self, pagination=10): - """ - Gets all your transactions - - args: - pagination -- Count of data to return per call - """ - url = self._url("/transaction/?perPage=" + str(pagination)) - return self._handle_request('GET', url) - - def getone(self, transaction_id): - """ - Gets one customer with the given transaction id - - args: - Transaction_id -- transaction we want to get - """ - url = self._url("/transaction/{}/".format(transaction_id)) - return self._handle_request('GET', url) - - def totals(self): - """ - Gets transaction totals - """ - url = self._url("/transaction/totals/") - return self._handle_request('GET', url) - - def initialize(self, email, amount, plan=None, reference=None, channel=None, metadata=None): - """ - Initialize a transaction and returns the response - - args: - email -- Customer's email address - amount -- Amount to charge - plan -- optional - Reference -- optional - channel -- channel type to use - metadata -- a list if json data objects/dicts - """ - amount = utils.validate_amount(amount) - - if not email: - raise InvalidDataError("Customer's Email is required for initialization") - - url = self._url("/transaction/initialize") - payload = { - "email": email, - "amount": amount, - "reference": reference, - "plan": plan, - "channels": channel, - "metadata": {"custom_fields": metadata} - } - return self._handle_request('POST', url, payload) - - def charge(self, email, auth_code, amount, reference=None): - """ - Charges a customer and returns the response - - args: - auth_code -- Customer's auth code - email -- Customer's email address - amount -- Amount to charge - reference -- optional - """ - amount = utils.validate_amount(amount) - - if not email: - raise InvalidDataError("Customer's Email is required to charge") - - if not auth_code: - raise InvalidDataError("Customer's Auth code is required to charge") - - url = self._url("/transaction/charge_authorization") - payload = { - "authorization_code": auth_code, - "email": email, - "amount": amount, - "reference": reference - } - - return self._handle_request('POST', url, payload) - - def verify(self, reference): - """ - Verifies a transaction using the provided reference number - - args: - reference -- reference of the transaction to verify - """ - - reference = str(reference) - url = self._url("/transaction/verify/{}".format(reference)) - return self._handle_request('GET', url) - - diff --git a/build/lib/paystackpy/transfers.py b/build/lib/paystackpy/transfers.py deleted file mode 100644 index 7f08fb1..0000000 --- a/build/lib/paystackpy/transfers.py +++ /dev/null @@ -1,74 +0,0 @@ -import paystackpy.utils as utils -from paystackpy.apiConfig import APIConfig - - -class Transfer(APIConfig): - def create_transfer_recipient(self, receipt_type='nuban', name=None, metadata=None, account_number=None, - bank_code=None, - currency=None, description=None, authorization_code=None): - url = self._url("/transferrecipient") - payload = { - "receipt_type": receipt_type, - "name": name, - "metadata": metadata, - "account_number": account_number, - "bank_code": bank_code, - "currency": currency, - "description": description, - "authorization_code": authorization_code - } - return self._handle_request('POST', url, payload) - - def get_transfer_recipient(self, perpage=50, page=1): - url = self._url("/transferrecipient?perPage={}&page={}".format(perpage, page)) - - return self._handle_request('GET', url) - - def update_transfer_recipient(self, refcode=None, name=None, email=None): - url = self._url("/transferrecipient/{}".format(refcode)) - payload = { - "name": name, - "email": email - } - return self._handle_request('PUT', url, payload) - - def delete_recipient(self, refcode): - url = self._url("/transferrecipient/{}".format(refcode)) - - return self._handle_request('DELETE', url) - - def initiate(self, source=None, amount=None, currency=None, reason=None, recipient=None): - url = self._url("/transfer") - - amount = utils.validate_amount(amount) - - payload = { - "source": source, - "amount": amount, - "currency": currency, - "reason": reason, - "recipient": recipient, - "reference": utils.reference_gen() - } - - return self._handle_request('POST', url, payload) - - def all_transfers(self, perpage=50, page=1): - url = self._url("/transfer?perPage={}&page={}".format(perpage, page)) - - return self._handle_request('GET', url) - - def get_transfer(self, ref_or_code): - url = self._url("/transfer/{}".format(ref_or_code)) - - return self._handle_request('GET', url) - - def finalize_transfer(self, transfer_code, otp): - url = self._url("/transfer/finalize_transfer") - - payload = { - "otp": otp, - "transfer_code": transfer_code - } - - return self._handle_request('POST', url, payload) diff --git a/build/lib/paystackpy/utils.py b/build/lib/paystackpy/utils.py deleted file mode 100644 index 1391d82..0000000 --- a/build/lib/paystackpy/utils.py +++ /dev/null @@ -1,37 +0,0 @@ -from paystackpy.errors import InvalidDataError -import random -# random.seed(123) - - -def validate_amount(amount): - if not amount: - raise InvalidDataError("Amount to be charged is required") - - if isinstance(amount, int) or isinstance(amount, float): - if amount < 0: - raise InvalidDataError("Invalid amount! Amount must not be a negative number") - return amount - else: - raise InvalidDataError("Amount should be a number or a float data type") - - -def validate_interval(interval): - - interval = interval if interval.lower() in ['hourly', 'daily', 'weekly', 'monthly', 'annually'] else None - if not interval: - raise InvalidDataError("Please provide a valid plan interval") - return interval - - -def reference_gen(): - possibilities = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' - token = "" - token_length = 12 - - for i in range(0, token_length): - math_random = random.random() - if math_random < 1: - math_random = random.uniform(0.1, 0.9) - token += possibilities[round(math_random * len(possibilities))] - - return token diff --git a/build/lib/paystackpy/version.py b/build/lib/paystackpy/version.py deleted file mode 100644 index ad11b80..0000000 --- a/build/lib/paystackpy/version.py +++ /dev/null @@ -1,5 +0,0 @@ -__title__ = 'paystackpy' -__version__ = '0.0.1' -__author__ = 'Confi Yobo' -__license__ = 'MIT' -__copyright__ = 'Copyright 2016. ConfI Yobo' diff --git a/paystackpy/transactions.py b/paystackpy/transactions.py index 652e38d..487cf7e 100644 --- a/paystackpy/transactions.py +++ b/paystackpy/transactions.py @@ -99,4 +99,6 @@ def verify(self, reference): url = self._url("/transaction/verify/{}".format(reference)) return self._handle_request('GET', url) - + def banks(self): + url = self._url("/bank/?perPage=100") + return self._handle_request('GET', url) diff --git a/paystackpy/version.py b/paystackpy/version.py index ad11b80..7b4e265 100644 --- a/paystackpy/version.py +++ b/paystackpy/version.py @@ -2,4 +2,4 @@ __version__ = '0.0.1' __author__ = 'Confi Yobo' __license__ = 'MIT' -__copyright__ = 'Copyright 2016. ConfI Yobo' +__copyright__ = 'Copyright 2016. Confi Yobo'