Skip to content

Commit

Permalink
07.09.24
Browse files Browse the repository at this point in the history
  • Loading branch information
nichind committed Sep 7, 2024
1 parent a013d5a commit c97ed62
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test.py
.idea

# Byte-compiled / optimized / DLL files
Expand Down
2 changes: 1 addition & 1 deletion pyeasypay/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .core import EasyPay, Invoice, Provider
from .core import EasyPay, Invoice, Provider, Providers

29 changes: 27 additions & 2 deletions pyeasypay/core/pay.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Any
from requests import get
from importlib.metadata import version
from os.path import dirname, basename, isfile, join
Expand Down Expand Up @@ -28,7 +29,17 @@ def __repr__(self):

class Providers:
def __init__(self):
pass
modules = glob.glob(join(dirname(__file__) + '/providers', "*.py"))
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
for _ in __all__:
setattr(self, _, Provider(_))


def list(self):
return self.__dict__

def __repr__(self):
return f'Providers({self.__dict__})'


class EasyPay:
Expand All @@ -40,8 +51,10 @@ def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
if 'provider' not in self.__dict__ and 'providers' not in self.__dict__:
raise ValueError('At least one provider is required')
raise ValueError('At least one provider is required for EasyPay to work')
if 'providers' in self.__dict__:
if isinstance(self.__dict__['providers'], Provider):
return self.configure_provider(self.__dict__['providers'])
for provider in self.__dict__['providers']:
self.configure_provider(provider)

Expand Down Expand Up @@ -93,6 +106,18 @@ async def init_invoice(self, provider: str | Provider):
modules = glob.glob(join(dirname(__file__) + '/providers', "*.py"))
__all__ = [basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
provider_name = provider.name if isinstance(provider, Provider) else provider
if self.currency is None or self.currency == '':
self.currency = 'USD'
print("Currency was not provided for create_invoice, defaulting to USD")
if provider_name == 'None' or provider_name is None or provider_name == '':
for provider, args in self.providers.__dict__.items():
if len(args.__dict__) > 1:
provider_name = provider
print(f"Provider was not provided for create_invoice, defaulting to {provider_name}"
" since it was added to the EasyPay instance")
break
if provider_name == '' or provider_name is None or provider_name == 'None':
raise ValueError('Provider is not provided for create_invoice')
if provider_name not in __all__:
raise ValueError(
f'Provider {provider_name} is not supported'
Expand Down
2 changes: 1 addition & 1 deletion pyeasypay/core/providers/cryptobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def create(self):
invoice = await self.crypto.create_invoice(asset=self.invoice.currency, amount=self.amount)
except factory.CodeErrorFactory as e:
await self.crypto.close()
raise ValueError(f"Wasn't able to create invoice ({e.code}: {e.name})")
raise ValueError(f"Wasn't able to create invoice for {self.creds.name} provider: ({e.code}: {e.name})")
self.invoice.pay_info = invoice.bot_invoice_url
self.invoice.identifier = invoice.invoice_id
self.invoice.status = invoice.status
Expand Down
2 changes: 1 addition & 1 deletion pyeasypay/core/providers/crystalpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def create(self):
data = response.json()

if data.get("error"):
raise ValueError(data.get("errors"))
raise ValueError(f"Wasn't able to create invoice for {self.creds.name} provider: {data.get("errors")}")
self.invoice.identifier = data.get("id")
self.invoice.pay_info = data.get("url")
return self.invoice.pay_info
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():

setup(
name='pyeasypay',
version='0.2.7',
version='0.2.8',
author='nichind',
author_email='nichinddev@gmail.com',
description='Make money from your Python projects the easy way.',
Expand Down

0 comments on commit c97ed62

Please sign in to comment.