Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added missing exception and SALE processing

Added the PaymentRegistrationNotCompleted exception.
Added methods to handle the SALE transaction.
  • Loading branch information...
commit 364a1d9c7253c470b4a499e1638cfc34b401b45c 1 parent af5beb8
@erlenddalen authored
View
5 djnetaxept/exceptions.py
@@ -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'
View
43 djnetaxept/managers.py
@@ -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):
@@ -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'
@@ -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
@@ -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,
@@ -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,
View
3  djnetaxept/models.py
@@ -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)
View
4 djnetaxept/utils.py
@@ -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')
Please sign in to comment.
Something went wrong with that request. Please try again.