Skip to content

Commit c44015b

Browse files
committed
authorization id can be absent from query response
1 parent 92f5ea9 commit c44015b

File tree

4 files changed

+107
-7
lines changed

4 files changed

+107
-7
lines changed

example_project/views/netaxept.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def after_terminal(request):
5353
response_code = request.GET['responseCode']
5454
logger.info('netaxept-after-terminal', transaction_id=transaction_id, response_code=response_code)
5555

56-
if response_code == 'OK':
56+
if response_code == 'Cancel':
57+
return HttpResponse('Payment cancelled')
58+
elif response_code == 'OK':
5759
payment = Payment.objects.get(token=transaction_id)
5860
try:
5961
# This will verify if the payment was indeed authorized.
@@ -63,10 +65,13 @@ def after_terminal(request):
6365
return HttpResponse('Error authorizing {}: {}'.format(payment.id, exc))
6466
else:
6567
return redirect('view_payment', payment_id=payment.id)
66-
elif response_code == 'Cancel':
67-
return HttpResponse('Payment cancelled')
68-
else:
69-
return HttpResponse('Payment error {}'.format(response_code))
68+
else: # The error case
69+
payment = Payment.objects.get(token=transaction_id)
70+
try:
71+
# This will query the state of the payment in netaxept, and create a transaction object with all details
72+
gateway_authorize(payment=payment, payment_token=payment.token)
73+
finally:
74+
return HttpResponse('Payment error {}'.format(response_code))
7075

7176

7277
def query(request: HttpRequest, transaction_id: str) -> HttpResponse:

payment/gateways/netaxept/netaxept_protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def query(config: NetaxeptConfig, transaction_id: str) -> QueryResponse:
191191
summary = d['PaymentInfo']['Summary']
192192
annulled = summary['Annulled'] == 'true'
193193
authorized = summary['Authorized'] == 'true'
194-
authorization_id = summary['AuthorizationId']
194+
authorization_id = summary.get('AuthorizationId') # AuthorizationId may be absent from the response
195195
return QueryResponse(
196196
annulled=annulled,
197197
authorized=authorized,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='django-payment',
6-
version='1.2',
6+
version='1.4',
77
description='',
88
long_description='',
99
author='Nicholas Wolff',

tests/gateways/test_netaxept.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,101 @@ def it_should_query(requests_post):
265265
raw_response=asdict(mock_response))
266266

267267

268+
@patch('requests.post')
269+
def it_should_handle_query_response_without_authorization_id(requests_post):
270+
mock_response = MockResponse(
271+
status_code=200,
272+
url='https://test.epayment.nets.eu/Netaxept/Query.aspx',
273+
encoding='ISO-8859-1',
274+
reason='OK',
275+
text="""<?xml version="1.0" encoding="utf-8"?>
276+
<PaymentInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
277+
<MerchantId>11111111</MerchantId>
278+
<QueryFinished>2019-10-14T10:15:07.2677951+02:00</QueryFinished>
279+
<TransactionId>1111111111114cf693a1cf86123e0d8f</TransactionId>
280+
<OrderInformation>
281+
<Amount>700</Amount>
282+
<Currency>NOK</Currency>
283+
<OrderNumber>7</OrderNumber>
284+
<OrderDescription> </OrderDescription>
285+
<Fee>0</Fee>
286+
<RoundingAmount>0</RoundingAmount>
287+
<Total>700</Total>
288+
<Timestamp>2019-09-11T16:30:06.967</Timestamp>
289+
</OrderInformation>
290+
<TerminalInformation>
291+
<CustomerEntered>2019-09-11T16:30:08.513</CustomerEntered>
292+
<CustomerRedirected>2019-09-11T16:30:24.903</CustomerRedirected>
293+
<Browser>Chrome-Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36</Browser>
294+
</TerminalInformation>
295+
<CustomerInformation>
296+
<Email />
297+
<IP>85.218.56.162</IP>
298+
<PhoneNumber />
299+
<CustomerNumber />
300+
<FirstName />
301+
<LastName />
302+
<Address1 />
303+
<Address2 />
304+
<Postcode />
305+
<Town />
306+
<Country />
307+
<SocialSecurityNumber />
308+
<CompanyName />
309+
<CompanyRegistrationNumber />
310+
</CustomerInformation>
311+
<Summary>
312+
<AmountCaptured>700</AmountCaptured>
313+
<AmountCredited>0</AmountCredited>
314+
<Annulled>false</Annulled>
315+
<Annuled>false</Annuled>
316+
<Authorized>true</Authorized>
317+
</Summary>
318+
<CardInformation>
319+
<Issuer>Visa</Issuer>
320+
<IssuerCountry>NO</IssuerCountry>
321+
<MaskedPAN>492500******0004</MaskedPAN>
322+
<PaymentMethod>Visa</PaymentMethod>
323+
<ExpiryDate>2301</ExpiryDate>
324+
<IssuerId>3</IssuerId>
325+
</CardInformation>
326+
<History>
327+
<TransactionLogLine>
328+
<DateTime>2019-09-11T16:30:06.967</DateTime>
329+
<Operation>Register</Operation>
330+
</TransactionLogLine>
331+
<TransactionLogLine>
332+
<DateTime>2019-09-11T16:30:24.81</DateTime>
333+
<Description>127.0.0.1: Auto AUTH</Description>
334+
<Operation>Auth</Operation>
335+
<BatchNumber>672</BatchNumber>
336+
</TransactionLogLine>
337+
</History>
338+
<ErrorLog>
339+
<PaymentError>
340+
<DateTime>2019-11-03T09:34:40.18</DateTime>
341+
<Operation>Auth</Operation>
342+
<ResponseCode>99</ResponseCode>
343+
<ResponseSource>Netaxept</ResponseSource>
344+
<ResponseText>Auth Reg Comp Failure) </ResponseText>
345+
</PaymentError>
346+
</ErrorLog>
347+
<AuthenticationInformation />
348+
<AvtaleGiroInformation />
349+
<SecurityInformation>
350+
<CustomerIPCountry>CH</CustomerIPCountry>
351+
<IPCountryMatchesIssuingCountry>false</IPCountryMatchesIssuingCountry>
352+
</SecurityInformation>
353+
</PaymentInfo>""")
354+
requests_post.return_value = mock_response
355+
query_response = query(config=_netaxept_config, transaction_id='233abb21f18b47dc98469fb9000b1f21')
356+
assert query_response == QueryResponse(
357+
annulled=False,
358+
authorized=True,
359+
authorization_id=None,
360+
raw_response=asdict(mock_response))
361+
362+
268363
##############################################################################
269364
# SPI tests
270365

0 commit comments

Comments
 (0)