def redeem(order_number, user, allocations): """ Settle payment for the passed set of account allocations Will raise UnableToTakePayment if any of the transfers is invalid """ # First, we need to check if the allocations are still valid. The accounts # may have changed status since the allocations were written to the # session. transfers = [] destination = core.redemptions_account() for code, amount in allocations.items(): try: account = Account.active.get(code=code) except Account.DoesNotExist: raise UnableToTakePayment( _("No active account found with code %s") % code) # We verify each transaction try: Transfer.objects.verify_transfer(account, destination, amount, user) except exceptions.AccountException, e: raise UnableToTakePayment(str(e)) transfers.append((account, destination, amount))
def _get_and_verify_transfers(order_number, user, allocations): """ Check if the allocations are still valid; the accounts may have changed status since the allocations were written to the session. Will raise UnableToTakePayment if any of the transfers is invalid. """ transfers = [] destination = core.redemptions_account() for code, amount in allocations.items(): try: account = Account.active.get(code=code) except Account.DoesNotExist: logger.warning("Verification failed for transfer of %s from " "unknown account (%s) for order #%s", amount, account.code, order_number) raise UnableToTakePayment( _("No active account found with code %s") % code) # We verify each transaction try: Transfer.objects.verify_transfer( account, destination, amount, user) except exceptions.AccountException, e: logger.warning("Verification failed for transfer of %s from '%s' " "(%s) for order #%s", amount, account.name, account.code, order_number) raise UnableToTakePayment(str(e)) transfers.append((account, destination, amount)) logger.info("Verified transfer of %s from '%s' (%s) for order #%s", amount, account.name, account.code, order_number)
def redeem(order_number, user, allocations): """ Settle payment for the passed set of account allocations Will raise UnableToTakePayment if any of the transfers is invalid """ # First, we need to check if the allocations are still valid. The accounts # may have changed status since the allocations were written to the # session. transfers = [] destination = core.redemptions_account() for code, amount in allocations.items(): try: account = Account.active.get(code=code) except Account.DoesNotExist: raise UnableToTakePayment( _("No active account found with code %s") % code) # We verify each transaction try: Transfer.objects.verify_transfer( account, destination, amount, user) except exceptions.AccountException as e: raise UnableToTakePayment(str(e)) transfers.append((account, destination, amount)) # All transfers verified, now redeem for account, destination, amount in transfers: facade.transfer(account, destination, amount, user=user, merchant_reference=order_number, description="Redeemed to pay for order %s" % order_number)
def redeem(order_number, user, allocations): """ Is a variation of accounts.checkout.gateway.redeem, which uses pk instead of code in allocations. Also validates that the type is 6 :: deferred Settle payment for the passed set of account allocations Will raise UnableToTakePayment if any of the transfers is invalid """ # First, we need to check if the allocations are still valid. The accounts # may have changed status since the allocations were written to the # session. transfers = [] destination = core.redemptions_account() for id, amount in allocations.items(): try: account = Account.active.get(pk=id) except Account.DoesNotExist: raise JSONAPIException(status='422', code='ACCOUNT_REDEMPTION_DNE', title='Account Does Not Exist', detail="Account "+str(id)+" does not exist") if account.account_type.id != 6: raise JSONAPIException(status='422', code='ACCOUNT_REDEMPTION_MISTYPE', title='Account Type Is Invalid', detail="Account "+str(id)+" is not a valid type for redemption") # We verify each transaction try: Transfer.objects.verify_transfer( account, destination, amount, user) except exceptions.AccountException as e: raise JSONAPIException(status='422', code='ACCOUNT_REDEMPTION_FAIL', title='Account Redemption Failed', detail="Account redemption failed: "+str(e)) transfers.append((account, destination, amount)) # All transfers verified, now redeem for account, destination, amount in transfers: facade.transfer(account, destination, amount, user=user, merchant_reference=order_number, description="Redeemed to pay for order %s" % order_number)