Ejemplo n.º 1
0
        public bool Claim(Mobile m)
        {
            if (State == TransactionState.Claimed)
            {
                return(true);
            }

            if (State != TransactionState.Processed)
            {
                return(false);
            }

            if ((State = TransactionState.Claimed) == TransactionState.Claimed)
            {
                Deliver(m);
                DeliveredTo  = m.RawName;
                DeliveryTime = TimeStamp.Now;

                ++Version;

                DonationEvents.InvokeTransClaimed(this, m);

                LogToFile();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        public bool Claim(Mobile from, Mobile to, string message, params object[] args)
        {
            if (from != null && to != null &&
                ((from.Player && from.Account == Account) || from.AccessLevel >= AccessLevel.Administrator))
            {
                DeliverFrom  = from;
                DeliverTo    = to;
                DeliveryTime = TimeStamp.UtcNow;

                if (Deliver(message, args))
                {
                    DonationEvents.InvokeTransDelivered(this);

                    if (!AutoDonate.CMOptions.ShowHistory)
                    {
                        Hidden = true;
                    }

                    State = DonationTransactionState.Claimed;
                    DonationEvents.InvokeTransClaimed(this);
                    return(true);
                }

                DeliverFrom  = null;
                DeliverTo    = null;
                DeliveryTime = TimeStamp.Zero;
            }

            return(false);
        }
Ejemplo n.º 3
0
        public bool Process()
        {
            if (State == TransactionState.Processed)
            {
                return(true);
            }

            if (State != TransactionState.Pending)
            {
                return(false);
            }

            if ((State = TransactionState.Processed) == TransactionState.Processed)
            {
                ++Version;

                DonationEvents.InvokeTransProcessed(this);

                LogToFile();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool Process()
        {
            if ((State = DonationTransactionState.Processed) == DonationTransactionState.Processed)
            {
                DonationEvents.InvokeTransProcessed(this);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 5
0
        public bool Void()
        {
            if ((State = DonationTransactionState.Void) == DonationTransactionState.Void)
            {
                if (!AutoDonate.CMOptions.ShowHistory)
                {
                    Hidden = true;
                }

                DonationEvents.InvokeTransVoided(this);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        public void Delete()
        {
            if (Deleted)
            {
                return;
            }

            Deleted = true;

            AutoDonate.Transactions.Remove(ID);

            DonationEvents.InvokeTransactionDeleted(this);

            DeliveredTo = null;
            SetAccount(null);
        }
Ejemplo n.º 7
0
        private long GetCredit(DonationProfile dp, bool delivering, out long credit, out long bonus)
        {
            if (!delivering && State != TransactionState.Processed)
            {
                return((credit = Credit) + (bonus = Bonus));
            }

            var total = DonationEvents.InvokeTransExchange(this, dp);

            if (AutoDonate.CMOptions.CreditBonus > 0)
            {
                total += (long)Math.Floor(Credit * AutoDonate.CMOptions.CreditBonus);
            }

            bonus  = Math.Max(0, total - Credit);
            credit = Math.Max(0, total - bonus);

            return(total);
        }
Ejemplo n.º 8
0
        public bool Void()
        {
            if (State == TransactionState.Voided)
            {
                return(true);
            }

            if ((State = TransactionState.Voided) == TransactionState.Voided)
            {
                ++Version;

                DonationEvents.InvokeTransVoided(this);

                LogToFile();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 9
0
        private static void OnExceptionThrown(Exception e, string message, params object[] args)
        {
            CMOptions.ToConsole(e);

            if (args != null)
            {
                if (!String.IsNullOrWhiteSpace(message))
                {
                    CMOptions.ToConsole(message, args);
                }

                DonationEvents.InvokeException(e, message, args);
            }
            else
            {
                if (!String.IsNullOrWhiteSpace(message))
                {
                    CMOptions.ToConsole(message);
                }

                DonationEvents.InvokeException(e, message);
            }
        }
Ejemplo n.º 10
0
        private static void ProcessTransaction(WebAPIQueries queries)
        {
            var id = queries["txn_id"];

            if (String.IsNullOrWhiteSpace(id))
            {
                return;
            }

            var type = queries["txn_type"];

            if (String.IsNullOrWhiteSpace(type) || !type.EqualsAny(true, _AcceptedTypes))
            {
                return;
            }

            var status = queries["payment_status"];

            if (String.IsNullOrWhiteSpace(status))
            {
                return;
            }

            TransactionState state;

            switch (status.Trim().ToUpper())
            {
            case "PENDING":
            case "PROCESSED":
            case "CREATED":
                state = TransactionState.Pending;
                break;

            case "COMPLETED":
                state = TransactionState.Processed;
                break;

            default:
                state = TransactionState.Voided;
                break;
            }

            long   credit;
            double value;

            ExtractCart(queries, out credit, out value);

            var custom = queries["custom"] ?? String.Empty;

            var trans = Transactions.GetValue(id);

            var create = trans == null;

            if (create)
            {
                var email = queries["payer_email"] ?? String.Empty;
                var notes = queries["payer_note"] ?? String.Empty;
                var extra = queries["extra_info"] ?? String.Empty;

                var a = Accounts.GetAccount(custom) ?? CMOptions.FallbackAccount;

                Transactions[id] = trans = new DonationTransaction(id, a, email, value, credit, notes, extra);

                var profile = EnsureProfile(a);

                if (profile == null)
                {
                    state        = TransactionState.Voided;
                    trans.Extra += "{VOID: NO PROFILE}";
                }
                else
                {
                    profile.Add(trans);
                }
            }

            if (!VerifyValue(queries, "business", CMOptions.Business) &&
                !VerifyValue(queries, "receiver_email", CMOptions.Business) &&
                !VerifyValue(queries, "receiver_id", CMOptions.Business))
            {
                state        = TransactionState.Voided;
                trans.Extra += "{VOID: UNEXPECTED BUSINESS}";
            }

            if (trans.Total != value)
            {
                state        = TransactionState.Voided;
                trans.Extra += "{VOID: TOTAL CHANGED}";
            }

            if (queries["test"] != null || queries["test_ipn"] != null)
            {
                state        = TransactionState.Voided;
                trans.Extra += "{VOID: TESTING}";
            }

            switch (state)
            {
            case TransactionState.Processed:
                trans.Process();
                break;

            case TransactionState.Voided:
                trans.Void();
                break;
            }

            if (create && trans.IsPending)
            {
                DonationEvents.InvokeTransPending(trans);
            }

            SpotCheck(trans.Account);
        }
Ejemplo n.º 11
0
        private void Deliver(Mobile m)
        {
            if (m == null || m.Account == null)
            {
                return;
            }

            if (Account != m.Account)
            {
                SetAccount(m.Account);
            }

            var dp = AutoDonate.EnsureProfile(Account);

            if (dp == null)
            {
                return;
            }

            long credit, bonus;
            var  total = GetCredit(dp, true, out credit, out bonus);

            Credit = credit;
            Bonus  = bonus;

            var bag = DonationEvents.InvokeTransPack(this, dp);

            if (bag == null || bag.Deleted)
            {
                dp.Credit += total;
                return;
            }

            Protect(bag);

            while (credit > 0)
            {
                var cur = AutoDonate.CMOptions.CurrencyType.CreateInstance();

                if (cur == null)
                {
                    bag.Delete();
                    break;
                }

                Protect(cur);

                if (cur.Stackable)
                {
                    cur.Amount = (int)Math.Min(credit, 60000);
                }

                credit -= cur.Amount;

                bag.DropItem(cur);
            }

            if (bag.Deleted)
            {
                dp.Credit += total;
                return;
            }

            while (bonus > 0)
            {
                var cur = AutoDonate.CMOptions.CurrencyType.CreateInstance();

                if (cur == null)
                {
                    bag.Delete();
                    break;
                }

                Protect(cur);

                cur.Name = String.Format("{0} [Bonus]", cur.ResolveName(m));

                if (cur.Stackable)
                {
                    cur.Amount = (int)Math.Min(bonus, 60000);
                }

                bonus -= cur.Amount;

                bag.DropItem(cur);
            }

            if (bag.Deleted || bag.GiveTo(m, GiveFlags.PackBankDelete) == GiveFlags.Delete)
            {
                dp.Credit += total;
            }
        }
Ejemplo n.º 12
0
 private void OnStateChanged(TransactionState oldState)
 {
     DonationEvents.InvokeStateChanged(this, oldState);
 }
Ejemplo n.º 13
0
		private static void OnTransDelivered(DonationEvents.TransDeliveredEventArgs e)
		{
			SpotCheck(e.Transaction.DeliverTo as PlayerMobile);
		}