public ActionResult IPN() { var formVals = new Dictionary<string, string>(); formVals.Add("cmd", "_notify-validate"); string response = GetPayPalResponse(formVals, true); if (response == "VERIFIED") { string transactionID = Request["txn_id"]; string sAmountPaid = Request["mc_gross"]; string orderID = Request["custom"]; //_logger.Info("IPN Verified for order " + orderID); //validate the order Decimal amountPaid = 0; Decimal.TryParse(sAmountPaid, out amountPaid); //Order order = _orderService.GetOrder(new Guid(orderID)); Order order = null; //check the amount paid if (AmountPaidIsValid(order, amountPaid)) { Address add = new Address(); add.FirstName = Request["first_name"]; add.LastName = Request["last_name"]; add.Email = Request["payer_email"]; add.Street1 = Request["address_street"]; add.City = Request["address_city"]; add.StateOrProvince = Request["address_state"]; add.Country = Request["address_country"]; add.Zip = Request["address_zip"]; add.UserName = order.UserName; //process it try { //_pipeline.AcceptPalPayment(order, transactionID, amountPaid); //_logger.Info("IPN Order successfully transacted: " + orderID); return RedirectToAction("Receipt", "Order", new { id = order.ID }); } catch { //HandleProcessingError(order, x); return View(); } } else { //let fail - this is the IPN so there is no viewer } } return View(); }
/// <summary> /// Handles the PDT Response from PayPal /// </summary> /// <returns></returns> public ActionResult PDT() { //_logger.Info("PDT Invoked"); string transactionID = Request.QueryString["tx"]; string sAmountPaid = Request.QueryString["amt"]; string orderID = Request.QueryString["cm"]; Dictionary<string, string> formVals = new Dictionary<string, string>(); formVals.Add("cmd", "_notify-synch"); formVals.Add("at", SiteData.PayPalPDTToken); formVals.Add("tx", transactionID); string response = GetPayPalResponse(formVals, true); //_logger.Info("PDT Response received: " + response); if (response.StartsWith("SUCCESS")) { //_logger.Info("PDT Response received for order " + orderID); //validate the order Decimal amountPaid = 0; Decimal.TryParse(sAmountPaid, out amountPaid); Order order = null; if (AmountPaidIsValid(order, amountPaid)) { Address add = new Address(); add.FirstName = GetPDTValue(response, "first_name"); add.LastName = GetPDTValue(response, "last_name"); add.Email = GetPDTValue(response, "payer_email"); add.Street1 = GetPDTValue(response, "address_street"); add.City = GetPDTValue(response, "address_city"); add.StateOrProvince = GetPDTValue(response, "address_state"); add.Country = GetPDTValue(response, "address_country"); add.Zip = GetPDTValue(response, "address_zip"); add.UserName = order.UserName; //process it try { // _pipeline.AcceptPalPayment(order, transactionID, amountPaid); // _logger.Info("PDT Order successfully transacted: " + orderID); return RedirectToAction("Receipt", "Order", new { id = order.ID }); } catch { //HandleProcessingError(order, x); return View(); } } else { //Payment amount is off //this can happen if you have a Gift cert at PayPal //be careful of this! //HandleProcessingError(order, new InvalidOperationException("Amount paid (" + amountPaid.ToString("C") + ") was below the order total")); return View(); } } else { ViewData["message"] = "Your payment was not successful with PayPal"; return View(); } }