diff --git a/ledger/payments/bpoint/facade.py b/ledger/payments/bpoint/facade.py index f5bcdc8a28..cc9abdc2bd 100644 --- a/ledger/payments/bpoint/facade.py +++ b/ledger/payments/bpoint/facade.py @@ -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 @@ -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 @@ -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)) diff --git a/ledger/payments/bpoint/models.py b/ledger/payments/bpoint/models.py index d1c747cec2..4d62d01ce9 100644 --- a/ledger/payments/bpoint/models.py +++ b/ledger/payments/bpoint/models.py @@ -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