Skip to content

Commit

Permalink
Added missing exception and SALE processing
Browse files Browse the repository at this point in the history
Added the PaymentRegistrationNotCompleted exception.
Added methods to handle the SALE transaction.
  • Loading branch information
erlenddalen committed Jul 4, 2013
1 parent af5beb8 commit 364a1d9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
5 changes: 4 additions & 1 deletion djnetaxept/exceptions.py
Expand Up @@ -9,4 +9,7 @@ class AmountAllreadyCaptured(BaseNetaxeptException):
msg = 'Amount allready captured, do a CREDIT'

class NoAmountCaptured(BaseNetaxeptException):
msg = 'No amount captured nothing to CREDIT'
msg = 'No amount captured nothing to CREDIT'

class PaymentRegistrationNotCompleted(BaseNetaxeptException):
msg = 'Payment registration is not completed yet'
43 changes: 37 additions & 6 deletions djnetaxept/managers.py
Expand Up @@ -2,7 +2,8 @@
from django.db import models
from djnetaxept.utils import get_client, get_basic_registerrequest, get_netaxept_object, handle_response_exception
from djnetaxept.operations import register, process, query, batch
from djnetaxept.exceptions import PaymentNotAuthorized, AmountAllreadyCaptured, NoAmountCaptured
from djnetaxept.exceptions import PaymentNotAuthorized, AmountAllreadyCaptured, NoAmountCaptured, \
PaymentRegistrationNotCompleted


class NetaxeptPaymentManager(models.Manager):
Expand Down Expand Up @@ -44,10 +45,39 @@ def register_payment(self,

class NetaxeptTransactionManager(models.Manager):

def sale_payment(self, payment, amount):

if not payment.completed():
raise PaymentRegistrationNotCompleted

client = get_client()
operation = 'SALE'

request = get_netaxept_object(client, 'ProcessRequest')
request.Operation = operation
request.TransactionId = payment.transaction_id
request.TransactionAmount = amount

transaction = self.model(
payment=payment,
transaction_id=payment.transaction_id,
amount=amount,
operation=operation,
)

try:
response = process(client, request)
except suds.WebFault, e:
handle_response_exception(e, transaction)

transaction.save()
return transaction

def auth_payment(self, payment):

if not payment.completed():
raise PaymentRegistrationNotCompleted
print "not completed"
raise PaymentRegistrationNotCompleted

client = get_client()
operation = 'AUTH'
Expand All @@ -61,12 +91,13 @@ def auth_payment(self, payment):
transaction_id=payment.transaction_id,
operation=operation
)

print "Transaction: ", transaction
try:
response = process(client, request)
except suds.WebFault, e:
handle_response_exception(e, transaction)


print "response: ", response
transaction.save()
return transaction

Expand All @@ -80,7 +111,7 @@ def capture_payment(self, payment, amount):
request = get_netaxept_object(client, 'ProcessRequest')
request.Operation = operation
request.TransactionId = payment.transaction_id
request.Amount = amount
request.TransactionAmount = amount

transaction = self.model(
payment=payment,
Expand Down Expand Up @@ -110,7 +141,7 @@ def credit_payment(self, payment, amount):
request = get_netaxept_object(client, 'ProcessRequest')
request.Operation = operation
request.TransactionId = payment.transaction_id
request.Amount = amount
request.TransactionAmount = amount

transaction = self.model(
payment=payment,
Expand Down
3 changes: 3 additions & 0 deletions djnetaxept/models.py
Expand Up @@ -22,6 +22,9 @@ class NetaxeptPayment(models.Model):

objects = NetaxeptPaymentManager()

def sale(self):
return NetaxeptTransaction.objects.sale_payment(self)

def auth(self):
return NetaxeptTransaction.objects.auth_payment(self)

Expand Down
4 changes: 2 additions & 2 deletions djnetaxept/utils.py
Expand Up @@ -6,8 +6,8 @@
logger = logging.getLogger(__name__)

WSDL = getattr(settings, 'NETAXEPT_WSDL', 'https://epayment-test.bbs.no/netaxept.svc?wsdl')
MERCHANTID = getattr(settings, 'NETAXEPT_MERCHANTID', '')
TOKEN = getattr(settings, 'NETAXEPT_TOKEN', '')
MERCHANTID = getattr(settings, 'NETAXEPT_MERCHANTID', '') # Enter your merchant id here
TOKEN = getattr(settings, 'NETAXEPT_TOKEN', '') # Enter the password you have received from Netaxept here
TERMNAL = getattr(settings, 'NETAXEPT_TERMINAL', 'https://epayment-test.bbs.no/Terminal/default.aspx')
CURRENCY_CODE = getattr(settings, 'NETAXEPT_CURRENCY_CODE', 'NOK')

Expand Down

0 comments on commit 364a1d9

Please sign in to comment.