Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Log this so we can investigate if something goofy happens
              Logger.Information(string.Format("{0}::{1}", "REQUEST", Request.Form.ToString()));

              //Per PayPal Order Management / Integration Guide Pg.25
              //we have to validate the price, transactionId, etc.
              string transactionId = Request.Form["txn_id"].ToString();
              string orderId = Request.Form["custom"].ToString();
              string amount = Request.Form["mc_gross"].ToString();
              decimal parsedAmount = 0.00M;
              bool isParsed = decimal.TryParse(amount, out parsedAmount);
              string paymentStatus = Request.Form["payment_status"].ToString();
              string receiverEmail = Request.Form["receiver_email"].ToString();

              if (transactionId.IndexOf(",") > -1) {
            transactionId = transactionId.Substring(0, transactionId.IndexOf(",", 0));
            transactionId = HttpUtility.UrlDecode(transactionId);
              }
              if (orderId.IndexOf(",") > -1) {
            orderId = orderId.Substring(0, orderId.IndexOf(",", 0));
            orderId = HttpUtility.UrlDecode(orderId);
              }
              byte[] buffer = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
              string formValues = System.Text.Encoding.ASCII.GetString(buffer);
              //string formValues = Request.Form.ToString();
              string response = Verify(formValues);
              if (response.StartsWith("VERIFIED")) {
            OrderController orderController = new OrderController();
            Guid orderGuid = new Guid(orderId);
            Order order = orderController.FetchOrder(orderGuid);
            if (order.OrderId > 0) {
              //check the payment_status is Completed
              //check that txn_id has not been previously processed
              //check that receiver_email is your Primary PayPal email
              //check that payment_amount/payment_currency are correct

              //TODO: CMC: Need to update the PayPalProConfiguration with preferred business email

              if ((paymentStatus.ToUpper().Equals("COMPLETED") && (order.OrderStatusDescriptorId == (int)OrderStatus.NotProcessed) && (order.Total == parsedAmount))) {
            Transaction transaction = OrderController.CommitStandardTransaction(order, transactionId, decimal.Parse(amount));
            Logger.Information(string.Format("{0}::{1}", "IPN", order.OrderNumber));
            //Send response 200
            Response.StatusCode = (int)System.Net.HttpStatusCode.OK;
            Response.Flush();
            Response.End();
              }
            }
              }
              else {
            Logger.Information(string.Format("{0}::{1}", "RESPONSE", HttpUtility.HtmlEncode(response)));
              }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
            //Log the querystring in case we have to investigate
            Logger.Information(Request.QueryString.ToString());

            string transactionId = Request.QueryString["tx"];
            string orderId = Request.QueryString["cm"];

            if (transactionId.IndexOf(",") > -1) {
              transactionId = transactionId.Substring(0, transactionId.IndexOf(",", 0));
              transactionId = HttpUtility.UrlDecode(transactionId);
            }
            else {
              transactionId = HttpUtility.UrlDecode(transactionId);
            }
            if (orderId.IndexOf(",") > -1) {
              orderId = orderId.Substring(0, orderId.IndexOf(",", 0));
              orderId = HttpUtility.UrlDecode(orderId);
            }
            else {
              orderId = HttpUtility.UrlDecode(orderId);
            }

            string response = Synchronize(transactionId);
            if (response.StartsWith("SUCCESS")) {
              string grossAmt = GetPDTValue(response, "mc_gross");
              decimal grossAmount = 0;
              decimal.TryParse(grossAmt, out grossAmount);
              OrderController orderController = new OrderController();
              Guid orderGuid = new Guid(orderId);
              Order order = orderController.FetchOrder(orderGuid);
              if (order.OrderId > 0) {
            Transaction transaction = null;
            if (order.OrderStatusDescriptorId == (int)OrderStatus.NotProcessed) {//then it hasn't been pinged by the ipn service
              transaction = OrderController.CommitStandardTransaction(order, transactionId, grossAmount);
              Logger.Information(string.Format("{0}::{1}", "PDT", order.OrderNumber));
            }
            else {//it has been pinged by the ipn service, so just grab the transaction
              transaction = new Transaction(Transaction.Columns.OrderId, order.OrderId);
            }
            Response.Redirect(string.Format("~/receipt.aspx?tid={0}", transaction.TransactionId), true);
              }
            }
              }
              catch (System.Threading.ThreadAbortException) {
            throw;
              }
              catch (Exception ex) {
            Logger.Error(typeof(pdthandler).Name, ex);
              }
        }