Esempio n. 1
0
        protected void updatePayPalData(PDTData data, PAYPAL_PAYMENT pp, string originalResponse)
        {
            pp.TransactionStatus = data.PaymentStatus;
            pp.Response          = originalResponse;
            ApplicationContext.Current.Payments.UpdatePayPalPayment(pp, false);

            if (data.PaymentStatus.ToUpper() == "COMPLETED")
            {
                ORDERS order = ApplicationContext.Current.Orders.GetById(pp.ID);
                order.Completed = true;
                ApplicationContext.Current.Orders.Update(order, false);
            }
            else if (data.PaymentStatus.ToUpper() == "REFUNDED" || data.PaymentStatus.ToUpper() == "REVERSED")
            {
                ORDERS order = ApplicationContext.Current.Orders.GetById(pp.ID);
                order.Completed = false;
                order.Canceled  = true;
                // I anulluar / canceled
                order.Status   = 6;
                order.Comments = order.Comments + "Order was canceled because: " + data.PaymentStatus;
                ApplicationContext.Current.Orders.Update(order, false);
                BasePage.Log(null, "PayPal Reversal/Refund: " + data.PaymentStatus + " TxnId: " + pp.TransactionKey + "\n Response: " + originalResponse, "", "IPN Handler");
                Thread thread = new Thread(() => BasePage.sendMailToAdmins("PayPal payment " + data.PaymentStatus + " for Order: " + pp.ID, "A " + data.PaymentStatus + " IPN was notified for order " + pp.ID +
                                                                           " from " + data.PayerEmail + " for the amount " + data.GrossTotal + " " + data.Currency));
                thread.Start();
            }
            else
            {
                BasePage.Log(null, "Payment status from PayPal not handled: " + data.PaymentStatus + "\n Response: " + originalResponse, "", "IPN Handler");
            }
        }
        public void DeleteById(int Id)
        {
            PAYPAL_PAYMENT pPayment = new PAYPAL_PAYMENT()
            {
                ID = Id
            };

            Delete(pPayment);
        }
        public void Update(PAYPAL_PAYMENT PP, bool Attach = true)
        {
            if (Attach)
            {
                Context.PAYPAL_PAYMENT.Attach(PP);
            }
            var entry = Context.ObjectStateManager.GetObjectStateEntry(PP);

            entry.SetModifiedProperty("TransactionStatus");
            entry.SetModifiedProperty("Response");
        }
Esempio n. 4
0
 public void UpdatePayPalPayment(PAYPAL_PAYMENT PP, bool Attach = true)
 {
     _paypalPaymentDAO.Update(PP, Attach);
     Context.SaveChanges();
 }
Esempio n. 5
0
 public void UpdatePayPalPayment(PAYPAL_PAYMENT PPayment)
 {
     _paypalPaymentDAO.Update(PPayment, true);
     Context.SaveChanges();
 }
Esempio n. 6
0
        protected void processRequest()
        {
            try
            {
                string         postUrl = Configuration.PaypalEnv;
                HttpWebRequest req     = (HttpWebRequest)WebRequest.Create(postUrl);

                //Set values for the request back
                req.Method      = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                byte[] param      = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
                string strRequest = Encoding.ASCII.GetString(param);
                string ipnPost    = strRequest;
                strRequest       += "&cmd=_notify-validate";
                req.ContentLength = strRequest.Length;

                //Send the request to PayPal and get the response
                StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                streamOut.Write(strRequest);
                streamOut.Close();

                StreamReader streamIn    = new StreamReader(req.GetResponse().GetResponseStream());
                string       strResponse = streamIn.ReadToEnd();
                streamIn.Close();

                if (strResponse == "VERIFIED")
                {
                    strRequest = HttpUtility.UrlDecode(strRequest);
                    strRequest = strRequest.Replace('&', '\n');
                    PDTData pdt = PDTData.Parse(strRequest, true);
                    //check that receiver_email is your Primary PayPal email
                    if (pdt.ReceiverEmail != Configuration.PaypalSellerEmail)
                    {
                        BasePage.Log(null, "PayPal receiver email different from default:" + pdt.ReceiverEmail + " - txnID: " + pdt.TransactionId, "", "IPN Handler");
                        return;
                    }

                    //check that payment_amount/payment_currency are correct
                    if (pdt.Currency != Configuration.PaypalCurrency)
                    {
                        BasePage.Log(null, "PayPal currency different from default:" + pdt.ReceiverEmail + " - txnID: " + pdt.TransactionId, "", "IPN Handler");
                        return;
                    }

                    //check the payment_status is Completed

                    //check that txn_id has not been previously processed
                    PAYPAL_PAYMENT       pp    = ApplicationContext.Current.Payments.GetByTxnId(pdt.TransactionId);
                    List <SHOPPING_CART> carts = ApplicationContext.Current.Carts.GetShoppingCartItems(pdt.Invoice);

                    if (pdt.PaymentStatus.ToUpper() == "COMPLETED" || pdt.PaymentStatus.ToUpper() == "PENDING" || pdt.PaymentStatus.ToUpper() == "PROCESSED")
                    {
                        // first time proccessing for this payment
                        if (pp == null && carts != null && carts.Count > 0)
                        {
                            savePayPalOrder(pdt, carts, strRequest);
                        }
                        else if (pp == null)
                        {
                            BasePage.Log(null, "PayPal " + pdt.PaymentStatus + " TxnId: " + pdt.TransactionId + " but CART EXPIRED \n Response: " + strRequest, "", "IPN Handler");
                            BasePage.sendMailToAdmins("PayPal payment " + pdt.PaymentStatus + " but cart expired. PLACE REFUND!", "A " + pdt.PaymentStatus + " IPN was notified for cart " + pdt.Invoice +
                                                      " from " + pdt.PayerEmail + " for the amount " + pdt.GrossTotal + " " + pdt.Currency + " but the cart expired. \nProceed with REFUND!");
                        }
                    }
                    else
                    {
                        //In the case of a refund, reversal, or canceled reversal
                        if (pp == null && !String.IsNullOrWhiteSpace(pdt.ParentTransactionId))
                        {
                            pp = ApplicationContext.Current.Payments.GetByTxnId(pdt.ParentTransactionId);
                        }
                    }
                    // update of existing paypal transaction
                    if (pp != null)
                    {
                        updatePayPalData(pdt, pp, strRequest);
                    }
                }
                else if (strResponse == "INVALID")
                {
                    BasePage.Log(null, "Invalid IPN request" + strRequest, "", "IPN Handler");
                }
                else
                {
                    BasePage.Log(null, "IPN request" + strRequest, "", "IPN Handler");
                }
            }
            catch (Exception ex)
            {
                BasePage.Log(ex, ex.Message, ex.StackTrace, "paypalSuccess.Save");
            }
        }
 public void Delete(PAYPAL_PAYMENT Entity)
 {
     Context.PAYPAL_PAYMENT.Attach(Entity);
     Context.DeleteObject(Entity);
 }
 public void Update(PAYPAL_PAYMENT Entity)
 {
     Update(Entity, true);
 }
 public void Insert(PAYPAL_PAYMENT Entity)
 {
     Context.PAYPAL_PAYMENT.AddObject(Entity);
 }
Esempio n. 10
0
 public List <PAYPAL_PAYMENT> Search(PAYPAL_PAYMENT Entity, int PageSize, int PageIndex, out int TotalRecords, string OrderExp, Util.SortDirection SortDirection)
 {
     throw new NotImplementedException();
 }