Skip to content

Commit

Permalink
ADD: example views
Browse files Browse the repository at this point in the history
  • Loading branch information
aibaq committed Jun 11, 2020
1 parent 852ebe0 commit aa8fc2e
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 8 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Installation

```
pip install git+ssh://[email protected]/aibaq/[email protected]
```

# Settings

```
INSTALLED_APPS += ['paybox_api']
PG_URL = 'https://api.paybox.money/payment.php'
PG_REVOKE_URL = 'https://api.paybox.money/revoke.php'
PG_SECRET = os.getenv('PG_SECRET')
PG_SECRET_TICKET = os.getenv('PG_SECRET_TICKET')
PG_MERCHANT_ID = os.getenv('PG_MERCHANT_ID')
PG_TESTING_MODE = '1'
PG_RESULT_URL = 'http://yourdomain/payments/paybox/result/'
PG_SUCCESS_URL = 'http://yourdomain/payments/paybox/success/'
PG_CHECK_URL = 'http://yourdomain/payments/paybox/check/'
PG_REFUND_URL = 'http://yourdomain/payments/paybox/refund/'
PG_CAPTURE_URL = 'http://yourdomain/payments/paybox/capture/'
PG_FAILURE_URL = 'http://yourdomain/payments/paybox/failure/'
```

# Usage

```
from app.payments.paybox import PayboxAPI
PayboxAPI().get_url(
order_id=1,
amount=1000,
description='Iphone11',
salt=PayboxAPI.generate_salt(),
email='[email protected]',
phone='+77777777777',
)
```
Open generated url in browser

handle callbacks at views.py : see test_app
12 changes: 7 additions & 5 deletions test_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.conf.urls import url
from django.contrib import admin
from rest_framework.routers import DefaultRouter

urlpatterns = [
url(r'^admin/', admin.site.urls),
]
from app.payments import views


router = DefaultRouter()
router.register('paybox', views.PayboxViewSet, basename='paybox')
urlpatterns = router.urls
3 changes: 0 additions & 3 deletions test_app/utils.py

This file was deleted.

63 changes: 63 additions & 0 deletions test_app/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging

from django.http import HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.urls import reverse

from rest_framework import (
viewsets,
serializers,
)
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
from rest_framework.response import Response

from paybox_api import PayboxAPI


logger = logging.getLogger(__name__)


class PayboxViewSet(viewsets.ViewSet):
permission_classes = (AllowAny,)

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def check(self, request):
# Do smth here
return Response()

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def result(self, request):
body = PayboxAPI.parse_body(request.body)

if body['pg_result'] == '1':
# Handle success result
else:
# Handle failure result
return Response()

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def refund(self, request):
# Do smth here
return Response({'refund': 'refund'})

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def capture(self, request):
# Do smth here
return Response({'capture': 'capture'})

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def success(self, request):
# Do smth here
return HttpResponseRedirect('google.com')

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def failure(self, request):
# Do smth here
return HttpResponseRedirect('google.com')
63 changes: 63 additions & 0 deletions views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import logging

from django.http import HttpResponseRedirect
from django.utils.decorators import method_decorator
from django.urls import reverse

from rest_framework import (
viewsets,
serializers,
)
from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
from rest_framework.response import Response

from paybox_api import PayboxAPI


logger = logging.getLogger(__name__)


class PayboxViewSet(viewsets.ViewSet):
permission_classes = (AllowAny,)

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def check(self, request):
# Do smth here
return Response()

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def result(self, request):
body = PayboxAPI.parse_body(request.body)

if body['pg_result'] == '1':
# Handle success result
else:
# Handle failure result
return Response()

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def refund(self, request):
# Do smth here
return Response({'refund': 'refund'})

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def capture(self, request):
# Do smth here
return Response({'capture': 'capture'})

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def success(self, request):
# Do smth here
return HttpResponseRedirect('google.com')

@action(methods=['post'], detail=False)
@method_decorator(PayboxAPI.verify_paybox())
def failure(self, request):
# Do smth here
return HttpResponseRedirect('google.com')

0 comments on commit aa8fc2e

Please sign in to comment.