Example #1
0
        public void SyncUnclaimedPayoutTest()
        {
            var ps = PaySystemSync;

            var amount = new Amount("USD", 1.0m);
            var from   = new Account("SYSTEM", 111, 222);
            var to     = new Account("USER", 111, 222);

            object id = null;

            using (var session = ps.StartSession())
            {
                session.StoreAccountData(new ActualAccountData(from)
                {
                    Identity   = from.Identity,
                    IdentityID = from.IdentityID,
                    AccountID  = from.AccountID
                });

                session.StoreAccountData(new ActualAccountData(to)
                {
                    Identity   = from.Identity,
                    IdentityID = from.IdentityID,
                    AccountID  = "*****@*****.**"
                });

                var tran = session.Transfer(from, to, amount);
                Assert.IsNotNull(tran);
                Assert.IsNotNull(tran.ID);
                Assert.IsTrue(tran.Token.AsString().Split(':').Length == 3);
                id = tran.ID;
                Assert.AreEqual(TransactionType.Transfer, tran.Type);
                Assert.AreEqual(amount, tran.Amount);
                Assert.AreEqual(from, tran.From);
                Assert.AreEqual(to, tran.To);
                Assert.AreEqual(TransactionStatus.Unclaimed, tran.Status);
            }

            var transaction = PaySystemHost.FetchTransaction(id);

            Assert.IsNotNull(transaction);
            Assert.AreEqual(TransactionType.Transfer, transaction.Type);
            Assert.AreEqual(amount, transaction.Amount);
            Assert.AreEqual(from, transaction.From);
            Assert.AreEqual(to, transaction.To);
            Assert.AreEqual(TransactionStatus.Unclaimed, transaction.Status);

            var voided = transaction.Void();

            Assert.IsTrue(voided);
            Assert.AreEqual(TransactionType.Transfer, transaction.Type);
            Assert.AreEqual(amount, transaction.Amount);
            Assert.AreEqual(from, transaction.From);
            Assert.AreEqual(to, transaction.To);
            Assert.AreEqual(TransactionStatus.Refunded, transaction.Status);
        }
Example #2
0
        public void AsyncPayoutTest()
        {
            var ps = PaySystemAsync;

            var amount = new Amount("USD", 1.0m);
            var from   = new Account("SYSTEM", 111, 222);
            var to     = new Account("USER", 111, 222);

            object id = null;

            using (var session = ps.StartSession())
            {
                session.StoreAccountData(new ActualAccountData(from)
                {
                    Identity   = from.Identity,
                    IdentityID = from.IdentityID,
                    AccountID  = from.AccountID
                });

                session.StoreAccountData(new ActualAccountData(to)
                {
                    Identity   = from.Identity,
                    IdentityID = from.IdentityID,
                    AccountID  = PaySystemHost.PaypalValidAccount
                });

                var tran = session.Transfer(from, to, amount);
                Assert.IsNotNull(tran);
                Assert.IsNotNull(tran.ID);
                id = tran.ID;
                Assert.AreEqual(TransactionType.Transfer, tran.Type);
                Assert.AreEqual(amount, tran.Amount);
                Assert.AreEqual(from, tran.From);
                Assert.AreEqual(to, tran.To);
                Assert.AreEqual(TransactionStatus.Pending, tran.Status);

                Assert.IsNotNull(session.User.AuthToken.Data); // token occured on first call
                Assert.IsInstanceOf <PayPalOAuthToken>(session.User.AuthToken.Data);

                var token = session.User.AuthToken.Data as PayPalOAuthToken;
                Assert.IsTrue(token.ObtainTime > App.TimeSource.Now.AddMinutes(-1));
                Assert.IsTrue(token.ObtainTime < App.TimeSource.Now);
                Assert.AreEqual(3600, token.ExpirationMarginSec);
                Assert.IsNotNullOrEmpty(token.ApplicationID);
                Assert.IsTrue(token.ExpiresInSec > 0);
                Assert.IsNotNullOrEmpty(token.AccessToken);
                Assert.IsNotNullOrEmpty(token.Scope);
                Assert.IsNotNullOrEmpty(token.Nonce);
            }

            var transaction = PaySystemHost.FetchTransaction(id);

            Assert.IsNotNull(transaction);
            for (int i = 0; i < 5 && (i == 0 || !transaction.Refresh()); i++)
            {
                if (i != 0)
                {
                    Console.WriteLine("...try refresh #" + i);
                }

                Assert.AreEqual(TransactionType.Transfer, transaction.Type);
                Assert.AreEqual(amount, transaction.Amount);
                Assert.AreEqual(from, transaction.From);
                Assert.AreEqual(to, transaction.To);
                Assert.AreEqual(TransactionStatus.Pending, transaction.Status);

                var sleep = ExternalRandomGenerator.Instance.NextScaledRandomInteger(5000, 10000);
                Console.WriteLine("Sleep {0} ms...".Args(sleep));
                Thread.Sleep(sleep);
            }

            Assert.IsNotNull(transaction);
            Assert.IsTrue(transaction.Token.AsString().Split(':').Length == 3);
            Assert.AreEqual(TransactionType.Transfer, transaction.Type);
            Assert.AreEqual(amount, transaction.Amount);
            Assert.AreEqual(from, transaction.From);
            Assert.AreEqual(to, transaction.To);
            Assert.AreEqual(TransactionStatus.Success, transaction.Status);
        }