-
Notifications
You must be signed in to change notification settings - Fork 3
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
26 changed files
with
954 additions
and
63 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 |
---|---|---|
|
@@ -17,3 +17,5 @@ test.db | |
.idea | ||
*.iml | ||
|
||
# Code | ||
.vscode/ |
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
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,5 @@ | ||
pytest-django | ||
flake8 | ||
mypy | ||
python-language-server | ||
|
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,27 @@ | ||
# Netaxept | ||
|
||
## Configuration | ||
|
||
In the PAYMENT_GATEWAYS setting, configure the netaxept connection params: | ||
|
||
`merchant_id`, `secret`, `base_url`, and `after_terminal_url`. | ||
|
||
The production base_url is: | ||
|
||
`https://epayment.nets.eu/` | ||
|
||
|
||
## Design | ||
|
||
Netaxept works by taking the user to a hosted page and then redirecting the user to the merchant in order to finish | ||
processing the payment. | ||
We chose not to provide such a view in the payment application (we do provide an example view in the example_project), | ||
This means a project that uses netaxept payment will have to implement its own after_terminal view. | ||
|
||
- The first reason is that it's not possible to design a simple, generic response that we can show to users of the | ||
application (because we don't know anything about the application) | ||
- The second reason is that after a successful payment something more than just acknowledging the payment | ||
usually needs to happen in the application (for instance setting the status of an order, sending an email, etc). | ||
|
||
It's not impossible to solve those two problems with configuration, application-provided functions, and signals | ||
but it doesn't seem like all this complexity is worth it, compared to reimplementing a simple, straightforward webhook. |
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
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
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
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,21 +1,13 @@ | ||
from django.http import HttpRequest, HttpResponse | ||
from django.shortcuts import get_object_or_404, redirect | ||
from django.shortcuts import get_object_or_404 | ||
from django.template.response import TemplateResponse | ||
from structlog import get_logger | ||
|
||
from payment.models import Payment | ||
from payment.utils import gateway_capture | ||
|
||
logger = get_logger() | ||
|
||
|
||
def view_payment(request: HttpRequest, payment_id: int) -> HttpResponse: | ||
payment = get_object_or_404(Payment, id=payment_id) | ||
return TemplateResponse(request, 'operation_list.html', {'payment': payment}) | ||
|
||
|
||
def capture(request: HttpRequest, payment_id: int) -> HttpResponse: | ||
payment = get_object_or_404(Payment, id=payment_id) | ||
capture_result = gateway_capture(payment=payment) | ||
logger.info('capture', payment=payment, capture_result=capture_result) | ||
return redirect('view_payment', payment_id=payment_id) |
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,66 @@ | ||
""" | ||
Example views for interactive testing of payment with netaxept. | ||
""" | ||
from django.http import HttpRequest | ||
from django.http import HttpResponse | ||
from django.shortcuts import redirect, get_object_or_404 | ||
from django.urls import path | ||
from django.views.decorators.http import require_GET | ||
from structlog import get_logger | ||
|
||
from payment import get_payment_gateway | ||
from payment.gateways.netaxept import actions | ||
from payment.gateways.netaxept import gateway_to_netaxept_config | ||
from payment.gateways.netaxept.netaxept_protocol import get_payment_terminal_url | ||
from payment.models import Payment | ||
|
||
logger = get_logger() | ||
|
||
|
||
@require_GET | ||
def register_and_authorize(request: HttpRequest, payment_id: int) -> HttpResponse: | ||
""" | ||
Register the payment with netaxept, and take the user to the terminal page for payment authorization. | ||
""" | ||
logger.info('netaxept-register-and-authorize', payment_id=payment_id) | ||
|
||
transaction_id = actions.register_payment(payment_id) | ||
|
||
payment = get_object_or_404(Payment, id=payment_id) | ||
payment_gateway, gateway_config = get_payment_gateway(payment.gateway) | ||
netaxept_config = gateway_to_netaxept_config(gateway_config) | ||
return redirect(get_payment_terminal_url(config=netaxept_config, transaction_id=transaction_id)) | ||
|
||
|
||
@require_GET | ||
def after_terminal(request): | ||
""" | ||
The browser gets redirected here when the user finishes interacting with the netaxept terminal pages. | ||
We expect query-string parameters: transactionId and responseCode. | ||
See: https://shop.nets.eu/web/partners/response-codes | ||
We know we opened the terminal with AutoAuth set to True, so we interpret this callback to mean that an | ||
AUTH operation was performed. Netaxept does not provide any way to authenticate that the callback really comes | ||
from netaxept (other than them sending us a valid hard to guess 32 character long transaction_id), so we cannot | ||
be 100% sure of the information received. | ||
We decide to store the authorization operation nonetheless. If by any chance the information was faked we will | ||
detect it in the next step, when we try to capture the money. | ||
""" | ||
transaction_id = request.GET['transactionId'] | ||
response_code = request.GET['responseCode'] | ||
logger.info('netaxept-webhook', transaction_id=transaction_id, response_code=response_code) | ||
|
||
success = (response_code == 'OK') | ||
|
||
actions.create_auth_transaction(transaction_id=transaction_id, success=success) | ||
|
||
if success: | ||
return HttpResponse('ok') | ||
elif response_code: | ||
return HttpResponse('response code {}'.format(response_code)) | ||
|
||
|
||
urls = [ | ||
path('register_and_authorize/<payment_id>', register_and_authorize, name='netaxept_register_and_authorize'), | ||
path('after_terminal', after_terminal, name='netaxept_after_terminal'), | ||
] |
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
Oops, something went wrong.