Skip to content

Commit

Permalink
authorization id can be absent from query response
Browse files Browse the repository at this point in the history
  • Loading branch information
nwolff committed Nov 3, 2019
1 parent 92f5ea9 commit 5cd62a4
Show file tree
Hide file tree
Showing 5 changed files with 251 additions and 7 deletions.
15 changes: 10 additions & 5 deletions example_project/views/netaxept.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def after_terminal(request):
response_code = request.GET['responseCode']
logger.info('netaxept-after-terminal', transaction_id=transaction_id, response_code=response_code)

if response_code == 'OK':
if response_code == 'Cancel':
return HttpResponse('Payment cancelled')
elif response_code == 'OK':
payment = Payment.objects.get(token=transaction_id)
try:
# This will verify if the payment was indeed authorized.
Expand All @@ -63,10 +65,13 @@ def after_terminal(request):
return HttpResponse('Error authorizing {}: {}'.format(payment.id, exc))
else:
return redirect('view_payment', payment_id=payment.id)
elif response_code == 'Cancel':
return HttpResponse('Payment cancelled')
else:
return HttpResponse('Payment error {}'.format(response_code))
else: # The error case
payment = Payment.objects.get(token=transaction_id)
try:
# This will query the state of the payment in netaxept, and create a transaction object with all details
gateway_authorize(payment=payment, payment_token=payment.token)
finally:
return HttpResponse('Payment error {}'.format(response_code))


def query(request: HttpRequest, transaction_id: str) -> HttpResponse:
Expand Down
2 changes: 1 addition & 1 deletion payment/gateways/netaxept/netaxept_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def query(config: NetaxeptConfig, transaction_id: str) -> QueryResponse:
summary = d['PaymentInfo']['Summary']
annulled = summary['Annulled'] == 'true'
authorized = summary['Authorized'] == 'true'
authorization_id = summary['AuthorizationId']
authorization_id = summary.get('AuthorizationId') # AuthorizationId may be absent from the response
return QueryResponse(
annulled=annulled,
authorized=authorized,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='django-payment',
version='1.2',
version='1.4',
description='',
long_description='',
author='Nicholas Wolff',
Expand Down
144 changes: 144 additions & 0 deletions tests/gateways/bob.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
<PaymentInfo>
<MerchantId>12002913</MerchantId>
<QueryFinished>2019-11-03T09:35:00.1029756+01:00</QueryFinished>
<TransactionId>
2778ffe955754b3ca217697982bb5272
</TransactionId>

<OrderInformation>
<Amount>1000</Amount>
<Currency>NOK</Currency>
<OrderNumber>32</OrderNumber>
<OrderDescription></OrderDescription>
<Fee>
0
</Fee>
<RoundingAmount>0</RoundingAmount>
<Total>1000</Total>
<Timestamp>
2019-11-03T09:34:21.273
</Timestamp>

</OrderInformation>


<TerminalInformation>
<CustomerEntered>2019-11-03T09:34:26.210</CustomerEntered>
<CustomerRedirected>
2019-11-03T09:34:40.227
</CustomerRedirected>
<Browser>Chrome-Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36
</Browser>

</TerminalInformation>


<CustomerInformation>
<Email>nwolff@gmail.com</Email>
<IP>85.218.56.162</IP>
<PhoneNumber/>

<CustomerNumber/>
<FirstName/>
<LastName/>
<Address1/>
<Address2/>
<Postcode/>
<Town/>

<Country/>
<SocialSecurityNumber/>
<CompanyName/>
<CompanyRegistrationNumber/>

</CustomerInformation>


<Summary>
<AmountCaptured>0</AmountCaptured>
<AmountCredited>0</AmountCredited>
<Annulled>
false
</Annulled>
<Annuled>false</Annuled>
<Authorized>false</Authorized>

</Summary>


<CardInformation>
<Issuer>Visa</Issuer>
<IssuerCountry>NO</IssuerCountry>
<MaskedPAN>
492500******0087
</MaskedPAN>
<PaymentMethod>Visa</PaymentMethod>
<ExpiryDate>2002</ExpiryDate>
<IssuerId>
3
</IssuerId>

</CardInformation>


<History>

<TransactionLogLine>
<DateTime>2019-11-03T09:34:21.273</DateTime>
<Description/>

<Operation>Register</Operation>
<TransactionReconRef/>

</TransactionLogLine>


</History>


<ErrorLog>

<PaymentError>
<DateTime>2019-11-03T09:34:40.18</DateTime>
<Operation>Auth</Operation>
<ResponseCode>
99
</ResponseCode>
<ResponseSource>Netaxept</ResponseSource>
<ResponseText>Auth Reg Comp
Failure)
</ResponseText>

</PaymentError>


</ErrorLog>

<AuthenticationInformation/>
<AvtaleGiroInformation/>

<Error>
<DateTime>2019-11-03T09:34:40.18</DateTime>
<Operation>Auth</Operation>
<ResponseCode>
99
</ResponseCode>
<ResponseSource>Netaxept</ResponseSource>
<ResponseText>Auth Reg Comp
Failure)
</ResponseText>

</Error>


<SecurityInformation>
<CustomerIPCountry>CH</CustomerIPCountry>
<IPCountryMatchesIssuingCountry>
false
</IPCountryMatchesIssuingCountry>

</SecurityInformation>


</PaymentInfo>
95 changes: 95 additions & 0 deletions tests/gateways/test_netaxept.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,101 @@ def it_should_query(requests_post):
raw_response=asdict(mock_response))


@patch('requests.post')
def it_should_handle_query_response_without_authorization_id(requests_post):
mock_response = MockResponse(
status_code=200,
url='https://test.epayment.nets.eu/Netaxept/Query.aspx',
encoding='ISO-8859-1',
reason='OK',
text="""<?xml version="1.0" encoding="utf-8"?>
<PaymentInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MerchantId>11111111</MerchantId>
<QueryFinished>2019-10-14T10:15:07.2677951+02:00</QueryFinished>
<TransactionId>1111111111114cf693a1cf86123e0d8f</TransactionId>
<OrderInformation>
<Amount>700</Amount>
<Currency>NOK</Currency>
<OrderNumber>7</OrderNumber>
<OrderDescription> </OrderDescription>
<Fee>0</Fee>
<RoundingAmount>0</RoundingAmount>
<Total>700</Total>
<Timestamp>2019-09-11T16:30:06.967</Timestamp>
</OrderInformation>
<TerminalInformation>
<CustomerEntered>2019-09-11T16:30:08.513</CustomerEntered>
<CustomerRedirected>2019-09-11T16:30:24.903</CustomerRedirected>
<Browser>Chrome-Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36</Browser>
</TerminalInformation>
<CustomerInformation>
<Email />
<IP>85.218.56.162</IP>
<PhoneNumber />
<CustomerNumber />
<FirstName />
<LastName />
<Address1 />
<Address2 />
<Postcode />
<Town />
<Country />
<SocialSecurityNumber />
<CompanyName />
<CompanyRegistrationNumber />
</CustomerInformation>
<Summary>
<AmountCaptured>700</AmountCaptured>
<AmountCredited>0</AmountCredited>
<Annulled>false</Annulled>
<Annuled>false</Annuled>
<Authorized>true</Authorized>
</Summary>
<CardInformation>
<Issuer>Visa</Issuer>
<IssuerCountry>NO</IssuerCountry>
<MaskedPAN>492500******0004</MaskedPAN>
<PaymentMethod>Visa</PaymentMethod>
<ExpiryDate>2301</ExpiryDate>
<IssuerId>3</IssuerId>
</CardInformation>
<History>
<TransactionLogLine>
<DateTime>2019-09-11T16:30:06.967</DateTime>
<Operation>Register</Operation>
</TransactionLogLine>
<TransactionLogLine>
<DateTime>2019-09-11T16:30:24.81</DateTime>
<Description>127.0.0.1: Auto AUTH</Description>
<Operation>Auth</Operation>
<BatchNumber>672</BatchNumber>
</TransactionLogLine>
</History>
<ErrorLog>
<PaymentError>
<DateTime>2019-11-03T09:34:40.18</DateTime>
<Operation>Auth</Operation>
<ResponseCode>99</ResponseCode>
<ResponseSource>Netaxept</ResponseSource>
<ResponseText>Auth Reg Comp Failure) </ResponseText>
</PaymentError>
</ErrorLog>
<AuthenticationInformation />
<AvtaleGiroInformation />
<SecurityInformation>
<CustomerIPCountry>CH</CustomerIPCountry>
<IPCountryMatchesIssuingCountry>false</IPCountryMatchesIssuingCountry>
</SecurityInformation>
</PaymentInfo>""")
requests_post.return_value = mock_response
query_response = query(config=_netaxept_config, transaction_id='233abb21f18b47dc98469fb9000b1f21')
assert query_response == QueryResponse(
annulled=False,
authorized=True,
authorization_id=None,
raw_response=asdict(mock_response))


##############################################################################
# SPI tests

Expand Down

0 comments on commit 5cd62a4

Please sign in to comment.