void TransferSuccess(FreeMoneyTransaction transaction)
        {
            if (transaction.InternalType == FreeMoneyTransaction.InternalTransactionType.Payment) {
                if (transaction.ObjectID == UUID.Zero) {
                    // User 2 User Transaction
                    m_log.Info ("[FreeMoney] Success: " + transaction.From + " did pay user " +
                                transaction.To + " " + m_gridCurrencySmallDenominationText + " " + transaction.Amount);

                    IUserAccountService userAccountService = m_scenes[0].UserAccountService;
                    UserAccount ua;

                    // Notify receiver
                    ua = userAccountService.GetUserAccount (transaction.From, "", "");
                    SendInstantMessage (transaction.To, ua.FirstName + " " + ua.LastName +
                                        " did pay you " + m_gridCurrencySmallDenominationText + transaction.Amount);

                    // Notify sender
                    ua = userAccountService.GetUserAccount (transaction.To, "", "");
                    SendInstantMessage (transaction.From, "You did pay " + ua.FirstName + " " +
                                        ua.LastName + " "+m_gridCurrencySmallDenominationText+" " + transaction.Amount);
                } else {
                    if (OnObjectPaid != null) {
                        m_log.Info ("[FreeMoney] Success: " + transaction.From + " did pay object " +
                                    transaction.ObjectID + " owned by " + transaction.To +
                                    " " + m_gridCurrencySmallDenominationText + " " + transaction.Amount);

                        OnObjectPaid (transaction.ObjectID, transaction.From, transaction.Amount);
                    }
                }
            } else if (transaction.InternalType == FreeMoneyTransaction.InternalTransactionType.Purchase) {
                if (transaction.ObjectID == UUID.Zero) {
                    m_log.Error ("[FreeMoney] Unable to find Object bought! UUID Zero.");
                } else {
                    Scene s = LocateSceneClientIn (transaction.From);
                    SceneObjectPart part = s.GetSceneObjectPart (transaction.ObjectID);
                    if (part == null) {
                        m_log.Error ("[FreeMoney] Unable to find Object bought! UUID = " + transaction.ObjectID);
                        return;
                    }

                    m_log.Info ("[FreeMoney] Success: " + transaction.From + " did buy object " +
                                transaction.ObjectID + " from " + transaction.To + " paying " + m_gridCurrencySmallDenominationText + " " +
                                transaction.Amount);

                    IBuySellModule module = s.RequestModuleInterface<IBuySellModule> ();
                    if (module == null) {
                        m_log.Error ("[FreeMoney] Missing BuySellModule! Transaction failed.");
                    } else {
                        ScenePresence sp = s.GetScenePresence(transaction.From);
                        if (sp != null)
                            module.BuyObject (sp.ControllingClient,
                                          transaction.InternalPurchaseFolderID, part.LocalId,
                                          transaction.InternalPurchaseType, transaction.Amount);
                    }
                }
            } else if (transaction.InternalType == FreeMoneyTransaction.InternalTransactionType.Land) {
                // User 2 Land Transaction
                EventManager.LandBuyArgs e = transaction.E;

                lock (e) {
                    e.economyValidated = true;
                }

                Scene s = LocateSceneClientIn (transaction.From);
                ILandObject land = s.LandChannel.GetLandObject ((int)e.parcelLocalID);

                if (land == null) {
                    m_log.Error ("[FreeMoney] Unable to find Land bought! UUID = " + e.parcelLocalID);
                    return;
                }

                m_log.Info ("[FreeMoney] Success: " + e.agentId + " did buy land from " + e.parcelOwnerID +
                            " paying " + m_gridCurrencySmallDenominationText + " " + e.parcelPrice);

                land.UpdateLandSold (e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID,
                                     e.parcelPrice, e.parcelArea);
            } else {
                m_log.Error ("[FreeMoney] Unknown Internal Transaction Type.");
                return;
            }
            // Cleanup.
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Remove (transaction.TxID);
        }
        public void ObjectBuy(IClientAPI remoteClient, UUID agentID, UUID sessionID, UUID groupID,
                               UUID categoryID, uint localID, byte saleType, int salePrice)
        {
            if (!m_active)
                return;

            IClientAPI user = null;
            Scene scene = null;

            // Find the user's controlling client.
            lock (m_scenes) {
                foreach (Scene sc in m_scenes) {
                    ScenePresence av = sc.GetScenePresence (agentID);

                    if ((av != null) && (av.IsChildAgent == false)) {
                        // Found the client,
                        // and their root scene.
                        user = av.ControllingClient;
                        scene = sc;
                    }
                }
            }

            if (scene == null || user == null) {
                m_log.Warn ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
                return;
            }

            if (salePrice == 0) {
                IBuySellModule module = scene.RequestModuleInterface<IBuySellModule> ();
                if (module == null) {
                    m_log.Error ("[FreeMoney] Missing BuySellModule! Transaction failed.");
                    return;
                }
                module.BuyObject (remoteClient, categoryID, localID, saleType, salePrice);
                return;
            }

            SceneObjectPart sop = scene.GetSceneObjectPart (localID);
            if (sop == null) {
                m_log.Error ("[FreeMoney] Unable to find SceneObjectPart that was paid. Aborting transaction.");
                return;
            }

            string email = "";

            if (m_allowPayPal) {
                if (sop.OwnerID == sop.GroupID) {
                    if (m_allowGroups) {
                        if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                            m_log.Warn ("[FreeMoney] Unknown email address of group " + sop.OwnerID);
                            if (!m_allowBitcoin) {
                                return;
                            }
                        }
                    } else {
                        m_log.Warn ("[FreeMoney] Purchase of group owned objects is disabled.");
                        if (!m_allowBitcoin) {
                            return;
                        }
                    }
                } else {
                    if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                        m_log.Warn ("[FreeMoney] Unknown email address of user " + sop.OwnerID);
                        if (!m_allowBitcoin) {
                            return;
                        }
                    }
                }
            }

            m_log.Info ("[FreeMoney] Start: " + agentID + " wants to buy object " + sop.UUID + " from " + sop.OwnerID +
                        " with email " + email + " costing " + m_gridCurrencySmallDenominationText + " " + salePrice);

            FreeMoneyTransaction txn = new FreeMoneyTransaction (agentID, sop.OwnerID, email, salePrice, scene, sop.UUID,
                                                           "Item Purchase - " + sop.Name + " (" + saleType + ")",
                                                           FreeMoneyTransaction.InternalTransactionType.Purchase,
                                                           categoryID, saleType);

            // Add transaction to queue
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Add (txn.TxID, txn);

            string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;

            // Talk to the address-handling server to initialize the transaction
            if (!CommunicateBitcoinTransaction(txn, baseUrl)) {
                m_log.Warn ("[FreeMoney] Attempt to set up transaction failed.");
                return;
            }

            user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm payment?", m_btcprotocol + "://" + m_btcurl + m_btcrequesturi + "?txn=" + txn.TxID);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <remarks>Thanks to Melanie for reminding me about 
        /// EventManager.OnMoneyTransfer being the critical function,
        /// and not ApplyCharge.</remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnMoneyTransfer(object sender, EventManager.MoneyTransferArgs e)
        {
            if (!m_active)
                return;

            IClientAPI user = null;
            Scene scene = null;

            // Find the user's controlling client.
            lock (m_scenes) {
                foreach (Scene sc in m_scenes) {
                    ScenePresence av = sc.GetScenePresence (e.sender);

                    if ((av != null) && (av.IsChildAgent == false)) {
                        // Found the client,
                        // and their root scene.
                        user = av.ControllingClient;
                        scene = sc;
                    }
                }
            }

            if (scene == null || user == null) {
                m_log.Warn ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
                return;
            }

            FreeMoneyTransaction txn;

            if (e.transactiontype == 5008) {
                // Object was paid, find it.
                SceneObjectPart sop = scene.GetSceneObjectPart (e.receiver);
                if (sop == null) {
                    m_log.Warn ("[FreeMoney] Unable to find SceneObjectPart that was paid. Aborting transaction.");
                    return;
                }

                string email;

                if (sop.OwnerID == sop.GroupID) {
                    if (m_allowGroups) {
                        if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                            m_log.Warn ("[FreeMoney] Unknown email address of group " + sop.OwnerID);
                            return;
                        }
                    } else {
                        m_log.Warn ("[FreeMoney] Payments to group owned objects is disabled.");
                        return;
                    }
                } else {
                    if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                        m_log.Warn ("[FreeMoney] Unknown email address of user " + sop.OwnerID);
                        return;
                    }
                }

                m_log.Info ("[FreeMoney] Start: " + e.sender + " wants to pay object " + e.receiver + " owned by " +
                            sop.OwnerID + " with email " + email + " " + m_gridCurrencySmallDenominationText + " " + e.amount);

                txn = new FreeMoneyTransaction (e.sender, sop.OwnerID, email, e.amount, scene, e.receiver,
                                             e.description + " T:" + e.transactiontype,
                                             FreeMoneyTransaction.InternalTransactionType.Payment);
            } else {
                // Payment to a user.
                string email;
                if (!GetEmail (scene.RegionInfo.ScopeID, e.receiver, out email)) {
                    m_log.Warn ("[FreeMoney] Unknown email address of user " + e.receiver);
                    return;
                }

                m_log.Info ("[FreeMoney] Start: " + e.sender + " wants to pay user " + e.receiver + " with email " +
                            email + " " + m_gridCurrencySmallDenominationText + " " + e.amount);

                txn = new FreeMoneyTransaction (e.sender, e.receiver, email, e.amount, scene, e.description + " T:" +
                                             e.transactiontype, FreeMoneyTransaction.InternalTransactionType.Payment);
            }

            // Add transaction to queue
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Add (txn.TxID, txn);

            string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;

            user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm payment?", m_btcprotocol + "://" + m_btcurl + m_btcrequesturi + "?txn=" + txn.TxID);
        }
        private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
        {
            if (!m_active)
                return;

            if (e.parcelPrice == 0)
                return;

            IClientAPI user = null;
            Scene scene = null;

            // Find the user's controlling client.
            lock (m_scenes) {
                foreach (Scene sc in m_scenes) {
                    ScenePresence av = sc.GetScenePresence (e.agentId);

                    if ((av != null) && (av.IsChildAgent == false)) {
                        // Found the client,
                        // and their root scene.
                        user = av.ControllingClient;
                        scene = sc;
                    }
                }
            }

            if (scene == null || user == null) {
                m_log.Error ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
                return;
            }

            string email;

            if ((e.parcelOwnerID == e.groupId) || e.groupOwned) {
                if (m_allowGroups) {
                    if (!GetEmail (scene.RegionInfo.ScopeID, e.parcelOwnerID, out email)) {
                        m_log.Warn ("[FreeMoney] Unknown email address of group " + e.parcelOwnerID);
                        return;
                    }
                } else {
                    m_log.Warn ("[FreeMoney] Purchases of group owned land is disabled.");
                    return;
                }
            } else {
                if (!GetEmail (scene.RegionInfo.ScopeID, e.parcelOwnerID, out email)) {
                    m_log.Warn ("[FreeMoney] Unknown email address of user " + e.parcelOwnerID);
                    return;
                }
            }

            m_log.Info ("[FreeMoney] Start: " + e.agentId + " wants to buy land from " + e.parcelOwnerID +
                        " with email " + email + " costing " + m_gridCurrencySmallDenominationText +" " + e.parcelPrice);

            FreeMoneyTransaction txn;
            txn = new FreeMoneyTransaction (e.agentId, e.parcelOwnerID, email, e.parcelPrice, scene,
                                         "Buy Land", FreeMoneyTransaction.InternalTransactionType.Land, e);

            // Add transaction to queue
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Add (txn.TxID, txn);

            string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;

            // Talk to the address-handling server to initialize the transaction
            if (!CommunicateBitcoinTransaction(txn, baseUrl)) {
                m_log.Warn ("[FreeMoney] Attempt to set up transaction failed.");
                return;
            }

            user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm payment?", m_btcprotocol + "://" + m_btcurl + m_btcrequesturi + "?txn=" + txn.TxID);
        }
        // This will send the transaction to the payment handling server
        // Traditional PayPal flow would pass this information as parameters
        // Doing it this way allows us to do the transaction without revealing the email address of the seller to the buyer
        private bool CommunicateBitcoinTransaction(FreeMoneyTransaction txn, string baseUrl)
        {
            // Hard-coding this for now - may end up building everything into mono, in which case it will go away.
            string bitcoin_server =  m_btcprotocol + "://" + m_btcurl + m_btcrequesturi;

            IUserAccountService userAccountService = m_scenes[0].UserAccountService;
            UserAccount ua;

            // Notify receiver
            ua = userAccountService.GetUserAccount (txn.From, "", "");
            string first = "";
            if (ua != null) {
                first = ua.FirstName;
            }
            //string first = ua.FirstName;

            string post_data = ""
            + "cmd=initialize_transaction"
            + "&payee"           +HttpUtility.HtmlEncode (txn.To.ToString())
            + "&business="       +HttpUtility.HtmlEncode (txn.SellersEmail)
            + "&item_name="     +HttpUtility.HtmlEncode (txn.Description)
            + "&item_number="   +HttpUtility.HtmlEncode (txn.TxID.ToString ())
            + "&amount="        +HttpUtility.HtmlEncode (String.Format ("{0:0.00}", ConvertAmountToCurrency (txn.Amount)))
            + "&notify_url="    +HttpUtility.HtmlEncode ("http://" + baseUrl + "/btcipn/") // TODO: Deal with passing the PayPal details
            + "&currency_code=" +HttpUtility.HtmlEncode (m_gridCurrencyCode)
            + "&sim_base_url="  +HttpUtility.HtmlEncode ("http://" + baseUrl)
            + "&payee_avatar_uuid="+HttpUtility.HtmlEncode ( txn.To.ToString() )
            + "&payer_avatar_uuid="+HttpUtility.HtmlEncode ( txn.From.ToString() )
            + "&payee_avatar_grid="+HttpUtility.HtmlEncode ( baseUrl ) // TODO: These probably need to change for hypergrid
            + "&payer_avatar_grid="+HttpUtility.HtmlEncode ( baseUrl ) // TODO: These probably need to change for hypergrid
            + "&payer_avatar_first="+HttpUtility.HtmlEncode ( first ) // TODO: These probably need to change for hypergrid
            + "&confirm_url="    +HttpUtility.HtmlEncode ("http://" + baseUrl + "/btcconfirm/")
            + "";

            /*
            + "&payee_avatar_first="+HttpUtility.HtmlEncode ( toUA.FirstName ) // TODO: These probably need to change for hypergrid
            + "&payer_avatar_first="+HttpUtility.HtmlEncode ( fromUA.FirstName ) // TODO: These probably need to change for hypergrid
            + "&payee_avatar_last="+HttpUtility.HtmlEncode ( toUA.LastName ) // TODO: These probably need to change for hypergrid
            + "&payer_avatar_last="+HttpUtility.HtmlEncode ( fromUA.LastName ) // TODO: These probably need to change for hypergrid
            */
                        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create (bitcoin_server);
            httpWebRequest.Method = "POST";
            httpWebRequest.ContentLength = post_data.Length;

            StreamWriter streamWriter = new StreamWriter (httpWebRequest.GetRequestStream (), System.Text.Encoding.ASCII);
            streamWriter.Write (post_data);
            streamWriter.Close ();

            string response;

            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse ();
            using (StreamReader streamReader = new StreamReader (httpWebResponse.GetResponseStream ())) {
                response = streamReader.ReadToEnd ();
                streamReader.Close ();
            }

                m_log.Error ("response: "+response);
            if (httpWebResponse.StatusCode != HttpStatusCode.OK) {
                m_log.Error ("[FreeMoney] Bitcoin transaction initialzation != 200. Aborting.");
                return false;
            }

            return true;
        }
Пример #6
0
        // This is called by the UserPage URL callback
        // ...or by another page if there's an error.
        private Hashtable ShowUserPage(Hashtable request, string baseUrl, FreeMoneyTransaction txn, string error_message)
        {
            string url = m_ppprotocol+"://" + m_ppurl + m_pprequesturi+"?cmd=_xclick" + "&business=" +
                HttpUtility.UrlEncode (txn.SellersEmail) + "&item_name=" + HttpUtility.UrlEncode (txn.Description) +
                    "&item_number=" + HttpUtility.UrlEncode (txn.TxID.ToString ()) + "&amount=" +
                    HttpUtility.UrlEncode (String.Format ("{0:0.00}", ConvertAmountToCurrency (txn.Amount))) +
                    "&page_style=" + HttpUtility.UrlEncode ("Paypal") + "&no_shipping=" +
                    HttpUtility.UrlEncode ("1") + "&return=" + HttpUtility.UrlEncode ("http://" + baseUrl + "/") +
                    "&cancel_return=" + HttpUtility.UrlEncode ("http://" + baseUrl + "/") + "&notify_url=" +
                    HttpUtility.UrlEncode ("http://" + baseUrl + "/ppipn/") + "&no_note=" +
                    HttpUtility.UrlEncode ("1") + "&currency_code=" + HttpUtility.UrlEncode (m_gridCurrencyCode) + "&lc=" +
                    HttpUtility.UrlEncode ("US") + "&bn=" + HttpUtility.UrlEncode ("PP-BuyNowBF") + "&charset=" +
                    HttpUtility.UrlEncode ("UTF-8") + "";

            // The URL for Bitcoin will be modelled on the FreeMoney one.
            // This will allow us use a common Bitcoin page handler whether or not we've hacked this.
            // It'll just throw away arguments it doesn't need.
            //string btcurl = m_btcprotocol+"://" + m_btcurl + m_btcrequesturi+"?cmd=_xclick";
            string btcurl = "/btcgo/";

            string btcfields = ""
            + "<input type=\"hidden\" name=\"txn\" value=\""+HttpUtility.HtmlEncode (txn.TxID.ToString ())+"\" />"
            + "<input type=\"hidden\" name=\"btc_session_id\" value=\""+HttpUtility.HtmlEncode ( GetSessionKey( txn.From ).ToString() )+"\" />";

            Dictionary<string, string> replacements = new Dictionary<string, string> ();
            replacements.Add ("{ITEM}",  HttpUtility.HtmlEncode(txn.Description));
            replacements.Add ("{AMOUNT}", HttpUtility.HtmlEncode(String.Format ("{0:0.00}", ConvertAmountToCurrency (txn.Amount))));
            replacements.Add ("{AMOUNTOS}", HttpUtility.HtmlEncode(txn.Amount.ToString ()));
            replacements.Add ("{CURRENCYCODE}", HttpUtility.HtmlEncode(m_gridCurrencyText));
            replacements.Add ("{BILLINGLINK}", url);
            replacements.Add ("{BTCBILLINGLINK}", btcurl);
            replacements.Add ("{BTCBILLINGHIDDENFIELDS}", btcfields);
            replacements.Add ("{OBJECTID}", HttpUtility.HtmlEncode(txn.ObjectID.ToString ()));
            replacements.Add ("{SELLEREMAIL}", HttpUtility.HtmlEncode(txn.SellersEmail));
            replacements.Add ("{BTC_ERRORS}",  error_message);

            string template;

            try {
                template = File.ReadAllText ("freemoney-template.htm");
            } catch (IOException) {
                template = "Error: freemoney-template.htm does not exist.";
                m_log.Error ("[FreeMoney] Unable to load template file.");
            }

            foreach (KeyValuePair<string, string> pair in replacements) {
                template = template.Replace (pair.Key, pair.Value);
            }

            Hashtable reply = new Hashtable ();

            reply["int_response_code"] = 200;
            // 200 OK
            reply["str_response_string"] = template;
            reply["content_type"] = "text/html";

            return reply;
        }
Пример #7
0
        private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
        {
            if (!m_active)
                return;

            if (e.parcelPrice == 0)
                return;

            IClientAPI user = null;
            Scene scene = null;

            // Find the user's controlling client.
            lock (m_scenes) {
                foreach (Scene sc in m_scenes) {
                    ScenePresence av = sc.GetScenePresence (e.agentId);

                    if ((av != null) && (av.IsChildAgent == false)) {
                        // Found the client,
                        // and their root scene.
                        user = av.ControllingClient;
                        scene = sc;
                    }
                }
            }

            if (scene == null || user == null) {
                m_log.Error ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
                return;
            }

            string email;

            if ((e.parcelOwnerID == e.groupId) || e.groupOwned) {
                if (m_allowGroups) {
                    if (!GetEmail (scene.RegionInfo.ScopeID, e.parcelOwnerID, out email)) {
                        m_log.Warn ("[FreeMoney] Unknown email address of group " + e.parcelOwnerID);
                        return;
                    }
                } else {
                    m_log.Warn ("[FreeMoney] Purchases of group owned land is disabled.");
                    return;
                }
            } else {
                if (!GetEmail (scene.RegionInfo.ScopeID, e.parcelOwnerID, out email)) {
                    m_log.Warn ("[FreeMoney] Unknown email address of user " + e.parcelOwnerID);
                    return;
                }
            }

            m_log.Info ("[FreeMoney] Start: " + e.agentId + " wants to buy land from " + e.parcelOwnerID +
                        " with email " + email + " costing " + m_gridCurrencySmallDenominationText +" " + e.parcelPrice);

            FreeMoneyTransaction txn;
            txn = new FreeMoneyTransaction (e.agentId, e.parcelOwnerID, email, e.parcelPrice, scene,
                                         "Buy Land", FreeMoneyTransaction.InternalTransactionType.Land, e);

            // Add transaction to queue
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Add (txn.TxID, txn);

            string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;

            // If we're definitely going to use Bitcoin for this transaction, go ahead and initialize it and show the page page.
            // Otherwise, show an intermediate page to choose the payment type, and only initialize for Bitcoin if they choose it.
            string pageName = "pp";
            if (m_directToBitcoin) {
                InitializeBitcoinTransaction(txn, baseUrl);
                pageName = "btcgo";
            }

            user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm payment?", "http://" +
                              baseUrl + "/"+pageName+"/?txn=" + txn.TxID);
        }
Пример #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <remarks>Thanks to Melanie for reminding me about 
        /// EventManager.OnMoneyTransfer being the critical function,
        /// and not ApplyCharge.</remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void OnMoneyTransfer(object sender, EventManager.MoneyTransferArgs e)
        {
            if (!m_active)
                return;

            IClientAPI user = null;
            Scene scene = null;

            // Find the user's controlling client.
            lock (m_scenes) {
                foreach (Scene sc in m_scenes) {
                    ScenePresence av = sc.GetScenePresence (e.sender);

                    if ((av != null) && (av.IsChildAgent == false)) {
                        // Found the client,
                        // and their root scene.
                        user = av.ControllingClient;
                        scene = sc;
                    }
                }
            }

            if (scene == null || user == null) {
                m_log.Warn ("[FreeMoney] Unable to find scene or user! Aborting transaction.");
                return;
            }

            FreeMoneyTransaction txn;

            if (e.transactiontype == 5008) {
                // Object was paid, find it.
                SceneObjectPart sop = scene.GetSceneObjectPart (e.receiver);
                if (sop == null) {
                    m_log.Warn ("[FreeMoney] Unable to find SceneObjectPart that was paid. Aborting transaction.");
                    return;
                }

                string email;

                if (sop.OwnerID == sop.GroupID) {
                    if (m_allowGroups) {
                        if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                            m_log.Warn ("[FreeMoney] Unknown email address of group " + sop.OwnerID);
                            return;
                        }
                    } else {
                        m_log.Warn ("[FreeMoney] Payments to group owned objects is disabled.");
                        return;
                    }
                } else {
                    if (!GetEmail (scene.RegionInfo.ScopeID, sop.OwnerID, out email)) {
                        m_log.Warn ("[FreeMoney] Unknown email address of user " + sop.OwnerID);
                        return;
                    }
                }

                m_log.Info ("[FreeMoney] Start: " + e.sender + " wants to pay object " + e.receiver + " owned by " +
                            sop.OwnerID + " with email " + email + " " + m_gridCurrencySmallDenominationText + " " + e.amount);

                txn = new FreeMoneyTransaction (e.sender, sop.OwnerID, email, e.amount, scene, e.receiver,
                                             e.description + " T:" + e.transactiontype,
                                             FreeMoneyTransaction.InternalTransactionType.Payment);
            } else {
                // Payment to a user.
                string email;
                if (!GetEmail (scene.RegionInfo.ScopeID, e.receiver, out email)) {
                    m_log.Warn ("[FreeMoney] Unknown email address of user " + e.receiver);
                    return;
                }

                m_log.Info ("[FreeMoney] Start: " + e.sender + " wants to pay user " + e.receiver + " with email " +
                            email + " " + m_gridCurrencySmallDenominationText + " " + e.amount);

                txn = new FreeMoneyTransaction (e.sender, e.receiver, email, e.amount, scene, e.description + " T:" +
                                             e.transactiontype, FreeMoneyTransaction.InternalTransactionType.Payment);
            }

            // Add transaction to queue
            lock (m_transactionsInProgress)
                m_transactionsInProgress.Add (txn.TxID, txn);

            string baseUrl = m_scenes[0].RegionInfo.ExternalHostName + ":" + m_scenes[0].RegionInfo.HttpPort;

            // If we're definitely going to use Bitcoin for this transaction, go ahead and initialize it and show the page page.
            // Otherwise, show an intermediate page to choose the payment type, and only initialize for Bitcoin if they choose it.
            string pageName = "pp";
            if (m_directToBitcoin) {
                InitializeBitcoinTransaction(txn, baseUrl);
                pageName = "btcgo";
            }

            user.SendLoadURL ("FreeMoney", txn.ObjectID, txn.To, false, "Confirm payment?", "http://" +
                              baseUrl + "/"+pageName+"/?txn=" + txn.TxID);
        }
Пример #9
0
        //public bool InitializeBitcoinTransaction(Dictionary<string,string> transaction_params, string base_url)
        private BitcoinTransaction InitializeBitcoinTransaction(FreeMoneyTransaction txn, string base_url)
        {
            // ED TODO: Put in params

            Dictionary<string, string> transaction_params = new Dictionary<string, string>();
            //transaction_params.Add("payee", txn.SellersEmail);
            transaction_params.Add("payee", txn.To.ToString());
            transaction_params.Add("business", txn.SellersEmail);
            transaction_params.Add("item_name", txn.Description);
            transaction_params.Add("item_number", txn.TxID.ToString());
            transaction_params.Add("amount", ConvertAmountToCurrency(txn.Amount).ToString());
            transaction_params.Add("currency_code", m_gridCurrencyCode);
            transaction_params.Add("notify_url", "");

            // Optionally, use an external URL that's accessible from outside NAT.
            if (m_externalBaseURL != "") {
                base_url = m_externalBaseURL;
            }

            BitcoinTransaction btc_trans = new BitcoinTransaction(m_connectionString, m_btcconfig, "http://"+base_url);
            btc_trans.Initialize(transaction_params, m_btcNumberOfConfirmationsRequired);

            return btc_trans;
        }