/// <summary>
        /// Creates a transfer token using some other options.
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="payeeId">payee Token member Id</param>
        /// <returns>a transfer Token</returns>
        public static Token CreateTransferTokenWithOtherOptions(
            UserMember payer,
            string payeeId)
        {
            long now = Util.CurrentMillis();

            // Set the details of the token.
            TransferTokenBuilder builder = payer.CreateTransferTokenBuilder(
                120.0,     // amount
                "EUR")     // currency
                                           .SetAccountId(payer.GetAccountsBlocking()[0].Id())
                                           .SetToMemberId(payeeId)
                                           .SetToMemberId(payeeId)
                                           // effective in one second:
                                           .SetEffectiveAtMs(now + 1000)
                                           // expires in 300 seconds:
                                           .SetExpiresAtMs(now + (300 * 1000))
                                           .SetRefId("a713c8a61994a749")
                                           .SetChargeAmount(10.0)
                                           .SetDescription("Book purchase");

            // Get the token redemption policy and resolve the token payload.
            PrepareTokenResult result = payer.PrepareTransferTokenBlocking(builder);

            // Create the token, signing with the payer's STANDARD-level key
            Token transferToken = payer.CreateTokenBlocking(result.TokenPayload, Level.Standard);

            return(transferToken);
        }
        /// <summary>
        /// Creates transfer token to a destination.
        /// </summary>
        /// <param name="payer">Payer who has no linked bank accounts</param>
        /// <param name="payeeAlias">Alias of payee member</param>
        /// <returns>a transfer Token</returns>
        public static Token CreateTransferTokenToDestination(
            UserMember payer,
            Alias payeeAlias)
        {
            // Set SEPA destination.
            TransferDestination sepaDestination = new TransferDestination
            {
                Sepa = new TransferDestination.Types.Sepa
                {
                    Bic  = "XUIWC2489",
                    Iban = "DE89 3704 0044 0532 0130 00"
                }
            };

            // Set the destination and other details.
            TransferTokenBuilder builder =
                payer.CreateTransferTokenBuilder(
                    100.0,         // amount
                    "EUR")         // currency
                .SetAccountId(payer.GetAccountsBlocking()[0].Id())
                .SetToAlias(payeeAlias)
                .AddDestination(sepaDestination);

            // Get the token redemption policy and resolve the token payload.
            PrepareTokenResult result = payer.PrepareTransferTokenBlocking(builder);

            // Create the token, signing with the payer's STANDARD-level key
            Token transferToken = payer.CreateTokenBlocking(result.TokenPayload, Level.Standard);

            return(transferToken);
        }
Exemplo n.º 3
0
        /// <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>
        /// Creates a transfer token and authorizes a money transfer from a payer to a payee.
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="payeeAlias">payee Token member alias</param>
        /// <returns>a transfer Token</returns>
        public static Token CreateTransferToken(
            UserMember payer,
            Alias payeeAlias)
        {
            // Create an access token for the grantee to access bank
            string purchaseId = Util.Nonce();


            // Create a transfer token.
            TransferTokenBuilder builder = payer.CreateTransferTokenBuilder(
                10.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);

            PrepareTokenResult result = payer.PrepareTransferTokenBlocking(builder);

            // Payer endorses a token to a payee by signing it
            // with her secure private key.
            Token transferToken = payer.CreateTokenBlocking(
                result.TokenPayload, Key.Types.Level.Low);

            return(transferToken);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a transfer token and authorizes a money transfer from a payer to a payee.
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="payeeAlias">payee Token member alias</param>
        /// <param name="keyLevel">the level of signature to provide</param>
        /// <returns>a transfer Token</returns>
        public static Token CreateTransferToken(
            UserMember payer,
            Alias payeeAlias,
            Level keyLevel)
        {
            // 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 = Util.Nonce();
            // Set the details of the token.
            TransferTokenBuilder builder = payer.CreateTransferTokenBuilder(
                10.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);
            PrepareTokenResult result = payer.PrepareTransferTokenBlocking(builder);
            // Create the token: Default behavior is to provide the member's signature
            // at the specified level. In other cases, it may be necessary to provide
            // additional signatures with payer.createToken(payload, signatures).
            Token transferToken = payer.CreateTokenBlocking(result.TokenPayload, keyLevel);

            return(transferToken);
        }
Exemplo n.º 6
0
        public void NotifyPaymentRequestSampleTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember payer = TestUtil.CreateMemberAndLinkAccounts(tokenClient);

                UserMember           payee      = PollNotificationsSample.CreateMember(tokenClient);
                Alias                payeeAlias = payee.GetFirstAliasBlocking();
                Tokenio.User.Account account    = LinkMemberAndBankSample.LinkBankAccounts(payer);
                LinkMemberAndBankSample.LinkBankAccounts(payee);

                TransferDestination tokenDestination = new TransferDestination
                {
                    Token = new TransferDestination.Types.Token
                    {
                        MemberId = payee.MemberId()
                    }
                };

                TransferTokenBuilder builder = payer.CreateTransferTokenBuilder(100.00, "EUR")
                                               .SetAccountId(account.Id())
                                               .SetToAlias(payeeAlias)
                                               .AddDestination(tokenDestination);

                PrepareTokenResult result = payer.PrepareTransferTokenBlocking(builder);
                Token    token            = payer.CreateTokenBlocking(result.TokenPayload, Key.Types.Level.Standard);
                Transfer transfer         = payee.RedeemTokenBlocking(token);

                var notification = PollNotificationsSample.Poll(payee);

                Assert.NotNull(notification);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Finds a previously-created access token from grantor to grantee.
        /// </summary>
        /// <param name="tokenClient">initialized SDK</param>
        /// <param name="grantor">Token member granting access to her accounts</param>
        /// <param name="granteeAlias">Token member alias acquiring information access</param>
        /// <returns>an access Token</returns>
        public static Token FindAccessToken(
            Tokenio.User.TokenClient tokenClient,
            UserMember grantor,
            Alias granteeAlias)
        {
            string granteeMemberId = tokenClient.GetMemberIdBlocking(granteeAlias);

            return(grantor.GetActiveAccessTokenBlocking(granteeMemberId));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates the user member.
        /// </summary>
        /// <returns>The user member.</returns>
        public static UserMember CreateUserMember()
        {
            Tokenio.User.TokenClient
                       client = Tokenio.User.TokenClient.Create(Tokenio.TokenCluster.DEVELOPMENT, DEV_KEY);
            Alias      alias  = RandomUserAlias();
            UserMember member = client.CreateMemberBlocking(alias);

            member.CreateTestBankAccountBlocking(1000.0, "EUR");
            return(member);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a standing order  token and authorizes a money transfer from a payer to a payee.
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="payeeAlias">payee Token member alias</param>
        /// <param name="keyLevel">the level of signature to provide</param>
        /// <returns>a standing order Token</returns>
        public static Token CreateStandingOrderToken(
            UserMember payer,
            Alias payeeAlias,
            Level keyLevel)
        {
            // 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 = Util.Nonce();
            // Set SEPA destination.
            TransferDestination sepaDestination = new TransferDestination
            {
                Sepa = new TransferDestination.Types.Sepa
                {
                    Bic  = "XUIWC2489",
                    Iban = "DE89 3704 0044 0532 0130 00"
                }
            };
            // Set the details of the token.
            StandingOrderTokenBuilder builder = payer.CreateStandingOrderTokenBuilder(
                10.0,                    // amount
                "EUR",                   // currency
                "DAIL",                  // frequency of the standing order
                DateTime.Now,            // start date
                DateTime.Now.AddDays(7)) // end date
                                         // source account:
                                                .SetAccountId(payer.GetAccountsBlocking()[0].Id())
                                         // payee token alias:
                                                .SetToAlias(payeeAlias)
                                         // optional description:
                                                .SetDescription("Credit card statement payment")
                                         // ref id (if not set, will get random ID)
                                                .SetRefId(purchaseId)
                                                .AddDestination(sepaDestination);
            // Get the token redemption policy and resolve the token payload.
            PrepareTokenResult result = payer.PrepareStandingOrderTokenBlocking(builder);
            // Create the token: Default behavior is to provide the member's signature
            // at the specified level. In other cases, it may be necessary to provide
            // additional signatures with payer.createToken(payload, signatures).
            Token token = payer.CreateTokenBlocking(result.TokenPayload, keyLevel);

            return(token);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        /// <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);
        }