Skip to content

Commit

Permalink
use gateway authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolff committed Oct 15, 2019
1 parent b2e66e9 commit 3fadb16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
12 changes: 0 additions & 12 deletions example_project/templates/netaxept/after_auth.html

This file was deleted.

2 changes: 1 addition & 1 deletion example_project/templates/view_payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <H3>Operations</H3>
<li><a href="{% url 'stripe_checkout' payment.id %}">Authorize - Checkout</a></li>
<li><a href="{% url 'stripe_payment_intents_manual_flow' payment.id %}">Authorize - Payment intents manual flow</a>
{% elif payment.gateway == 'netaxept' %}
<li><a href="{% url 'netaxept_register_and_authorize' payment.id %}">Register and Authorize</a></li>
<li><a href="{% url 'netaxept_register_and_goto_terminal' payment.id %}">Register and Goto Terminal</a></li>
{% if payment.token %}
<li><a href="{% url 'netaxept_query' payment.token %}">Query</a></li>
{% endif %}
Expand Down
17 changes: 11 additions & 6 deletions example_project/views/netaxept.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from payment.gateways.netaxept import gateway_to_netaxept_config
from payment.gateways.netaxept import netaxept_protocol
from payment.models import Payment
from payment.utils import gateway_authorize

logger = get_logger()


@require_GET
def register_and_authorize(request: HttpRequest, payment_id: int) -> HttpResponse:
def register_and_goto_terminal(request: HttpRequest, payment_id: int) -> HttpResponse:
"""
Register the payment with netaxept, and take the user to the terminal page for payment authorization
"""
Expand Down Expand Up @@ -50,11 +51,15 @@ def after_terminal(request):
response_code = request.GET['responseCode']
logger.info('netaxept-after-terminal', transaction_id=transaction_id, response_code=response_code)

payment_authorized = actions.verify_auth_transaction(transaction_id=transaction_id, response_code=response_code)
payment = Payment.objects.get(token=transaction_id)

return TemplateResponse(request, 'netaxept/after_auth.html',
{'transaction_id': transaction_id, 'response_code': response_code,
'payment_authorized': payment_authorized})
try:
gateway_authorize(payment=payment, payment_token=transaction_id)
except Exception as exc:
logger.error('netaxept after terminal', exc_info=exc)
return HttpResponse('Error authorizing {}: {}'.format(payment.id, exc))
else:
return redirect('view_payment', payment_id=payment.id)


def query(request: HttpRequest, transaction_id: str) -> HttpResponse:
Expand All @@ -69,7 +74,7 @@ def query(request: HttpRequest, transaction_id: str) -> HttpResponse:


urls = [
path('register_and_authorize/<payment_id>', register_and_authorize, name='netaxept_register_and_authorize'),
path('register_and_goto_terminal/<payment_id>', register_and_goto_terminal, name='netaxept_register_and_goto_terminal'),
path('after_terminal', after_terminal, name='netaxept_after_terminal'),
path('query/<transaction_id>', query, name='netaxept_query'),
]

0 comments on commit 3fadb16

Please sign in to comment.