Skip to content

Commit

Permalink
fix: Linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chapimenge3 committed Mar 9, 2023
1 parent 0f244b9 commit baed948
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
49 changes: 28 additions & 21 deletions chapa/api.py
Expand Up @@ -11,11 +11,26 @@

class Response:
"""Custom Response class for SMS handling."""

def __init__(self, dict1):
self.__dict__.update(dict1)


def convert_response(response):
"""
Convert Response data to a Response object
Args:
response (dict): The response data to convert
Returns:
Response: The converted response
"""
if not isinstance(response, dict):
return response

return json.loads(json.dumps(response), object_hook=Response)


class Chapa:
"""
Simple SDK for Chapa Payment gateway
Expand Down Expand Up @@ -64,32 +79,18 @@ def send_request(self, url, method, data=None, params=None, headers=None):
response = func(url, data=data, headers=headers)
return getattr(response, "json", lambda: response.text)()

def convert_response(self, response):
"""
Convert Response data to a Response object
Args:
response (dict): The response data to convert
Returns:
Response: The converted response
"""
if not isinstance(response, dict):
return response

return json.loads(json.dumps(response), object_hook=Response)

def _construct_request(self, *args, **kwargs):
"""Construct the request to send to the API"""

res = self.send_request(*args, **kwargs)
if self.response_format == "obj" and isinstance(res, dict):
return self.convert_response(res)
return convert_response(res)

return res

def initialize(self, email: str, amount: int, first_name: str, last_name: str, tx_ref: str,
currency='ETB', callback_url=None, return_url=None, customization=None, headers=None, **kwargs):
currency='ETB', callback_url=None, return_url=None, customization=None,
headers=None, **kwargs):
"""
Initialize the Transaction
Expand All @@ -102,7 +103,8 @@ def initialize(self, email: str, amount: int, first_name: str, last_name: str, t
currency (str, optional): currency the transaction. Defaults to 'ETB'.
callback_url (str, optional): url for the customer to redirect after payment.
Defaults to None.
return_url (str, optional): Web address to redirect the user after payment is successful.
return_url (str, optional): Web address to redirect the user after payment
is successful.
Defaults to None.
customization (dict, optional): customization, currently 'title' and 'description'
are available. Defaults to None.
Expand All @@ -118,6 +120,7 @@ def initialize(self, email: str, amount: int, first_name: str, last_name: str, t
'last_name': last_name,
'tx_ref': tx_ref,
'currency': currency,
'return_url': return_url
}

if kwargs:
Expand Down Expand Up @@ -175,7 +178,9 @@ def verify(self, transaction, headers=None):
)
return response

def create_subaccount(self, business_name: str, account_name: str, bank_code: str, account_number: str, split_value: str, split_type: str, headers=None, **kwargs):
def create_subaccount(self, business_name: str, account_name: str, bank_code: str,
account_number: str, split_value: str, split_type: str,
headers=None, **kwargs):
"""
Create a subaccount for split payment
Expand Down Expand Up @@ -214,7 +219,9 @@ def create_subaccount(self, business_name: str, account_name: str, bank_code: st
)
return response

def initialize_split_payment(self, amount: int, currency: str, email: str, first_name: str, last_name: str, tx_ref: str, callback_url: str, return_url: str, subaccount_id: str, headers=None, **kwargs):
def initialize_split_payment(self, amount: int, currency: str, email: str, first_name: str,
last_name: str, tx_ref: str, callback_url: str, return_url: str,
subaccount_id: str, headers=None, **kwargs):
"""
Initialize split payment transaction
Expand Down
8 changes: 4 additions & 4 deletions chapa/webhook.py
Expand Up @@ -8,11 +8,11 @@
'charge.success': 'Charged successfully.',
'customeridentification.failed': 'Customer identification failed.',
'customeridentification.success': 'Customer identified successfully.',
'invoice.create': 'An invoice has been created for a customer\'s subscription.'
'Usually sent 3 days before the subscription is due.',
'invoice.create': 'An invoice has been created for a customer\'s subscription.' \
'Usually sent 3 days before the subscription is due.',
'invoice.payment_failed': 'Payment for invoice has failed.',
'invoice.update': 'Customer\'s invoice has been updated. This invoice should'
'be examined carfeully, and take necessary action.',
'invoice.update': 'Customer\'s invoice has been updated. This invoice should' \
'be examined carfeully, and take necessary action.',
'paymentrequest.pending': 'Payment request has been sent to customer and payment is pending.',
'paymentrequest.success': 'Customer\'s payment is successful.',
'subscription.create': 'Subscription has been created.',
Expand Down

0 comments on commit baed948

Please sign in to comment.