-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
175 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |