def make_payment(self): ''' Pay this invoice with the token attached to it. :return: BpointTransaction ''' from ledger.payments.facade import bpoint_facade try: if self.token: card_details = self.token.split('|') card = TempBankCard(card_details[0], card_details[1]) txn = bpoint_facade.pay_with_temptoken( 'payment', 'telephoneorder', 'single', card, self.order_number, self.reference, self.amount, None) if txn.approved: try: BpointToken.objects.get(DVToken=card_details[0]) self.token = '' self.save() except BpointToken.DoesNotExist: UsedBpointToken.objects.create(DVToken=card_details[0]) self.token = '' self.save() return txn else: raise ValidationError( 'This invoice doesn\'t have any tokens attached to it.') except Exception as e: print(str(e)) raise
def make_payment(self): ''' Pay this invoice with the token attached to it. :return: BpointTransaction ''' from ledger.payments.facade import bpoint_facade try: if self.token: card_details = self.token.split('|') card = TempBankCard( card_details[0], card_details[1] ) txn = bpoint_facade.pay_with_temptoken( 'payment', 'telephoneorder', 'single', card, self.order_number, self.reference, 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
def refund(self, info, user, matched=True): from ledger.payments.facade import bpoint_facade from ledger.payments.models import TrackRefund, Invoice LEDGER_REFUND_EMAIL = env('LEDGER_REFUND_EMAIL', False) with transaction.atomic(): amount = info['amount'] details = info['details'] try: txn = None if self.action == 'payment' or self.action == 'capture': card_details = self.dvtoken.split('|') card = TempBankCard(self.dvtoken, None) card.last_digits = self.last_digits if self.approved: if amount <= self.refundable_amount: txn = bpoint_facade.pay_with_temptoken( 'refund' if matched else 'unmatched_refund', 'telephoneorder', 'single', card, self.order, self.crn1, amount, self.txn_number) if txn.approved: try: BpointToken.objects.get( DVToken=txn.dvtoken) except BpointToken.DoesNotExist: UsedBpointToken.objects.create( DVToken=txn.dvtoken) TrackRefund.objects.create(user=user, type=2, refund_id=txn.id, details=details) if LEDGER_REFUND_EMAIL is True: # Disabled as requested by Walter and then enabled again for parkstay send_refund_email( Invoice.objects.get( reference=self.crn1), 'card', txn.amount, card_ending=self.last_digits) else: raise ValidationError( 'The refund amount is greater than the amount refundable on this card.' ) else: raise ValidationError( 'A refund cannot be made to an unnapproved tranascation.' ) else: raise ValidationError( 'The transaction has to be either a payment or capture in order to make a refund.' ) return txn except: raise
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, replay=True)
def refund(self,info,user,matched=True): from ledger.payments.facade import bpoint_facade from ledger.payments.models import TrackRefund, Invoice with transaction.atomic(): amount = info['amount'] details = info['details'] try: txn = None if self.action == 'payment' or self.action == 'capture': card_details = self.dvtoken.split('|') card = TempBankCard( self.dvtoken, None ) card.last_digits = self.last_digits if self.approved: if amount <= self.refundable_amount: txn = bpoint_facade.pay_with_temptoken( 'refund' if matched else 'unmatched_refund', 'telephoneorder', 'single', card, self.order, self.crn1, amount, self.txn_number ) if txn.approved: try: BpointToken.objects.get(DVToken=txn.dvtoken) except BpointToken.DoesNotExist: UsedBpointToken.objects.create(DVToken=txn.dvtoken) TrackRefund.objects.create(user=user,type=2,refund_id=txn.id,details=details) send_refund_email(Invoice.objects.get(reference=self.crn1),'card',txn.amount,card_ending=self.last_digits) else: raise ValidationError('The refund amount is greater than the amount refundable on this card.') else: raise ValidationError('A refund cannot be made to an unnapproved tranascation.') else: raise ValidationError('The transaction has to be either a payment or capture in order to make a refund.') return txn except: raise
def make_payment(self): ''' Pay this invoice with the token attached to it. :return: BpointTransaction ''' from ledger.payments.facade import bpoint_facade from ledger.payments.utils import update_payments try: if self.token: card_details = self.token.split('|') card = TempBankCard( card_details[0], card_details[1] ) if len(card_details) == 3: card.last_digits = card_details[2] else: card.last_digits = None txn = bpoint_facade.pay_with_temptoken( 'payment', 'telephoneorder', 'single', card, self.order_number, self.reference, self.amount, None ) if txn.approved: try: BpointToken.objects.get(DVToken=card_details[0]) self.token = '' self.save() except BpointToken.DoesNotExist: UsedBpointToken.objects.create(DVToken=card_details[0]) self.token = '' self.save() update_payments(self.reference) return txn else: raise ValidationError('This invoice doesn\'t have any tokens attached to it.') except Exception as e: traceback.print_exc() raise
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, replay=True )