def transaction(self): """Return a transaction that corresponds to the real transfer of value between the debit and credit accounts. The value of the transaction is the actual receipted value Returns: Transaction: Transaction corresponding to this receipt """ from Acquire.Accounting import Transaction as _Transaction if self.is_null(): return _Transaction() else: return _Transaction( self.receipted_value(), "Receipt for transaction %s" % self.transaction_uid())
def deposit(user, value, description=None, accounting_service=None, accounting_url=None): """Tell the system to allow the user to deposit 'value' from their (real) financial account to the system accounts """ authorisation = _Authorisation(user=user) if accounting_service is None: accounting_service = _get_accounting_service(accounting_url) else: if not accounting_service.is_accounting_service(): raise TypeError("You can only deposit funds using an " "accounting service!") args = {"authorisation": authorisation.to_data()} if description is None: args["value"] = str(_create_decimal(value)) else: args["transaction"] = _Transaction(value, description).to_data() privkey = _PrivateKey() result = _call_function( accounting_service.service_url(), "deposit", args=args, args_key=accounting_service.public_key(), response_key=privkey, public_cert=accounting_service.public_certificate()) return result
def transaction(self): """Return a transaction that corresponds to the real transfer of value back from the credit to debit accounts (remembering that the original debit account will be the new credit account, and the original credit account will be the new debit account). Returns: Transaction: Transaction related to this refund """ from Acquire.Accounting import Transaction as _Transaction if self.is_null(): return _Transaction() else: return _Transaction( self.value(), "Refund for transaction %s" % self.transaction_uid())
def original_transaction(self): """If this is a receipt or refund transaction then return the original transaction that this is receipting or refunding. Otherwise returns a null Transaction Returns: TransactionRecord """ if self.is_receipt() or self.is_refund(): return self.original_transaction_record().transaction() else: from Acquire.Accounting import Transaction as _Transaction return _Transaction()
def deposit(user, value, description=None, account_name=None, accounting_service=None, accounting_url=None): """Tell the system to allow the user to deposit 'value' from their (real) financial account to the system accounts Args: user (User): User to authorise value (Decimal): Value to deposit description (str): Description of deposit accounting_service (Service, default=None): Accounting service to make deposit accounting_url (str): Accounting URl Returns: TODO - return value here """ if accounting_service is None: service = _get_accounting_service(accounting_url) else: if not accounting_service.is_accounting_service(): raise TypeError("You can only deposit funds using an " "accounting service!") service = accounting_service if description is None: description = "Deposit" from Acquire.Accounting import Transaction as _Transaction transaction = _Transaction(value=value, description=description) from Acquire.Client import Authorisation as _Authorisation authorisation = _Authorisation(user=user, resource=transaction.fingerprint()) args = { "authorisation": authorisation.to_data(), "transaction": transaction.to_data() } if account_name: args["account_name"] = str(account_name) result = service.call_function(function="deposit", args=args) return result