Skip to content

Commit

Permalink
Merge pull request #114 from rayrayndwiga/master
Browse files Browse the repository at this point in the history
Delete invoice token after making payment.
  • Loading branch information
dbca-asi committed Sep 5, 2016
2 parents dd56c10 + f2fa9a4 commit d51a43b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
10 changes: 10 additions & 0 deletions ledger/payments/bpoint/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ def pay_with_temptoken(self,action,_type,sub_type,token,order_number=None,refere
except BpointToken.DoesNotExist as e:
raise UnableToTakePayment(str(e))

def delete_token(self,token):
try:
res = self.gateway.delete_token(token)
except Exception:
raise
# Check if the transaction was successful
if not res.api_response.response_code == 0:
raise UnableToTakePayment(res.api_response.response_text)
return res

def friendly_error_msg(self, txn):
if not txn.approved:
raise UnableToTakePayment(txn.response_txt)
Expand Down
10 changes: 8 additions & 2 deletions ledger/payments/bpoint/gateway.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import logging
from . import settings
logger = logging.getLogger('bpoint_dpaw')
from ledger.payments.bpoint.BPOINT.API import TransactionRequest,Credentials,TransactionSearchRequest, AddDVTokenRequest
from ledger.payments.bpoint.BPOINT.API import (TransactionRequest,
Credentials,
TransactionSearchRequest,
AddDVTokenRequest,
DeleteDVTokenRequest)

class Gateway(object):

Expand Down Expand Up @@ -66,6 +70,8 @@ def handle_txn(self,order_num,reference,action,amount,card_details,biller_code,_

return txn.submit()


def delete_token(self,token):
req = DeleteDVTokenRequest(self.credentials,token)
return req.submit()


10 changes: 9 additions & 1 deletion ledger/payments/invoice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.db.models.functions import Coalesce
from django.conf import settings
from django.utils.encoding import python_2_unicode_compatible
from django.core.exceptions import ValidationError
from oscar.apps.order.models import Order
from ledger.payments.bpay.crn import getCRN
from ledger.payments.bpay.models import BpayTransaction
Expand Down Expand Up @@ -141,7 +142,7 @@ def make_payment(self):
card_details[0],
card_details[1]
)
return bpoint_facade.pay_with_temptoken(
txn = bpoint_facade.pay_with_temptoken(
'payment',
'telephoneorder',
'single',
Expand All @@ -151,5 +152,12 @@ def make_payment(self):
self.amount,
None
)
if txn.approved:
bpoint_facade.delete_token(self.token)
self.token = ''
self.save()
return txn
else:
raise ValidationError('This invoice doesn\'t have any tokens attached to it.')
except:
raise
1 change: 0 additions & 1 deletion ledger/payments/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def _create_invoice(invoice_buffer, invoice):
]
)
for discount in discounts:
print discount.__dict__
data.append(
[
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
</tr>
<tr>
<td>Invoice Number</td>
<td>{{invoice.id}}</td>
<td>{{invoice.number}}</td>
</tr>
<tr>
<td>Total (AUD)</td>
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Django<1.10.0
https://static.dpaw.wa.gov.au/static/py/dpaw-utils/dist/dpaw-utils-0.3a7.tar.gz
django-oscar>=1.1
django-oscar>=1.3
git+https://github.com/scottp-dpaw/python-social-auth@securityfix#egg=python-social-auth
mixer>=5.4.1
coverage>=4.0.3
Expand Down

0 comments on commit d51a43b

Please sign in to comment.