Exemplo n.º 1
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            DACResult r = ZincOps.Zinc_RealTimeProductQuery(txtAdd.Text, _country);

            if (r.sError != "")
            {
                MsgBox("Error", "We encountered an error while adding this product.  " + r.sError, this);
            }
        }
Exemplo n.º 2
0
        private void UpdOrders()
        {
            string    sql = "Select * from Orders Where status <> 'COMPLETED' and Updated < getdate()-.1";
            DataTable dt  = gData.GetDataTable2(sql);

            for (int y = 0; y < dt.Rows.Count; y++)
            {
                string    sZincID = dt.Rows[y]["zincID"].ToNonNullString();
                DACResult r       = ZincOps.Zinc_QueryOrderStatus(sZincID);
                string    test    = "";
            }
        }
Exemplo n.º 3
0
        public static DACResult UploadFile(string sLocalPath, string sAPI_KEY)
        {
            DACResult r = new DACResult();
            // Returns the URL of the resource
            string        sDir          = Splitter.SplitFile(sLocalPath);
            FileInfo      fi            = new FileInfo(sLocalPath);
            string        sOriginalName = fi.Name;
            DirectoryInfo di            = new DirectoryInfo(sDir);
            string        sURL          = "https://localhost:44358/UnchainedUpload";
            int           nTotalParts   = 0;

            for (int i = 0; i < Splitter.MAX_PARTS; i++)
            {
                string sPartial = i.ToString() + ".dat";
                string sPath    = Path.Combine(di.FullName, sPartial);
                if (File.Exists(sPath))
                {
                    nTotalParts = i;
                }
                else
                {
                    break;
                }
            }
            for (int i = 0; i <= nTotalParts; i++)
            {
                string sPartial = i.ToString() + ".dat";
                string sPath    = Path.Combine(di.FullName, sPartial);
                if (File.Exists(sPath))
                {
                    string sResult = IO.SubmitPart(sAPI_KEY, sURL, sOriginalName, sPath, i, nTotalParts);
                    string sStatus = IO.ExtractXML(sResult, "<status>", "</status>");
                    string out_URL = IO.ExtractXML(sResult, "<url>", "</url>");
                    double nStatus = IO.GetDouble(sStatus);

                    if (nStatus != 1)
                    {
                        r.OverallResult = false;
                        break;
                    }
                    if (i == nTotalParts)
                    {
                        r.OverallResult = true;
                        r.URL           = out_URL;
                    }
                }
            }
            // Relinquish Space
            bool fEliminated = Splitter.RelinquishSpace(sLocalPath);

            return(r);
        }
Exemplo n.º 4
0
        private void ResubmitZinc(string oldid)
        {
            string    sql      = "Select * from Orders where id = '" + BMS.PurifySQL(oldid, 20) + "'";
            DataTable oldOrder = gData.GetDataTable2(sql);

            if (oldOrder.Rows.Count < 1)
            {
                return;
            }

            sql = "Select * from products where id='" + BMS.PurifySQL(oldOrder.Rows[0]["productid"].ToString(), 40) + "'";
            DataTable dtProd = gData.GetDataTable2(sql);

            if (dtProd.Rows.Count < 1)
            {
                return;
            }

            ZincOps.zinc_address zTo = ZincOps.GetDeliveryAddress(oldOrder.Rows[0]["addressbookid"].ToString());
            string    sProductGuid   = oldOrder.Rows[0]["productid"].ToNonNullString();
            string    sProductID     = dtProd.Rows[0]["product_id"].ToNonNullString();
            string    sOrderID       = Guid.NewGuid().ToString();
            double    nMaxPrice      = 25;
            DACResult r = ZincOps.Zinc_CreateOrder(zTo, nMaxPrice, sProductID, sOrderID);

            if (r.sError != "")
            {
                MsgBox("Buying Error", "Sorry, the purchase Failed.  Exception: " + r.sError + ".  You have not been charged.  ", this);
            }
            else
            {
                double dPriceUSD = GetDouble(dtProd.Rows[0]["price"]) / 100;

                string sNotes = "Store purchase: " + dtProd.Rows[0]["Title"] + ", Item: "
                                + dtProd.Rows[0]["product_id"] + ", Amount: $" + DoFormat(dPriceUSD);
                double nPriceBBP = GetDouble(oldOrder.Rows[0]["bbpprice"]);

                string sStatus = "PROCESSING";
                string sql1    = "Insert into Orders (id, retailer, productid, addressbookid, status, added, updated, notes, zincid, userid, bbpprice) values ('"
                                 + sOrderID + "','AMAZON','"
                                 + BMS.PurifySQL(sProductGuid, 256) + "','"
                                 + BMS.PurifySQL(oldOrder.Rows[0]["addressbookid"].ToString(), 100) + "','"
                                 + sStatus + "',getdate(),getdate(),null,'" + r.sResult
                                 + "','" + gUser(this).UserId.ToString() + "','" + nPriceBBP.ToString() + "')";
                gData.Exec(sql1);
            }
        }
Exemplo n.º 5
0
        public static DACResult Zinc_CreateOrder(zinc_address toShippingAddress, double nMaxPriceUSD, string sAmzProductId, string sOrderID)
        {
            DACResult r = new DACResult();

            return(r);
        }
Exemplo n.º 6
0
        public static DACResult Zinc_RealTimeProductQuery(string myItem, string sCountry)
        {
            DACResult r = new DACResult();

            r.sError = "";
            try
            {
                Chilkat.Rest rest             = ConnectToZinc();
                string       jsonOrder        = "";
                string[]     q                = myItem.Split("/");
                string       sOriginalURL     = "";
                string       sSearchProductID = "";
                for (int i = 0; i < q.Length; i++)
                {
                    sOriginalURL += q[i] + "/";
                    if (q[i].Length == 10)
                    {
                        sSearchProductID = q[i];
                        break;
                    }
                }
                string sRetailer = "amazon";
                if (sCountry == "UK")
                {
                    sRetailer = "amazon_uk";
                }
                else
                {
                    sRetailer = "amazon";
                }
                string sResponse = rest.FullRequestString("GET", "/v1/search?query=" + HttpUtility.UrlEncode(sSearchProductID) + "&retailer=" + sRetailer, jsonOrder);
                if (rest.LastMethodSuccess != true)
                {
                    Log(rest.LastErrorText);
                    r.sError = "Unable to interface with AMAZON.";
                    return(r);
                }
                dynamic oJson = JsonConvert.DeserializeObject <dynamic>(sResponse);
                if (oJson["results"] == null)
                {
                    r.sError = "Unable to find item";
                    return(r);
                }

                foreach (var j in oJson["results"])
                {
                    // if its not prime or its pantry; give them a nice error
                    bool fFresh  = j["fresh"].Value;
                    bool fPrime  = j["prime"].Value;
                    bool fPantry = j["pantry"].Value;
                    if (fFresh || fPantry)
                    {
                        r.sError = "Sorry, we are not interfacing with Fresh or Pantry items yet. ";
                        return(r);
                    }
                    if (!fPrime)
                    {
                        r.sError = "Sorry, this item is not amazon prime.  Please, only add Amazon Prime items so we can offer free shipping. ";
                        return(r);
                    }
                    CacheProduct(j, sOriginalURL, sCountry);
                    r.sResult = sOriginalURL;
                    return(r);
                }
                r.sResult = sOriginalURL;
                return(r);
            }
            catch (Exception ex)
            {
                r.sError = "Unable to find product.";
                return(r);
            }
        }
Exemplo n.º 7
0
        public static DACResult Zinc_QueryOrderStatus(string sZincID)
        {
            DACResult r = new DACResult();

            r.sError = "";
            try
            {
                Chilkat.Rest rest      = ConnectToZinc();
                string       jsonOrder = "";
                string       sResponse = rest.FullRequestString("GET", "/v1/orders/" + sZincID, jsonOrder);
                if (rest.LastMethodSuccess != true)
                {
                    Log(rest.LastErrorText);
                    r.sError = "Unable to interface with AMAZON.";
                    return(r);
                }
                dynamic oJson = JsonConvert.DeserializeObject <dynamic>(sResponse);
                // Tracking
                string sDeliveryDate = GetJsonValue(oJson, "delivery_dates", "date");
                string sTrackingURL  = GetJsonValue(oJson, "merchant_order_ids", "tracking_url");
                if (sTrackingURL != "")
                {
                    sTrackingURL = sZincID;
                }


                string sCode = GetJsonValue(oJson, "code", "");

                string msg = GetJsonValue(oJson, "message", "");
                msg = msg.Replace("'", "");

                string sStatus = "";

                if (sCode == "aborted_request")
                {
                    sStatus      = "COMPLETED";
                    sTrackingURL = sCode;
                }
                else if (msg == "One of the products you selected is unavailable.")
                {
                    sStatus      = "COMPLETED";
                    sTrackingURL = "CUSTOMER REFUNDED";
                    // Credit the user the amount
                    string    sMySql     = "Select * from Orders where ZincID = '" + BMS.PurifySQL(sZincID, 40) + "'";
                    DataTable dtRefunded = gData.GetDataTable2(sMySql);
                    if (dtRefunded.Rows.Count > 0)
                    {
                        double nPriceBBP = GetDouble(dtRefunded.Rows[0]["bbpprice"]);
                        string sSql2     = "Select product_id from products where id='" + dtRefunded.Rows[0]["productid"].ToString() + "'";
                        string sProdID   = gData.GetScalarString2(sSql2, "product_id");
                        string sNotes    = "Full refund for unavailable product for product id " + sProdID;
                        DataOps.AdjBalance(1 * nPriceBBP, DataOps.GetUserRecord(dtRefunded.Rows[0]["UserId"].ToString()).UserId.ToString(), sNotes);
                        NotifyOfMissingProduct(DataOps.GetUserRecord(dtRefunded.Rows[0]["UserId"].ToString()).EmailAddress, sProdID);
                    }
                }
                else if (sTrackingURL != "")
                {
                    sStatus = "OUT_FOR_DELIVERY";
                    if (sDeliveryDate != "")
                    {
                        System.TimeSpan diffResult = System.DateTime.Now - Convert.ToDateTime(sDeliveryDate);
                        if (diffResult.TotalHours > 1)
                        {
                            sStatus = "COMPLETED";
                        }
                    }
                }


                if (r.sResult != "" || true)
                {
                    string sql = "Update Orders Set Updated=getdate(),DeliveryDate='" + sDeliveryDate + "', TrackingNumber='" + sTrackingURL + "',Message='"
                                 + msg + "',Status = '" + sStatus + "' where ZincID = '" + sZincID + "' and status <> 'COMPLETED'";
                    gData.Exec(sql);
                }

                return(r);
            }
            catch (Exception ex)
            {
                r.sError = "Unable to find product.";
                return(r);
            }
        }
Exemplo n.º 8
0
        protected void btnBuy_Click(object sender, EventArgs e)
        {
            string    sID = Request.QueryString["buyid"].ToNonNullString();
            string    sql = "Select * from Products Where id='" + BMS.PurifySQL(sID, 200) + "' and deleted=0";
            DataTable dt  = gData.GetDataTable2(sql);

            if (dt.Rows.Count < 1)
            {
                MsgBox("Error", "Item no longer available.", this);
            }
            double dPriceUSD   = GetDouble(dt.Rows[0]["Price"].ToString()) / 100;
            double nSaleAmount = GetDouble(GetBMSConfigurationKeyValue("amazonsale"));

            double nPriceBBP = GetBBPAmountDouble(dPriceUSD, nSaleAmount);

            if (dPriceUSD < 1)
            {
                MsgBox("Error", "This items price is not correct.  ", this);
            }

            if (gUser(this).LoggedIn == false)
            {
                MsgBox("Log In Error", "Sorry, you must be logged in first.", this);
                return;
            }

            if (gUser(this).TwoFactorAuthorized == false || gUser(this).Require2FA != 1)
            {
                MsgBox("Two Factor Not Enabled", "Sorry, you cannot spend unless you enable two factor authorization.  Please go to the Account Edit page to enable 2FA. ", this);
                return;
            }

            // Amazon Promotion $5
            double nUnlockAmazon = gData.GetScalarDoubleFromObject("Users", "UnlockAmazon", gUser(this).UserId);
            double nMax          = GetBBPAmountDouble(5);

            double nBal = DataOps.GetUserBalance(gUser(this).UserId.ToString());

            if (nUnlockAmazon == 1 && (nPriceBBP <= nMax || nBal + nMax >= nPriceBBP))
            {
                string sql2 = "Update Users set unlockamazon=2 where id = '" + gUser(this).UserId.ToString() + "'";
                gData.Exec(sql2);
                // End of promotion
                if (nPriceBBP < nMax)
                {
                    nMax = nPriceBBP;
                }
                string sNarr = "Promotional Store Credit";
                DataOps.AdjBalance(nMax + 100, gUser(this).UserId.ToString(), sNarr);
                Log("Giving away promotional store credit to " + gUser(this).EmailAddress);
            }

            if (nBal == 0 || nBal < 1 || nPriceBBP > nBal || nPriceBBP > 20000000)
            {
                MsgBox("Insufficient Funds", "Sorry, the amount requested exceeds your balance.", this);
                return;
            }

            // Buy then adjust
            string deliveryid = ddDeliveryAddress.SelectedValue;

            ZincOps.zinc_address zTo = ZincOps.GetDeliveryAddress(deliveryid);
            string sProductID        = dt.Rows[0]["product_id"].ToNonNullString();

            if (sProductID == "")
            {
                MsgBox("Error", "Unable to find item.", this);
            }
            string sOrderID  = Guid.NewGuid().ToString();
            double nMaxPrice = Math.Round(dPriceUSD + 5, 0);



            DACResult r = ZincOps.Zinc_CreateOrder(zTo, nMaxPrice, sProductID, sOrderID);

            if (r.sError != "")
            {
                MsgBox("Buying Error", "Sorry, the purchase Failed.  Exception: " + r.sError + ".  You have not been charged.  ", this);
            }
            else
            {
                string sNotes = "Store purchase: " + dt.Rows[0]["Title"] + ", Item: " + dt.Rows[0]["product_id"] + ", Amount: $" + DoFormat(dPriceUSD);

                DataOps.AdjBalance(-1 * nPriceBBP, gUser(this).UserId.ToString(), sNotes);
                string sStatus = "PROCESSING";
                string sql1    = "Insert into Orders (id, retailer, productid, addressbookid, status, added, updated, notes, zincid, userid, bbpprice) values ('"
                                 + sOrderID + "','AMAZON','"
                                 + BMS.PurifySQL(sID, 256) + "','"
                                 + BMS.PurifySQL(ddDeliveryAddress.SelectedValue.ToString(), 100) + "','"
                                 + sStatus + "',getdate(),getdate(),null,'" + r.sResult + "','" + gUser(this).UserId.ToString() + "','" + nPriceBBP.ToString() + "')";
                gData.Exec(sql1);

                MsgBox("Success", "You have successfully purchased the item [" + dt.Rows[0]["Title"]
                       + "].  To track this order, simply navigate to <a href='MyOrders'>My Orders</a>.  Thank you for shopping with BiblePay.  ", this);
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string sAction = Request.QueryString["action"].ToNonNullString();

            Log("SERVER::" + sAction);

            if (sAction == "BBP_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.BBP_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "QUERY_UTXO")
            {
                Response.Write("<eof>");
                Response.End();
            }
            else if (sAction == "QUERY_UTXOS")
            {
                Response.Write("<eof>");
                Response.End();
                return;

                string sXML      = Request.Headers["Action"].ToNonNullString();
                string sAddress  = ExtractXML(sXML, "<address>", "</address>").ToString();
                string sTicker   = ExtractXML(sXML, "<ticker>", "</ticker>").ToString();
                int    nUTXOTime = (int)GetDouble(ExtractXML(sXML, "<timestamp>", "</timestamp>").ToString());

                List <SimpleUTXO> l      = QueryUTXOs(sTicker, sAddress, nUTXOTime);
                string            sReply = "";
                for (int i = 0; i < l.Count; i++)
                {
                    SimpleUTXO u = l[i];
                    sReply += SerializeUTXO(u);
                }
                sReply += "<eof>";

                //Log("Query LISTOF(UTXO) " + sXML + " == REPLY == " + sReply);
                Response.Write(sReply);
                Response.End();
            }
            else if (sAction == "PUBKEYDERIVE")
            {
                string  sMinerID = Request.Headers["MinerID"].ToNonNullString();
                string  sHash    = GetSha256HashI(sMinerID);
                KeyType k        = DeriveNewKey(sHash);
                string  sReply   = k.PubKey + "|" + k.PrivKey + "|";
                Response.Write(sReply);
                Response.End();
            }
            else if (sAction == "QUERYADDRESSBALANCE")
            {
                string sAddress  = Request.Headers["Address"].ToNonNullString();
                string sAddress2 = Request.QueryString["Address"].ToNonNullString();
                double b         = QueryAddressBalance(Coalesce(sAddress, sAddress2));
                string sReply    = b.ToString();
                Log("QUERYADDRBALANCE " + Coalesce(sAddress, sAddress2) + " REPLY " + sReply);
                Response.Write(sReply);
                Response.End();
            }
            else if (sAction == "QUERYROKUBALANCE")
            {
                string  sHWID  = Request.Headers["hwid"].ToNonNullString();
                KeyType k      = DeriveRokuKeypair(sHWID);
                double  b      = QueryAddressBalance(k.PubKey);
                string  sReply = b.ToString();
                Response.Write(sReply);
                Response.End();
            }
            else if (sAction == "LISTROKUORPHANNFTS")
            {
                string sHWID = Request.Headers["hwid"].ToNonNullString();
                string data  = Common.ListRokuNFTS(sHWID, false);
                Response.Write(data);
                Response.End();
            }
            else if (sAction == "LISTMYROKUORPHANNFTS")
            {
                string sHWID = Request.Headers["hwid"].ToNonNullString();
                string data  = Common.ListRokuNFTS(sHWID, true);
                Response.Write(data);
                Response.End();
            }
            else if (sAction == "QUERYROKUADDRESS")
            {
                string  sHWID = Request.Headers["hwid"].ToNonNullString();
                KeyType k     = DeriveRokuKeypair(sHWID);
                Response.Write(k.PubKey);
                Response.End();
            }
            else if (sAction == "QUERYROKUPRIVATEKEY")
            {
                string  sHWID = Request.Headers["hwid"].ToNonNullString();
                KeyType k     = DeriveRokuKeypair(sHWID);
                Response.Write(k.PrivKey);
                Response.End();
            }
            else if (sAction == "BUYNFT")
            {
                // This lets a Roku TV viewer sponsor an orphan:
                string sHWID      = Request.Headers["hwid"].ToNonNullString();
                string sAmt       = Request.QueryString["amount"].ToNonNullString();
                string sData      = Request.Headers["base64data"].ToNonNullString();
                string sDecoded   = Base64Decode(sData);
                string sLastOwner = ExtractXML(sDecoded, "<lastcpk>", "</lastcpk>").ToString();
                double dAmt       = GetDouble(sAmt);
                if (dAmt > 0 && sHWID != "" && sLastOwner != "")
                {
                    KeyType   k       = DeriveRokuKeypair(sHWID);
                    DACResult r       = CreateFundingTransaction(dAmt, sLastOwner, k.PrivKey, sDecoded, true);
                    string    sResult = r.sTXID.ToNonNullString() + "|" + r.sResult.ToNonNullString() + "|" + r.sError.ToNonNullString();
                    Log("SPENDING : " + sResult + ", Enc=" + sData + ", Data=" + sDecoded);
                    string sDesc  = ExtractXML(sDecoded, "<description>", "</description>").ToString();
                    string sLo    = ExtractXML(sDecoded, "<loqualityurl>", "</loqualityurl>").ToString();
                    double nPrice = GetDouble(ExtractXML(sDecoded, "<buyitnowamount>", "</buyitnowamount>"));
                    NotifyOfRokuSale(sDesc, "*****@*****.**", r.sTXID, true, sLo, nPrice);
                    Response.Write(sResult);
                    Response.End();
                }
                else
                {
                    Response.Write("Invalid Funding Transaction");
                    Response.End();
                }
            }
            else if (sAction == "SERIALIZENFT")
            {
                string sNFTID = Request.Headers["nftid"].ToNonNullString();
                if (sNFTID == "")
                {
                    Response.Write("");
                    Response.End();
                }
                string  sHWID     = Request.Headers["hwid"].ToNonNullString();
                KeyType k         = DeriveRokuKeypair(sHWID);
                string  sBuyerCPK = k.PubKey;
                string  sPayload  = PoolCommon.SerializeNFT(sHWID, sNFTID, "BUY");
                Response.Write(sPayload);
                Response.End();
            }
            else if (sAction == "CREATEFUNDINGTRANSACTION")
            {
                string    sPrivKey   = Request.Headers["PRIVKEY"].ToNonNullString();
                string    sToAddress = Request.Headers["TOADDRESS"].ToNonNullString();
                string    sAmount    = Request.Headers["AMOUNT"].ToNonNullString();
                string    sNotes     = Request.Headers["NOTES"].ToNonNullString();
                DACResult r          = CreateFundingTransaction(GetDouble(sAmount), sToAddress, sPrivKey, sNotes, true);
                string    sResult    = r.sTXID.ToNonNullString() + "|" + r.sResult.ToNonNullString() + "|" + r.sError.ToNonNullString();
                Response.Write(sResult);
                Response.End();
            }
            else if (sAction == "MAIL")
            {
                string           sXML1 = Request.Headers["Action"].ToNonNullString();
                string           sXML  = Base64Decode(sXML1);
                DirectMailLetter m     = new DirectMailLetter();
                string           sTo   = ExtractXML(sXML, "<to>", "</to>").ToString();
                string           sFrom = ExtractXML(sXML, "<from>", "</from>").ToString();
                m.To.Name         = ExtractXML(sTo, "<Name>", "</Name>").ToString();
                m.To.AddressLine1 = ExtractXML(sTo, "<AddressLine1>", "</AddressLine1>").ToString();
                m.To.AddressLine2 = ExtractXML(sTo, "<AddressLine2>", "</AddressLine2>").ToString();
                m.To.City         = ExtractXML(sTo, "<City>", "</City>").ToString();
                m.To.State        = ExtractXML(sTo, "<State>", "</State>").ToString();
                m.To.Zip          = ExtractXML(sTo, "<Zip>", "</Zip>").ToString();

                m.From.Name         = ExtractXML(sFrom, "<Name>", "</Name>").ToString();
                m.From.AddressLine1 = ExtractXML(sFrom, "<AddressLine1>", "</AddressLine1>").ToString();
                m.From.AddressLine2 = ExtractXML(sFrom, "<AddressLine2>", "</AddressLine2>").ToString();
                m.From.City         = ExtractXML(sFrom, "<City>", "</City>").ToString();
                m.From.State        = ExtractXML(sFrom, "<State>", "</State>").ToString();
                m.From.Zip          = ExtractXML(sFrom, "<Zip>", "</Zip>").ToString();

                m.Medium = "Letter";
                m.Size   = "8.5x14";
                m.DryRun = GetDouble(ExtractXML(sXML, "<dryrun>", "</dryrun>").ToString()) == 1;

                // Check to see if they paid for this  (requires <txid> and <toaddress>)
                double nPaidBBP = 0;
                if (m.DryRun == false)
                {
                    for (int iSleep = 0; iSleep < 10; iSleep++)
                    {
                        nPaidBBP = BMS.VerifyServicePayment(sXML);
                        if (nPaidBBP > 0)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
                }
                double nAmtPaidUSD = GetUSDAmountFromBBP(nPaidBBP);
                Log("Mailing " + sXML + ", PAID=" + nPaidBBP.ToString() + ", amtusd = " + nAmtPaidUSD.ToString() + ", dryrun=" + m.DryRun.ToString());
                // ************************************ DRY RUN ? ************************************************
                if (m.DryRun == false && nAmtPaidUSD < .51)
                {
                    m.DryRun = true;
                }
                m.PostalClass = "First Class";
                m.Template    = ExtractXML(sXML, "<Template>", "</Template>").ToNonNullString().ToLower();
                m.Data        = "ea659d20-6031-4f23-abab-3fe39abf381f"; // Easter template
                string[] vCard = m.Template.Split(" ");
                if (vCard.Length < 1)
                {
                    Response.Write("<EOF><HTML>");
                    return;
                }
                m.VariablePayload.ImageURL          = "https://foundation.biblepay.org/Uploads/DM/" + vCard[0] + ".jpg";
                m.VariablePayload.OpeningSalutation = ExtractXML(sTo, "<OpeningSalutation>", "</OpeningSalutation>").ToString();
                m.VariablePayload.Paragraph1        = ExtractXML(sXML, "<paragraph1>", "</paragraph1>").ToString();
                m.VariablePayload.Paragraph2        = ExtractXML(sXML, "<paragraph2>", "</paragraph2>").ToString();
                m.VariablePayload.ClosingSalutation = ExtractXML(sTo, "<ClosingSalutation>", "</ClosingSalutation>").ToString();
                m.VariablePayload.FirstName         = m.To.Name;
                m.VariablePayload.SenderName        = m.From.Name;
                m.VariablePayload.SenderCompany     = "Bible Pay";
                Log("Create Greeting Card " + m.VariablePayload.ImageURL + ";" + m.Template);
                m.Description = "tx " + ExtractXML(sXML, "<txid>", "</txid>").ToString();
                string response = MailLetter(m) + "<EOF></HTML>";
                Response.Write(response);
                Response.End();
                return;
            }
            else if (sAction == "statement")
            {
                string sBusinessAddress = Request.QueryString["businessaddress"].ToNonNullString();
                string sCustomerAddress = Request.QueryString["customeraddress"].ToNonNullString();
                int    nStart           = (int)GetDouble(Request.QueryString["starttime"].ToNonNullString());
                int    nEnd             = (int)GetDouble(Request.QueryString["endtime"].ToNonNullString());
                if (nEnd < nStart)
                {
                    nStart = 0;
                    nEnd   = 0;
                }
                dynamic oJson2 = PoolCommon.GetStatement(sBusinessAddress, sCustomerAddress, nStart, nEnd);
                if (oJson2 == null)
                {
                    Response.Write("<EOF>");
                    return;
                }
                dynamic oJson    = oJson2.Result;
                var     jmyc     = oJson["Charges"];
                var     jmyp     = oJson["Payments"];
                string  sTable   = "<table width=100% style='text-align:left;'>";
                string  sCharges = sTable + "<TR><TH>Date</th><th width=50%>Description<th>Amount</th></tr>";
                foreach (var jCharge in jmyc)
                {
                    string sKey         = jCharge.Name;
                    string sDesc        = jCharge.Value["Description"].Value;
                    var    nAmt         = jCharge.Value["Amount"].Value;
                    string sFromAddress = jCharge.Value["FromAddress"].Value;
                    string sName        = jCharge.Value["Name"].Value;
                    var    nTime        = jCharge.Value["Time"].Value;
                    string sRow         = "<TR><TD>" + UnixTimeStampToDateTime(nTime) + "<TD>" + sDesc + "</TD><TD>" + nAmt.ToString() + "</TR>\r\n";
                    sCharges += sRow;
                }
                sCharges += "</table>";

                string sPays = sTable + "<TR><TH>Date</th><th width=50%>Invoice Number</th><th>Amount</th></tr>";

                foreach (var jPayment in jmyp)
                {
                    string sKey           = jPayment.Name;
                    string sDesc          = jPayment.Value["Notes"].Value;
                    double nAmt           = jPayment.Value["Amount"].Value;
                    string sInvoiceNumber = jPayment.Value["InvoiceNumber"].Value;
                    var    nTime          = jPayment.Value["Time"].Value;
                    var    TXID           = jPayment.Value["TXID"].Value;
                    string sRow           = "<TR><TD>" + UnixTimeStampToDateTime(nTime) + "<td>" + sInvoiceNumber + "<td>" + nAmt.ToNonNullString() + "</td></tr>\r\n";
                    sPays += sRow;
                }

                sPays += "</table>";

                string sExtra = sTable + "<TR><TH><TH width=50%>TOTALS:</th><th>Amount</th></tr>";
                string sWords = "Prior Charges,Prior Payments,Balance Forward,Current Charges,Current Payments,Current Balance";
                string sRow1  = "<TR><TD><TD>Period Start<TD>" + UnixTimeStampToDateTime(oJson["Period Start"].Value) + "</TR>\r\n";
                sExtra += sRow1;
                string sRow2 = "<TR><TD><TD>Period End<TD>" + UnixTimeStampToDateTime(oJson["Period End"].Value) + "</TR>\r\n";
                sExtra += sRow2;

                string[] vWords = sWords.Split(",");
                for (int i = 0; i < vWords.Length; i++)
                {
                    var    nAmt = oJson[vWords[i]].Value;
                    string sRow = "<TR><TD><TD>" + vWords[i] + "<TD>" + nAmt.ToString() + "</TR>\r\n";
                    sExtra += sRow;
                }
                sExtra += "</table>";

                string HTML = UICommon.GetTableBeginning("Statement 04-24-2021 CPKABC123456");
                HTML += sCharges + "<br><br>" + sPays + "<br><br>" + sExtra;
                // To byte array here
                var result = Pdf.From(HTML).Portrait().Content();
                Response.Clear();
                Response.ContentType = "application/pdf";
                string sPeriod = UnixTimeStampToDateTime(oJson["Period Start"].Value).ToString();
                string accName = "Statement - " + sPeriod + ".pdf";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + accName);
                Response.BinaryWrite(result);
                Response.Flush();
                Response.End();
            }
            else if (sAction == "TIP")
            {
                string sToAddress = Request.QueryString["ToAddress"].ToNonNullString();
                bool   bValid     = PoolCommon.ValidateBiblepayAddress(false, sToAddress);
                double dAmt       = Code.Common.GetDouble(Request.QueryString["Amount"].ToNonNullString());
                if (gUser(this).LoggedIn == false)
                {
                    MsgBox("Log In Error", "Sorry, you must be logged in first.", this);
                    return;
                }
                double nBalance = DataOps.GetUserBalance(gUser(this).UserId);

                if (dAmt > nBalance)
                {
                    MsgBox("Balance Too Low", "Sorry, unable to tip user because your balance is too low.", this);
                    return;
                }
                if (dAmt < 0 || dAmt > 1000000)
                {
                    MsgBox("Out of Range", "Sorry you must tip between .01 and 1MM BBP.", this);
                    return;
                }

                if (!bValid)
                {
                    MsgBox("Invalid address", "Sorry, the address is invalid.", this);
                    return;
                }
                string txid = Withdraw(gUser(this).UserId, sToAddress, dAmt, "Tip to " + sToAddress);

                if (txid == "")
                {
                    MsgBox("Send Failure", "Sorry, the tip failed. Please contact [email protected]", this);
                    return;
                }
                else
                {
                    MsgBox("Success!", "You have tipped " + sToAddress + " the amount " + dAmt.ToString() + " BBP.  ", this);
                    return;
                }
            }
            else if (sAction == "XMR_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.XMR_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "DASH_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.DASH_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "LTC_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.LTC_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "ZEC_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.ZEC_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "BCH_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.BCH_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "XLM_PRICE_QUOTE")
            {
                string sXLM = Saved.Code.BMS.XLM_PRICE_QUOTE();
                Response.Write(sXLM);
                Response.End();
                return;
            }
            else if (sAction == "XRP_PRICE_QUOTE")
            {
                string s1 = Saved.Code.BMS.XRP_PRICE_QUOTE();
                Response.Write(s1);
                Response.End();
                return;
            }
            else if (sAction.Contains("GENERIC_PRICE_QUOTE"))
            {
                string[] vTicker = sAction.Split("_");
                if (vTicker.Length > 2)
                {
                    double nPQ     = Saved.Code.BMS.GetPriceQuote(vTicker[3]);
                    string sRes    = nPQ.ToString("0." + new string('#', 339));
                    string sResult = "<MIDPOINT>" + sRes + "</MIDPOINT><EOF>";
                    Response.Write(sResult);
                    Response.End();
                    return;
                }
            }
            else if (sAction == "DOGE_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.DOGE_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "ETH_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.ETH_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "MOBILE_API")
            {
                MobileAPI m = new MobileAPI();

                //string sBPQ = Saved.Code.BMS.BTC_PRICE_QUOTE();
                //string sBBP = Saved.Code.BMS.BBP_PRICE_QUOTE();
                m.BTCUSD = BMS.GetPriceQuote("BTC/USD");
                double nBBPBTC = BMS.GetPriceQuote("BBP/BTC");

                m.BBPUSD = m.BTCUSD * nBBPBTC;
                m.BBPBTC = nBBPBTC.ToString("0." + new string('#', 339));

                String json = Newtonsoft.Json.JsonConvert.SerializeObject(m);


                Response.Write(json);
                Response.End();
                return;
            }
            else if (sAction == "BTC_PRICE_QUOTE")
            {
                string sBPQ = Saved.Code.BMS.BTC_PRICE_QUOTE();
                Response.Write(sBPQ);
                Response.End();
                return;
            }
            else if (sAction == "LAST_MANDATORY_VERSION")
            {
                string LMV = Saved.Code.BMS.LAST_MANDATORY_VERSION();
                Response.Write(LMV);
                Response.End();
                return;
            }
            else if (sAction == "KAIROS_PAYMENTS")
            {
                Saved.Code.BMS.KAIROS_PAYMENTS(Response);
                return;
            }
            else if (sAction == "CAMEROON_PAYMENTS")
            {
                Saved.Code.BMS.CAMEROON_PAYMENTS(Response);
                return;
            }
            else if (sAction == "CAMEROON_CHILDREN")
            {
                Saved.Code.BMS.CAMEROON_CHILDREN(Response);
                return;
            }
            else if (sAction == "KAIROS_CHILDREN")
            {
                Saved.Code.BMS.KAIROS_CHILDREN(Response);
                return;
            }
            else if (sAction == "PoolMetrics")
            {
                string XML = BMS.GetPoolMetrics();
                Response.Write(XML);
                Response.End();
                return;
            }
            else if (sAction == "FaucetID")
            {
                string sResult = Saved.Code.BMS.FaucetID(Request);
                Response.Write(sResult);
                Response.End();
                return;
            }
            else if (sAction == "GetUTXO")
            {
                Response.Write("<EOF></HTML>\r\n");
            }
            else if (sAction == "GetUTXOData")
            {
                string sReport = DataOps.GetUTXOReport();
                Response.Write(sReport);
                Response.End();
                return;
            }
            else if (sAction == "TrackDashPay")
            {
                string sResult = Saved.Code.BMS.TrackDashPay(Request);
                Response.Write(sResult);
                Response.End();
                return;
            }
            else if (sAction == "DashPay")
            {
                string sResult = Saved.Code.BMS.DashPay(Request);
                Response.Write(sResult);
                Response.End();
                return;
            }
            else
            {
                Response.Write("<HTML>NOT FOUND</EOF>");
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Debugger.IsAttached)
            {
                CoerceUser(Session);
            }

            bool fTestNet = false;

            if (Session["chkDigital"] == null)
            {
                // first time
                Session["chkDigital"] = "1";
                Session["chkSocial"]  = "1";
            }

            if (IsPostBack)
            {
                Session["chkDigital"] = chkDigital.Checked ? "1" : "0";
                Session["chkSocial"]  = chkSocial.Checked ? "1" : "0";
            }
            chkDigital.Checked = SessionToBool(Session, "chkDigital");
            chkSocial.Checked  = SessionToBool(Session, "chkSocial");


            string sType = Request.QueryString["type"] ?? "";

            if (sType != "")
            {
                if (sType == "orphan" || sType == "goods")
                {
                    Session["NFTQueryType"] = sType;
                    Response.Redirect("NFTBrowse");
                }
                else
                {
                    MsgBox("Error", "No such nft type.", this);
                }
            }
            string sBuy = Request.QueryString["buy"] ?? "";
            string sBid = Request.QueryString["bid"] ?? "";
            string sID  = Request.QueryString["id"] ?? "";

            if (sBid == "1" && sID.Length > 10)
            {
                if (!gUser(this).LoggedIn)
                {
                    MsgBox("NFT Bid Error", "Sorry, you must log in first to bid on an NFT.", this);
                }


                double nOffer = GetDouble(Request.QueryString["amount"] ?? "");

                DACResult d = BuyNFT1(gUser(this).UserId, sID, nOffer, true, fTestNet);
                if (d.sError != "")
                {
                    MsgBox("NFT Bid Error", d.sError, this);
                }
                else
                {
                    MsgBox("Success", "You have bidded " + nOffer.ToString() + " BBP on this NFT.", this);
                }
            }

            if (sBuy == "1" && sID.Length > 10)
            {
                if (!gUser(this).LoggedIn)
                {
                    MsgBox("NFT Buy Error", "Sorry, you must log in first to buy an NFT.", this);
                }

                Code.PoolCommon.NFT myNFT = GetSpecificNFT(sID, fTestNet);

                DACResult d       = BuyNFT1(gUser(this).UserId, sID, myNFT.nBuyItNowAmount, false, fTestNet);
                bool      fOrphan = myNFT.Type.ToLower().Contains("orphan");

                if (d.sError != "")
                {
                    MsgBox("NFT Buy Error", d.sError, this);
                }
                else
                {
                    string sNarr = fOrphan ? "You have successfully sponsored this Orphan!" : "You are now the proud new owner of an NFT.";
                    MsgBox("Success", sNarr + "<br><br> Please see your biblepaycore home wallet NFT list to find "
                           + d.sTXID + ".  <br><br> Please wait a few blocks for the ownership to be transferred.  <br><br>You can also view your NFT <a href='NFTList'>here.</a>", this);
                }
            }
        }