Skip to content

Commit

Permalink
set up pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
nyior committed Dec 17, 2021
1 parent 83944a8 commit 40f05d7
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 49 deletions.
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
1 change: 0 additions & 1 deletion paystack/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion paystack/services/base_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def validate_amount(self, amount):
if isinstance(amount, int) or isinstance(amount, float):
if amount < 0:
raise ValidationError("Negative amount is not allowed")
return amount * 100 # in kobo
return amount * 100 # in kobo
else:
raise ValidationError("Amount must be a number")

Expand Down
9 changes: 5 additions & 4 deletions paystack/services/transaction_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from rest_framework.response import Response

from paystack.models import TransactionLog
from paystack.paystack_urls import (PAYSTACK_CHARGE_AUTHORIZATION_URL,
PAYSTACK_INITIALIZE_TRANSACTION_URL,
PAYSTACK_VERIFY_TRANSACTION_URL,
TRANSACTION_URL)
from paystack.paystack_urls import (
PAYSTACK_CHARGE_AUTHORIZATION_URL,
PAYSTACK_INITIALIZE_TRANSACTION_URL,
PAYSTACK_VERIFY_TRANSACTION_URL,
)

from .base_api_service import BaseAPIService

Expand Down
3 changes: 1 addition & 2 deletions paystack/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.urls import include, path
from rest_framework import routers

from paystack.views import (PaystackCustomerViewSet, TransactionViewSet,
WebhookView)
from paystack.views import PaystackCustomerViewSet, TransactionViewSet, WebhookView

router = routers.DefaultRouter()
router.register("transaction", TransactionViewSet, basename="transaction")
Expand Down
38 changes: 19 additions & 19 deletions paystack/views/transaction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import viewsets
from rest_framework.decorators import action, permission_classes
from rest_framework.decorators import action

from paystack.models import TransactionLog
from paystack.serializers import PaymentSerializer
Expand All @@ -17,15 +17,15 @@ class TransactionViewSet(viewsets.ModelViewSet):
@action(detail=False, methods=["post"])
def initiate(self, request):
"""
This is used to charge customers that had already been charged in
past.
Expects the payload in the format below:
{
"email": "string",
"amount": float/int,
"metadata": dict/json, --Optional
}
This is used to charge customers that had already been charged in
past.
Expects the payload in the format below:
{
"email": "string",
"amount": float/int,
"metadata": dict/json, --Optional
}
"""
payload = request.data

Expand All @@ -51,19 +51,19 @@ def verify(self, request):
@action(detail=False, methods=["post"], url_path="charge-customer")
def charge_customer(self, request):
"""
This is used to charge customers that had already been charged in
past.
Expects the payload in the format below:
This is used to charge customers that had already been charged in
past.
Expects the payload in the format below:
{
"email": "string",
"amount": float/int,
"authorization_code": "string",
}
{
"email": "string",
"amount": float/int,
"authorization_code": "string",
}
"""
payload = request.data

transaction_service = TransactionService()
charge = transaction_service.recurrent_charge(payload)

Expand Down
3 changes: 2 additions & 1 deletion paystack/views/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class WebhookFacadeView(APIView):
"""
Exsits for extensibility reasons. Users might want to capture
the data returned from Paystack and do some stuff with it.
E.g retrieve the user tied to the payment(usually passed as a meta data in this package)
E.g retrieve the user tied to the
payment(usually passed as a meta data in this package)
and clear the user's cart or create an order for that user.
"""

Expand Down
8 changes: 8 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Django==2.2
djangorestframework==3.1.3
pytest==6.2.5
python-dotenv==0.19.2
isort==5.10.1
black==21.12b0
flake8==4.0.1
pre-commit==2.16.0
24 changes: 23 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,33 @@ install_requires =
djangorestframework>=3.1.3



[tool:pytest]
DJANGO_SETTINGS_MODULE = tests.settings
django_find_project = false
testpaths =
tests


[tool.black]
line-length = 89
# include = '\.pyi?$'
exclude = migrations, dist, .env


[isort]
line_length = 89
skip = migrations, .venv, dist
known_third_party = django_dynamic_fixture
known_first_party = paystack
multi_line_output = 3
include_trailing_comma = True

[flake8]
max-line-length = 89
exclude = *migrations*, dist, .venv
# ignore = E203, E266, E501, W503, F403, F401
ignore = F403, F401
max-complexity = 18
select = B,C,E,F,W,T4,B9


3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import pytest
from django.contrib.auth import get_user_model

pytestmark = pytest.mark.django_db

from django.contrib.auth import get_user_model

User = get_user_model()


Expand Down
19 changes: 1 addition & 18 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

load_dotenv()


# Run tests: python -m pytest tests
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

Expand Down Expand Up @@ -95,23 +95,6 @@

REST_FRAMEWORK = {"DEFAULT_SCHEMA_CLASS": "rest_framework.schemas.coreapi.AutoSchema"}

# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]

PAYSTACK_PUBLIC_KEY = os.environ.get("PAYSTACK_PUBLIC_KEY")
PAYSTACK_PRIVATE_KEY = os.environ.get("PAYSTACK_PRIVATE_KEY")
Expand Down

0 comments on commit 40f05d7

Please sign in to comment.