def handle_payment(self, order_number, total, **kwargs): # Override payment method to use accounts to pay for the order allocations = self.get_account_allocations() if allocations.total < total.incl_tax: raise exceptions.UnableToTakePayment( "Your account allocations do not cover the order total") try: transactions = gateway.redeem( order_number, self.request.user, allocations) except act_exceptions.AccountException: raise exceptions.UnableToTakePayment( "An error occurred with the account redemption") # flush session allocations # self.set_account_allocations(Allocations()) # If we get here, payment was successful. We record the payment # sources and event to complete the audit trail for this order source_type, __ = SourceType.objects.get_or_create( name="Account") for code, amount in allocations.items(): source = Source( source_type=source_type, amount_debited=amount, reference=code) self.add_payment_source(source) self.add_payment_event("Settled", total.incl_tax, reference=transactions[0])
def handle_payment(self, order_number, total, **kwargs): # Override payment method to use accounts to pay for the order allocations = self.get_account_allocations() if allocations.total != total: raise exceptions.UnableToTakePayment( "Your account allocations do not cover the order total") gateway.redeem(order_number, self.request.user, allocations) # If we get here, payment was successful. We record the payment # sources and event to complete the audit trail for this order source_type, __ = SourceType.objects.get_or_create( name="Account") for code, amount in allocations.items(): source = Source( source_type=source_type, amount_debited=amount, reference=code) self.add_payment_source(source) self.add_payment_event("Settle", total)