Skip to content

Commit

Permalink
Merge pull request #240 from rayrayndwiga/master
Browse files Browse the repository at this point in the history
Ledger: fixes
  • Loading branch information
dbca-asi committed Oct 26, 2017
2 parents 24ca9b3 + 8c8d4a9 commit 9986fac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
31 changes: 16 additions & 15 deletions ledger/payments/bpoint/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def request_token(self,reference,bank_card=None):

return res

def post_transaction(self, action,_type,sub_type,order_number=None,reference=None,total=None,bankcard=None,orig_txn_number=None):
def post_transaction(self, action,_type,sub_type,order_number=None,reference=None,total=None,bankcard=None,orig_txn_number=None,replay=False):
'''Create a new transaction.
Actions are:
payment - Debit the card immediately
Expand All @@ -164,18 +164,19 @@ def post_transaction(self, action,_type,sub_type,order_number=None,reference=Non
try:
if reference:
inv = Invoice.objects.get(reference=reference)
if action in ['reversal','refund'] and inv.payment_status == 'unpaid':
raise ValidationError("A {} cannot be made for an unpaid invoice.".format(action))
if action == 'refund' and (inv.payment_amount < decimal.Decimal(total)):
raise ValidationError("A refund greater than the amount paid for the invoice cannot be made.")
if inv.payment_status == 'paid' and action == 'payment':
raise ValidationError('This invoice has already been paid for.')
if inv.voided and action not in ['refund','unmatched_refund']:
raise ValidationError('You cannot make a payment for an invoice that has been voided.')
if (decimal.Decimal(total) > inv.balance) and action == 'payment':
raise ValidationError('The amount to be charged is more than the amount payable for this invoice.')

txn = self._submit_info(order_number,reference,total,action,_type,sub_type,bankcard,orig_txn_number)
if not replay:
if action in ['reversal','refund'] and inv.payment_status == 'unpaid':
raise ValidationError("A {} cannot be made for an unpaid invoice.".format(action))
if action == 'refund' and (inv.payment_amount < decimal.Decimal(total)):
raise ValidationError("A refund greater than the amount paid for the invoice cannot be made.")
if inv.payment_status == 'paid' and action == 'payment':
raise ValidationError('This invoice has already been paid for.')
if inv.voided and action not in ['refund','unmatched_refund']:
raise ValidationError('You cannot make a payment for an invoice that has been voided.')
if (decimal.Decimal(total) > inv.balance) and action == 'payment':
raise ValidationError('The amount to be charged is more than the amount payable for this invoice.')

txn = self._submit_info(order_number,reference,total,action,_type,sub_type,bankcard,orig_txn_number,replay=replay)
self.friendly_error_msg(txn)

return txn
Expand Down Expand Up @@ -224,11 +225,11 @@ def pay_with_storedtoken(self,action,_type,sub_type,token_id,order_number=None,r
except BpointToken.DoesNotExist as e:
raise UnableToTakePayment(str(e))

def pay_with_temptoken(self,action,_type,sub_type,token,order_number=None,reference=None,total=None,orig_txn_number=None):
def pay_with_temptoken(self,action,_type,sub_type,token,order_number=None,reference=None,total=None,orig_txn_number=None,replay=False):
''' Make a payment using a temp token
'''
try:
return self.post_transaction(action,_type,sub_type,order_number,reference,total,token,orig_txn_number)
return self.post_transaction(action,_type,sub_type,order_number,reference,total,token,orig_txn_number,replay=replay)
except BpointToken.DoesNotExist as e:
raise UnableToTakePayment(str(e))

Expand Down
22 changes: 22 additions & 0 deletions ledger/payments/bpoint/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,28 @@ def refundable_amount(self):

# Methods
# ==============================
def replay_transaction(self):
from ledger.payments.facade import bpoint_facade

if self.action != 'payment':
raise ValidationError('Cant replay non payment transactions')

card = TempBankCard(
self.dvtoken,
None
)
card.last_digits = self.last_digits
txn = bpoint_facade.pay_with_temptoken(
'payment',
'internet',
'single',
card,
self.order,
self.crn1,
self.amount,
None
)

def refund(self,info,user,matched=True):
from ledger.payments.facade import bpoint_facade
from ledger.payments.models import TrackRefund, Invoice
Expand Down

0 comments on commit 9986fac

Please sign in to comment.