Exemplo 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");
            }
        }
Exemplo n.º 2
0
        public static PDTData Parse(string postData, bool IPN)
        {
            String  sKey, sValue;
            PDTData ph = new PDTData();

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:

                /*
                 * loop is set to start at 1 rather than 0 because first
                 * string in array will be single word SUCCESS or FAIL
                 * Only used to verify post data
                 */
                CultureInfo ci = new CultureInfo("en-US");
                // use split to split array we already have using "=" as delimiter
                int i;
                for (i = 0; i < StringArray.Length - 1; i++)
                {
                    if (!IPN && i == 0)
                    {
                        continue;
                    }
                    String[] StringArray1 = StringArray[i].Split('=');

                    if (StringArray1.Length < 2)
                    {
                        continue;
                    }
                    sKey   = StringArray1[0];
                    sValue = StringArray1[1];

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                    case "mc_gross":
                        ph.GrossTotal = Convert.ToDecimal(sValue, ci);
                        break;

                    case "mc_fee":
                        ph.Fee = Convert.ToDecimal(sValue, ci);
                        break;

                    case "invoice":
                        ph.Invoice = sValue;
                        break;

                    case "payment_status":
                        ph.PaymentStatus = Convert.ToString(sValue);
                        break;

                    case "payment_date":
                        ph.PaymentDate = ConvertPayPalDateTime(sValue);
                        break;

                    case "first_name":
                        ph.PayerFirstName = Convert.ToString(sValue);
                        break;

                    case "business":
                        ph.BusinessEmail = Convert.ToString(sValue);
                        break;

                    case "payer_email":
                        ph.PayerEmail = Convert.ToString(sValue);
                        break;

                    case "Tx Token":
                        ph.TxToken = Convert.ToString(sValue);
                        break;

                    case "last_name":
                        ph.PayerLastName = Convert.ToString(sValue);
                        break;

                    case "receiver_email":
                        ph.ReceiverEmail = Convert.ToString(sValue);
                        break;

                    case "mc_currency":
                        ph.Currency = Convert.ToString(sValue);
                        break;

                    case "txn_id":
                        ph.TransactionId = Convert.ToString(sValue);
                        break;

                    case "custom":
                        ph.Custom = Convert.ToString(sValue);
                        break;

                    case "subscr_id":
                        ph.SubscriberId = Convert.ToString(sValue);
                        break;

                    case "payer_status":
                        ph.PayerStatus = Convert.ToString(sValue);
                        break;

                    case "parent_txn_id":
                        ph.ParentTransactionId = Convert.ToString(sValue);
                        break;
                    }
                }

                return(ph);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        protected void savePayPalOrder(PDTData data, List<SHOPPING_CART> carts, string originalResponse)
        {
            CultureInfo ci = new CultureInfo("en-US");
            string cartID = data.Invoice;
            if (carts != null && carts.Count > 0)
            {
                decimal total = ApplicationContext.Current.Carts.GetShoppingCartTotalAmount(cartID).Value;

                ORDERS order = new ORDERS();

                int addrID = 0;
                // Bonus has been used
                if (total != data.GrossTotal)
                {
                    string[] custom = data.Custom.Split('-');
                    if (custom.Length == 3)
                    {
                        decimal bonus = Convert.ToDecimal(custom[2], ci);
                        int bonusID = Convert.ToInt32(custom[1]);
                        addrID = Convert.ToInt32(custom[0]);
                        if (bonus == total - data.GrossTotal)
                        {
                            setBonus(order, bonusID, bonus);
                        }
                        else
                        {
                            BasePage.Log(null, "IPN order save - bonus MANIPULATION. Original:" + (total - data.GrossTotal) + " new: " + bonus +
                                " - txnID: " + data.TransactionId, "", "IPN Handler");
                            return;
                        }
                    }
                }
                else
                {
                    addrID = Convert.ToInt32(data.Custom);
                }

                order.TotalAmount = total;
                order.AmountPaid = data.GrossTotal;
                order.Verified = false;
                order.Canceled = false;
                if (data.PaymentStatus.ToUpper() == "COMPLETED")
                {
                    order.Completed = true;
                }
                else
                {
                    order.Completed = false;
                }
                order.Status = 1;

                try
                {
                    order.CustomerID = carts.First().CustomerID;

                    order.PAYMENT = new PAYMENT() { Type = 2 };
                    order.PAYMENT.PAYPAL_PAYMENT = new PAYPAL_PAYMENT()
                    {
                        Amount = data.GrossTotal,
                        CartID = cartID,
                        PaidOn = DateTime.Now,
                        Currency = data.Currency,
                        Fee = data.Fee,
                        PayerEmail = data.PayerEmail,
                        TransactionKey = data.TransactionId,
                        PayerName = data.PayerFirstName + " " + data.PayerLastName,
                        PaypalEmail = data.ReceiverEmail,
                        Response = originalResponse,
                        TransactionStatus = data.PaymentStatus,
                        PayerStatus = data.PayerStatus
                    };

                    // for now it is set to carrier without a fee
                    order.ShippingID = 3;

                    order.DateCreated = DateTime.Now;
                    ADDRESS addr = ApplicationContext.Current.Customers.GetAddressById(addrID);
                    // addresses
                    if (addr != null)
                    {
                        ADDRESSINFO shipping = new ADDRESSINFO(addr);
                        order.ADDRESSINFO = shipping;
                    }
                    //inserting and not saving as the saving will be done in the details insertion
                    ApplicationContext.Current.Orders.Insert(order, true, false);

                    // inserting the products of this order

                    ApplicationContext.Current.Orders.InsertDetailsFromCart(order, carts, false);

                    List<ORDER_DETAIL> details = ApplicationContext.Current.Orders.GetDetails(order.ID);

                    CUSTOMER customer = ApplicationContext.Current.Customers.GetById(carts[0].CustomerID);

                    Thread thread = new Thread(() => BasePage.sendOrderMailToAdmins(details, "PayPal", "PayPal Order", order.TotalAmount, customer.Name + " " + customer.Surname));
                    thread.Start();

                    Thread thread2 = new Thread(() => BasePage.sendOrderMailToCustomer(customer, details, "Porosia ne FZone.al"));
                    thread2.Start();
                }
                catch (System.Threading.ThreadAbortException ex)
                {
                }
                catch (Exception e)
                {
                    //TODO log exception
                    BasePage.Log(e, e.Message, e.StackTrace, "paypalSuccess.Save");
                }
            }
        }
Exemplo n.º 4
0
        public static PDTData Parse(string postData, bool IPN)
        {
            String sKey, sValue;
            PDTData ph = new PDTData();

            try
            {
                //split response into string array using whitespace delimeter
                String[] StringArray = postData.Split('\n');

                // NOTE:
                /*
                * loop is set to start at 1 rather than 0 because first
                string in array will be single word SUCCESS or FAIL
                Only used to verify post data
                */
                CultureInfo ci = new CultureInfo("en-US");
                // use split to split array we already have using "=" as delimiter
                int i;
                for (i = 0; i < StringArray.Length - 1; i++)
                {
                    if (!IPN && i == 0)
                    {
                        continue;
                    }
                    String[] StringArray1 = StringArray[i].Split('=');

                    if (StringArray1.Length < 2)
                    {
                        continue;
                    }
                    sKey = StringArray1[0];
                    sValue = StringArray1[1];

                    // set string vars to hold variable names using a switch
                    switch (sKey)
                    {
                        case "mc_gross":
                            ph.GrossTotal = Convert.ToDecimal(sValue, ci);
                            break;

                        case "mc_fee":
                            ph.Fee = Convert.ToDecimal(sValue, ci);
                            break;

                        case "invoice":
                            ph.Invoice = sValue;
                            break;

                        case "payment_status":
                            ph.PaymentStatus = Convert.ToString(sValue);
                            break;

                        case "payment_date":
                            ph.PaymentDate = ConvertPayPalDateTime(sValue);
                            break;

                        case "first_name":
                            ph.PayerFirstName = Convert.ToString(sValue);
                            break;

                        case "business":
                            ph.BusinessEmail = Convert.ToString(sValue);
                            break;

                        case "payer_email":
                            ph.PayerEmail = Convert.ToString(sValue);
                            break;

                        case "Tx Token":
                            ph.TxToken = Convert.ToString(sValue);
                            break;

                        case "last_name":
                            ph.PayerLastName = Convert.ToString(sValue);
                            break;

                        case "receiver_email":
                            ph.ReceiverEmail = Convert.ToString(sValue);
                            break;

                        case "mc_currency":
                            ph.Currency = Convert.ToString(sValue);
                            break;

                        case "txn_id":
                            ph.TransactionId = Convert.ToString(sValue);
                            break;

                        case "custom":
                            ph.Custom = Convert.ToString(sValue);
                            break;

                        case "subscr_id":
                            ph.SubscriberId = Convert.ToString(sValue);
                            break;

                        case "payer_status":
                            ph.PayerStatus = Convert.ToString(sValue);
                            break;

                        case "parent_txn_id":
                            ph.ParentTransactionId = Convert.ToString(sValue);
                            break;
                    }
                }

                return ph;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }