Esempio n. 1
0
 /// <summary>
 /// Illustrate Member.getTransfer
 /// </summary>
 /// <param name="payer">payer Token member</param>
 /// <param name="transferId">id of a transfer</param>
 /// <returns>a Transfer</returns>
 public static Transfer GetTransferSample(
     UserMember payer,
     string transferId)
 {
     Transfer transfer = payer.GetTransferBlocking(transferId);
     return transfer;
 }
Esempio n. 2
0
        /// <summary>
        /// Adds, removes, and resolves aliases.
        /// </summary>
        /// <param name="tokenClient">token client</param>
        /// <param name="member">member</param>
        /// <returns>resolved member ID and alias</returns>
        public static TokenMember Aliases(Tokenio.User.TokenClient tokenClient, UserMember member)
        {
            Alias alias1 = member.GetFirstAliasBlocking();

            Alias alias2 = new Alias
            {
                Type  = Alias.Types.Type.Email,
                Value = "alias2-" + Util.Nonce() + "*****@*****.**"
            };

            // add the alias
            member.AddAliasBlocking(alias2);

            Alias alias3 = new Alias
            {
                Type  = Alias.Types.Type.Email,
                Value = "alias3-" + Util.Nonce() + "*****@*****.**"
            };

            Alias alias4 = new Alias
            {
                Type  = Alias.Types.Type.Email,
                Value = "alias4-" + Util.Nonce() + "*****@*****.**"
            };

            member.AddAliasesBlocking((new[] { alias3, alias4 }).ToList());
            // remove the alias
            member.RemoveAliasBlocking(alias1);

            member.RemoveAliasesBlocking((new[] { alias2, alias3 }).ToList());

            TokenMember resolved = tokenClient.ResolveAliasBlocking(alias4);

            return(resolved);
        }
Esempio n. 3
0
        public void RecoveryComplex()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                MemberRecoverySample mrs = new MemberRecoverySample();

                Tokenio.User.TokenClient agentTokenIO = TestUtil.CreateClient();
                Alias      agentAlias  = TestUtil.RandomAlias();
                UserMember agentMember = agentTokenIO.CreateMemberBlocking(agentAlias);

                mrs.agentMember = agentMember;

                // set up
                Alias      originalAlias  = TestUtil.RandomAlias();
                UserMember originalMember = tokenClient.CreateMemberBlocking(originalAlias);
                mrs.SetUpComplexRecoveryRule(originalMember, tokenClient, agentAlias);

                // recover
                Tokenio.User.TokenClient otherTokenClient = TestUtil.CreateClient();
                UserMember recoveredMember = mrs.RecoverWithComplexRule(
                    otherTokenClient,
                    originalAlias);
                // make sure it worked
                Alias recoveredAlias = recoveredMember.GetFirstAliasBlocking();
                Assert.Equal(recoveredAlias, originalAlias);
            }
        }
Esempio n. 4
0
        public void GetTransactionsTest()
        {
            using (Tokenio.Tpp.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember payer      = TestUtil.CreateUserMember();
                Alias      payeeAlias = TestUtil.RandomAlias();
                TppMember  payee      = tokenClient.CreateMemberBlocking(payeeAlias);

                Account payeeAccount = payee.CreateTestBankAccountBlocking(1000, "EUR");

                Token token = TestUtil.CreateTransferToken(payer, payeeAlias);

                Transfer transfer = RedeemTransferTokenSample.RedeemTransferToken(
                    payee,
                    payeeAccount.Id(),
                    token.Id);

                string      transactionId = transfer.TransactionId;
                Transaction transaction   = payer.GetTransactionBlocking(
                    payer.GetAccountsBlocking()[0].Id(),
                    transactionId,
                    Key.Types.Level.Standard);
                Assert.Equal(transaction.TokenId, token.Id);
            }
        }
Esempio n. 5
0
        }                                                           /* this simple sample uses a no op */

        /// <summary>
        /// Illustrate setting up a recovery rule more complex than "normal consumer"
        /// mode, without the "normal consumer" shortcuts.
        /// </summary>
        /// <param name="newMember">newly-created member we are setting up</param>
        /// <param name="tokenClient">SDK client</param>
        /// <param name="agentAlias">Alias of recovery agent.</param>
        public void SetUpComplexRecoveryRule(
            UserMember newMember,
            Tokenio.User.TokenClient tokenClient,
            Alias agentAlias)
        {
            // setUpComplex begin snippet to include in docs
            // Someday in the future, this user might ask the recovery agent
            // "Please tell Token that I am the member with ID m:12345678 ."
            // While we're setting up this new member, we need to tell the
            // recovery agent the new member ID so the agent can "remember" later.
            TellRecoveryAgentMemberId(newMember.MemberId());

            string agentId = tokenClient.GetMemberIdBlocking(agentAlias);

            RecoveryRule recoveryRule = new RecoveryRule {
                PrimaryAgent = agentId
            };

            // This example doesn't call .setSecondaryAgents ,
            // but could have. If it had, then recovery would have
            // required one secondary agent authorization along with
            // the primary agent authorization.
            newMember.AddRecoveryRuleBlocking(recoveryRule);
            // setUpComplex done snippet to include in docs
        }
Esempio n. 6
0
        public void RedeemTransactionsAccessTokenTest()
        {
            using (var tokenClient = TestUtil.CreateClient())
            {
                UserMember grantor      = TestUtil.CreateUserMember();
                string     accountId    = grantor.GetAccountsBlocking()[0].Id();
                Alias      granteeAlias = TestUtil.RandomAlias();
                TppMember  grantee      = tokenClient.CreateMemberBlocking(granteeAlias);

                // make some transactions
                Alias     payeeAlias   = TestUtil.RandomAlias();
                TppMember payee        = tokenClient.CreateMemberBlocking(payeeAlias);
                var       payeeAccount = payee.CreateTestBankAccountBlocking(1000, "EUR");
                for (int i = 0; i < 5; i++)
                {
                    Token token = CreateTransferTokenSample.CreateTransferToken(
                        grantor,
                        payeeAlias,
                        Key.Types.Level.Standard);
                    RedeemTransferTokenSample.RedeemTransferToken(
                        payee,
                        payeeAccount.Id(),
                        token.Id);
                }

                Token accessToken =
                    CreateAndEndorseAccessTokenSample.CreateTransactionsAccessToken(grantor, accountId, granteeAlias);
                IList <Transaction> transactions =
                    RedeemAccessTokenSample.RedeemTransactionsAccessToken(grantee, accessToken.Id);

                Assert.Equal(5, transactions.Count);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a payment request (a transfer token payload)
        /// and sends it to a potential payer.
        /// </summary>
        /// <param name="tokenClient">initialized SDK</param>
        /// <param name="payee">payee Token member</param>
        /// <param name="payerAlias">payer Token member alias</param>
        /// <returns>a transfer Token</returns>
        public static NotifyStatus NotifyPaymentRequest(
            Tokenio.User.TokenClient tokenClient,
            UserMember payee,
            Alias payerAlias)
        {
            // We'll use this as a reference ID. Normally, a payee who
            // explicitly sets a reference ID would use an ID from a db.
            // E.g., an online merchant might use the ID of a "shopping cart".
            // We don't have a db, so we fake it with a random string:
            string       cartId         = Util.Nonce();
            TokenPayload paymentRequest = new TokenPayload
            {
                Description = "Sample payment request",
                From        = new TokenMember {
                    Alias = payerAlias
                },
                To = new TokenMember {
                    Alias = payee.GetFirstAliasBlocking()
                },
                Transfer = new TransferBody {
                    Amount = "100.00", Currency = "EUR"
                },
                RefId = cartId
            };


            NotifyStatus status = tokenClient.NotifyPaymentRequestBlocking(paymentRequest);

            return(status);
        }
Esempio n. 8
0
        public void RedeemStandingOrdersAccessTokenTest()
        {
            using (var tokenClient = TestUtil.CreateClient())
            {
                UserMember grantor      = TestUtil.CreateUserMember();
                string     accountId    = grantor.GetAccountsBlocking()[0].Id();
                Alias      granteeAlias = TestUtil.RandomAlias();
                TppMember  grantee      = tokenClient.CreateMemberBlocking(granteeAlias);

                // make some standing orders
                Alias     payeeAlias = TestUtil.RandomAlias();
                TppMember payee      = tokenClient.CreateMemberBlocking(payeeAlias);
                for (int i = 0; i < 5; i++)
                {
                    Token token = CreateStandingOrderTokenSample.CreateStandingOrderToken(
                        grantor,
                        payeeAlias,
                        Key.Types.Level.Standard);
                    RedeemStandingOrderTokenSample.RedeemStandingOrderToken(
                        payee,
                        token.Id);
                }

                Token accessToken =
                    CreateAndEndorseAccessTokenSample.CreateStandingOrdersAccessToken(grantor, accountId, granteeAlias);
                IList <StandingOrder> standingOrders =
                    RedeemAccessTokenSample.RedeemStandingOrdersAccessToken(grantee, accessToken.Id);

                Assert.Equal(5, standingOrders.Count);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Gets a list of access tokens associated with the member.
        /// </summary>
        /// <param name="member">member</param>
        /// <returns>paged list of access tokens</returns>
        public static PagedList <Token> GetAccessTokens(UserMember member)
        {
            // last 10 tokens and offset that can be used to get the next 10
            PagedList <Token> pagedList = member.GetAccessTokensBlocking("", 10);

            return(pagedList);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates the member and link accounts.
        /// </summary>
        /// <returns>The member and link accounts.</returns>
        /// <param name="client">Client.</param>
        public static UserMember CreateMemberAndLinkAccounts(Tokenio.User.TokenClient client)
        {
            Alias      alias  = RandomAlias();
            UserMember member = client.CreateMemberBlocking(alias);

            LinkMemberAndBankSample.LinkBankAccounts(member);
            return(member);
        }
Esempio n. 11
0
        /// <summary>
        /// Log in on provisioned device (assuming "remote" member approved key).
        /// </summary>
        /// <param name="tokenClient">SDK client</param>
        /// <param name="alias">member's alias</param>
        /// <returns>Member</returns>
        public static UserMember UseProvisionedDevice(Tokenio.User.TokenClient tokenClient, Alias alias)
        {
            string memberId = tokenClient.GetMemberIdBlocking(alias);
            // Uses the key that remote member approved (we hope)
            UserMember member = tokenClient.GetMemberBlocking(memberId);

            return(member);
        }
        /// <summary>
        /// Cancels a transfer token.
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="tokenId">token ID to cancel</param>
        /// <returns>operation result</returns>
        public static TokenOperationResult CancelTransferToken(UserMember payer, string tokenId)
        {
            // Retrieve a transfer token to cancel.
            Token transferToken = payer.GetTokenBlocking(tokenId);

            // Cancel transfer token.
            return(payer.CancelTokenBlocking(transferToken));
        }
Esempio n. 13
0
        /// <summary>
        /// Cancels an access token.
        /// </summary>
        /// <param name="grantor">grantor Token member</param>
        /// <param name="tokenId">token ID to cancel</param>
        /// <returns>operation result</returns>
        public static TokenOperationResult CancelAccessToken(UserMember grantor, string tokenId)
        {
            // Retrieve an access token to cancel.
            Token accessToken = grantor.GetTokenBlocking(tokenId);

            // Cancel access token.
            return(grantor.CancelTokenBlocking(accessToken));
        }
Esempio n. 14
0
        /// <summary>
        /// Get a member's list of balances.
        /// </summary>
        /// <param name="member">Member.</param>
        /// <returns>list of balances</returns>
        public static IList <Balance> MemberGetBalanceListSample(UserMember member)
        {
            List <string> accountIds = member
                                       .GetAccountsBlocking().Select(acc => acc.Id()).ToList();

            var balances = member.GetBalancesBlocking(accountIds, Key.Types.Level.Standard);

            return(balances);
        }
Esempio n. 15
0
 public void CreatePaymentTokenWithOtherOptionsTest()
 {
     using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
     {
         UserMember payer = TestUtil.CreateMemberAndLinkAccounts(tokenClient);
         UserMember payee = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());
         Token      token = CreateTransferTokenSample.CreateTransferTokenWithOtherOptions(payer, payee.MemberId());
         Assert.NotNull(token);
     }
 }
Esempio n. 16
0
        public void ProfilesTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember member  = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());
                Profile    profile = MemberMethodsSample.Profiles(member);

                Assert.NotEmpty(profile.DisplayNameFirst);
            }
        }
Esempio n. 17
0
        public void AccountGetBalanceSampleTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember member = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());
                member.CreateTestBankAccountBlocking(1000.0, "EUR");

                var sums = GetBalanceSample.AccountGetBalanceSample(member);
                Assert.Equal(1000.0, sums["EUR"]);
            }
        }
Esempio n. 18
0
 public void CreatePaymentTokenScheduledTest()
 {
     using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
     {
         UserMember payer      = TestUtil.CreateMemberAndLinkAccounts(tokenClient);
         Alias      payeeAlias = TestUtil.RandomAlias();
         UserMember payee      = tokenClient.CreateMemberBlocking(payeeAlias);
         Token      token      = CreateTransferTokenSample.CreateTransferTokenScheduled(payer, payeeAlias);
         Assert.NotNull(token);
     }
 }
Esempio n. 19
0
        public void LinkMemberAndBankTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember member = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());

                LinkMemberAndBankSample.LinkBankAccounts(member);

                Assert.NotEmpty(member.GetAccountsBlocking());
            }
        }
Esempio n. 20
0
        public void KeysTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                IKeyStore     keyStore     = new InMemoryKeyStore();
                ICryptoEngine cryptoEngine = new TokenCryptoEngine("member-id", keyStore);

                UserMember member = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());
                MemberMethodsSample.Keys(cryptoEngine, member);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Illustrate Account.getTransaction
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="transfer">recently-completed transfer</param>
        /// <returns>a Transaction</returns>
        public static Transaction AccountGetTransactionSample(
            UserMember payer,
            Transfer transfer)
        {
            Tokenio.User.Account account = payer.GetAccountsBlocking()[0];

            string      txnId       = transfer.TransactionId;
            Transaction transaction = account.GetTransactionBlocking(txnId, Level.Standard);

            return(transaction);
        }
Esempio n. 22
0
 public void CancelTransferTokenByGrantorTest()
 {
     using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
     {
         UserMember           payer        = TestUtil.CreateMemberAndLinkAccounts(tokenClient);
         Alias                granteeAlias = TestUtil.RandomAlias();
         UserMember           payee        = tokenClient.CreateMemberBlocking(granteeAlias);
         Token                token        = CreateTransferTokenSample.CreateTransferToken(payer, granteeAlias, Level.Low);
         TokenOperationResult result       = CancelTokenSample.CancelTransferToken(payer, token.Id);
         Assert.Equal(TokenOperationResult.Types.Status.Success, result.Status);
     }
 }
        public void CancelTransferTokenByGranteeTest()
        {
            using (Tokenio.Tpp.TokenClient tokenClient = TestUtil.CreateClient()) {
                UserMember grantor      = TestUtil.CreateUserMember();
                Alias      granteeAlias = TestUtil.RandomAlias();
                TppMember  grantee      = tokenClient.CreateMemberBlocking(granteeAlias);

                Token token = TestUtil.CreateTransferToken(grantor, granteeAlias);
                TokenOperationResult result = CancelTransferTokenSample.CancelTransferToken(grantee, token.Id);
                Assert.Equal(result.Status, TokenOperationResult.Types.Status.Success);
            }
        }
Esempio n. 24
0
        public void AliasesTest()
        {
            using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
            {
                UserMember member = tokenClient.CreateMemberBlocking(TestUtil.RandomAlias());
                MemberMethodsSample.Aliases(tokenClient, member);
                List <Alias> aliases = member.GetAliasesBlocking().ToList();

                Assert.Equal(1, aliases.Count);
                Assert.Contains("alias4", aliases[0].Value);
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Gets a token by ID.
        /// </summary>
        /// <param name="member">member represented by the token (payer/payee/grantor/grantee)</param>
        /// <param name="tokenId">token ID</param>
        /// <returns>token</returns>
        public static Token GetToken(UserMember member, string tokenId)
        {
            Token token = member.GetTokenBlocking(tokenId);

            // get token payload
            TokenPayload payload = token.Payload;

            // get signatures
            var signatures = token.PayloadSignatures;

            return(token);
        }
Esempio n. 26
0
 public void CreateStandingOrderTokenTest()
 {
     using (Tokenio.User.TokenClient tokenClient = TestUtil.CreateClient())
     {
         UserMember payer      = TestUtil.CreateMemberAndLinkAccounts(tokenClient);
         Alias      payeeAlias = TestUtil.RandomAlias();
         UserMember payee      = tokenClient.CreateMemberBlocking(payeeAlias);
         Token      token      =
             CreateStandingOrderTokenSample.CreateStandingOrderToken(payer, payeeAlias, Level.Standard);
         Assert.NotNull(token);
     }
 }
Esempio n. 27
0
        /// <summary>
        /// Redeems a standing order token to make a series of transfers from payer bank account
        /// to payee bank account.
        /// </summary>
        /// <param name="payee">payee Token member</param>
        /// <param name="tokenId">ID of the token to redeem</param>
        /// <returns>standing order submission record</returns>
        public static StandingOrderSubmission RedeemStandingOrderToken(
            UserMember payee,
            string tokenId) // ID of token to redeem
        {
            // Retrieve a standing order token to redeem.
            Token token = payee.GetTokenBlocking(tokenId);
            // Payee redeems a standing order token.
            // Money is transferred in many installments to a payee bank account.
            StandingOrderSubmission submission = payee.RedeemStandingOrderTokenBlocking(token.Id);

            return(submission);
        }
Esempio n. 28
0
 /// <summary>
 /// Illustrate Account.getTransactions
 /// </summary>
 /// <param name="payer">payer Token member</param>
 public static void AccountGetTransactionsSample(UserMember payer)
 {
     Tokenio.User.Account account = payer.GetAccountsBlocking()[0];
     foreach (Transaction transaction in account.GetTransactionsBlocking(null, 10, Level.Standard).List)
     {
         DisplayTransaction(
             transaction.Amount.Currency,
             transaction.Amount.Value,
             transaction.Type,        // debit or credit
             transaction.Status);
     }
 }
Esempio n. 29
0
        /// <summary>
        /// Illustrate Member.getTransaction
        /// </summary>
        /// <param name="payer">payer Token member</param>
        /// <param name="transfer">recently-completed transfer</param>
        /// <returns>a Transaction</returns>
        public static Transaction GetTransactionSample(
            UserMember payer,
            Transfer transfer)
        {
            List <Tokenio.User.Account> accounts = payer.GetAccountsBlocking().ToList();
            string accountId = accounts[0].Id();

            string      transactionId = transfer.TransactionId;
            Transaction transaction   = payer.GetTransactionBlocking(accountId, transactionId, Level.Standard);

            return(transaction);
        }
Esempio n. 30
0
        public void CancelAccessTokenByGranteeTest()
        {
            using  (Tokenio.Tpp.TokenClient tokenClient = TestUtil.CreateClient()) {
                Tokenio.User.Member grantor = TestUtil.CreateUserMember();
                string    accountId         = grantor.GetAccountsBlocking()[0].Id();
                Alias     granteeAlias      = TestUtil.RandomAlias();
                TppMember grantee           = tokenClient.CreateMemberBlocking(granteeAlias);

                Token token = TestUtil.CreateAccessToken(grantor, accountId, granteeAlias);
                TokenOperationResult result = CancelAccessTokenSample.CancelAccessToken(grantee, token.Id);
                Assert.Equal(result.Status, TokenOperationResult.Types.Status.Success);
            }
        }