public string createAuthorization(WebPayPalAuthorization authorization, int currentUserId)
        {
            if ((authorization.type == "Logged-in" && currentUserId > 0)
                || (authorization.type == "Email" && currentUserId == -1)
                || (authorization.type == "Anonymous" && currentUserId == -1))
            {
                if (authorization.type == "Logged-in" && (authorization.email != null || authorization.name != null))
                {
                    throw new Exception("Incompatible email or name provided while logged-in.");
                }
                if (authorization.type == "Email" && (String.IsNullOrWhiteSpace(authorization.email) || String.IsNullOrWhiteSpace(authorization.name)))
                {
                    throw new Exception("Email or name not provided with Email type.");
                }
                if (authorization.type == "Anonymous" && (authorization.email != null || authorization.name != null))
                {
                    throw new Exception("Incompatible email or name provided with Anonymous type.");
                }
                PayPalAuthorization a = new PayPalAuthorization();
                a.guid = Guid.NewGuid().ToString();
                a.type = authorization.type;

                a.bfksRegistrationId = authorization.bfksRegistrationId;
                a.frostyRegistrationId = authorization.frostyRegistrationId;

                if (currentUserId > 0)
                {
                    a.userId = currentUserId;
                }
                else
                {
                    a.userId = null;
                }

                a.email = authorization.email;
                a.name = authorization.name;
                a.date = DateTime.UtcNow;

                db.PayPalAuthorizations.Add(a);
                db.SaveChanges();

                return a.guid;
            }
            else
            {
                throw new Exception("Invalid authorization type or currentUserId: type=" + authorization.type + ", currentUserId=" + currentUserId);
            }
        }
Ejemplo n.º 2
0
        private void addTestAuthorizations(DatabaseContext db)
        {
            PayPalAuthorization a = new PayPalAuthorization();

            a.guid = Guid.NewGuid().ToString();
            if (this.random.NextDouble() < 1.0 / 3.0)
            {
                a.type   = "Logged-in";
                a.userId = 1;
                a.email  = null;
                a.name   = null;
            }
            else if (this.random.NextDouble() < 1.0 / 3.0)
            {
                a.type   = "Email";
                a.userId = null;
                a.email  = "*****@*****.**";
                a.name   = "Foo Bar Name";
            }
            else
            {
                a.type   = "Anonymous";
                a.userId = null;
                a.email  = null;
                a.name   = null;
            }
            a.date = DateTime.UtcNow;
            db.PayPalAuthorizations.Add(a);

            PayPalNotification n = new PayPalNotification();

            n.dateReceived  = DateTime.UtcNow;
            n.transactionId = (this.random.NextDouble() * (1 << 31)).ToString();
            n.payerId       = (this.random.NextDouble() * (1 << 31)).ToString();
            n.paymentGross  = (this.random.NextDouble() * 1000).ToString();
            n.paymentFee    = (Double.Parse(n.paymentGross) * 0.1).ToString();
            n.mcCurrency    = "USD";
            n.mcGross       = n.paymentGross;
            n.reasonCode    = null;
            n.paymentDate   = (DateTime.UtcNow - new TimeSpan(4, 30, 0)).ToString();
            n.paymentStatus = "Completed";
            n.custom        = a.guid;
            db.PayPalNotifications.Add(n);

            db.SaveChanges();
        }