Exemplo n.º 1
0
        string CheckoutResponse(HttpListenerRequest request)
        {
            string post = "";

            if (request.HttpMethod == "POST")
            {
                using (System.IO.StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding))
                {
                    post = reader.ReadToEnd();
                }
            }
            System.Diagnostics.Debug.WriteLine(post);
            try
            {
                string[] pieces = post.Split('&');
                Dictionary <string, string> args = new Dictionary <string, string>();
                foreach (string piece in pieces)
                {
                    string[] kv = piece.Split('=');
                    args[kv[0]] = kv[1];
                }

                string purchaseResult = BraintreeManager.DoPurchase(args["payment_method_nonce"], args["uid"], args["pid"]);
                string html           = LoadPurchaseCompleteHtml();
                html = html.Replace("PRODUCT_ID", args["pid"]);

                return(html);
                //return string.Format("<HTML><BODY>Thank you!<br>{0}</BODY></HTML>", purchaseResult);
            }
            catch (Exception ex)
            {
                return(string.Format("<HTML><BODY>Data Error <br /> {0}</BODY></HTML>", ex.ToString()));
            }
        }
Exemplo n.º 2
0
        string PurchaseResponse(HttpListenerRequest request)
        {
            //return string.Format("<HTML><BODY>My web page.<br>{0}<br>{1}<br>{2}</BODY></HTML>", DateTime.Now, request.QueryString["uid"], request.QueryString["pid"]);

            System.Diagnostics.Debug.WriteLine(request.RawUrl);
            GlobalProduct prod = Marketplace.Instance.GetProduct(request.QueryString["pid"]);

            if (prod == null)
            {
                return("<HTML><BODY>Invalid Product</BODY></HTML>");
            }

            string html = LoadPurchaseHtml();

            html = html.Replace("CLIENT_AUTH_TOKEN", BraintreeManager.GetClientToken(request.QueryString["uid"]));
            html = html.Replace("PAYPAL_AMOUNT_TOKEN", prod.USD.ToString());
            html = html.Replace("PAYPAL_CURRENCY_TOKEN", "USD");

            html = html.Replace("COIN_AMMOUNT", prod.Coins.ToString());
            html = html.Replace("VIP_AMMOUNT", prod.VIP.ToString());
            html = html.Replace("USD_AMMOUNT", prod.USD.ToString());

            html = html.Replace("USER_ID", request.QueryString["uid"]);
            html = html.Replace("PRODUCT_ID", request.QueryString["pid"]);

#if DEBUG
            html = html.Replace("BRAINTREE_PREFIX", "");
#else
            html = html.Replace("BRAINTREE_PREFIX", "http://www.ronzgames.com/braintree");
#endif

            return(html);
        }