/// <summary> /// Creates the transfer token. /// </summary> /// <returns>The transfer token.</returns> /// <param name="payer">Payer.</param> /// <param name="payeeAlias">Payee alias.</param> public static Token CreateTransferToken( UserMember payer, Alias payeeAlias) { // We'll use this as a reference ID. Normally, a payer who // explicitly sets a reference ID would use an ID from a db. // E.g., a bill-paying service might use ID of a "purchase". // We don't have a db, so we fake it with a random string: string purchaseId = Tokenio.User.Utils.Util.Nonce(); // Create a transfer token. var tokenPayload = payer.CreateTransferTokenBuilder( 100.0, // amount "EUR") // currency // source account: .SetAccountId(payer.GetAccountsBlocking()[0].Id()) // payee token alias: .SetToAlias(payeeAlias) // optional description: .SetDescription("Book purchase") // ref id (if not set, will get random ID) .SetRefId(purchaseId) .BuildPayload(); var transferToken = payer.CreateTokenBlocking(tokenPayload, new List <Signature>()); // Payer endorses a token to a payee by signing it // with her secure private key. transferToken = payer.EndorseTokenBlocking(transferToken, Key.Types.Level.Standard).Token; return(transferToken); }
/// <summary> /// Replaces a previously-created access token. /// </summary> /// <param name="grantor">Token member granting access to her accounts</param> /// <param name="granteeAlias">Token member alias acquiring information access</param> /// <param name="oldToken">token to replace</param> /// <returns>success or failure</returns> public static TokenOperationResult ReplaceAccessToken( UserMember grantor, Alias granteeAlias, Token oldToken) { string accountId = grantor.CreateTestBankAccountBlocking(1000.0, "EUR") .Id(); // Replace the old access token Token newToken = grantor.ReplaceAccessTokenBlocking( oldToken, AccessTokenBuilder .FromPayload(oldToken.Payload) .ForAccount(accountId)) .Token; // Endorse the new access token TokenOperationResult status = grantor.EndorseTokenBlocking(newToken, Key.Types.Level.Standard); return(status); }
/// <summary> /// Creates the access token. /// </summary> /// <returns>The access token.</returns> /// <param name="grantor">Grantor.</param> /// <param name="accountId">Account identifier.</param> /// <param name="granteeAlias">Grantee alias.</param> public static Token CreateAccessToken( UserMember grantor, string accountId, Alias granteeAlias) { // Create an access token for the grantee to access bank // account names of the grantor. Token accessToken = grantor.CreateAccessTokenBlocking( AccessTokenBuilder .Create(granteeAlias) .ForAccount(accountId) .ForAccountBalances(accountId)); // Grantor endorses a token to a grantee by signing it // with her secure private key. accessToken = grantor.EndorseTokenBlocking( accessToken, Key.Types.Level.Standard).Token; return(accessToken); }