Exemplo n.º 1
0
        protected void btn_SubmitPaypal_Click(object sender, ImageClickEventArgs e)
        {
            var id = txtID.Value;

            if (Request.Cookies["email"] == null)
            {
                FormsAuthentication.SignOut();
                FormsAuthentication.RedirectToLoginPage();

            }

            var email = Request.Cookies["email"].Value;

            CMEDWorkShopBalance objbalance = controller.GetCMEDWorkShopBalancePayment(Convert.ToInt32(id), email.ToString());
            workshop = controller.GetCMEDWorkShop(Convert.ToInt32(id));

            if (!string.IsNullOrEmpty(id))
            {
                if (Helper.IsNumeric(id))
                {

                    Price = Convert.ToInt32(objbalance.balance);

                }
                else
                {
                    Response.Redirect("http://www.myss.com/");
                }

                long ShoppingCartID = controller.IssueNewGlobalID();
                Response.Cookies["ShoppingCartID"].Value = ShoppingCartID.ToString();

                try
                {
                    controller.SaveCartItem(workshop.ProductID, Price, ShoppingCartID, EmailTextBox.Text.Trim(), GetUserIP());
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                string auth_status = string.Empty;
                string auth_code = string.Empty;
                string auth_message = string.Empty;
                string auth_response_code = string.Empty;
                string auth_transaction_id = string.Empty;

                CMEDShopTransaction transaction = new CMEDShopTransaction
                {
                    order_id = ShoppingCartID,
                    first_name = FirstNameTextBox.Text,
                    last_name = LastNameTextBox.Text,
                    address = AddressTextBox.Text,
                    city = CityTextBox.Text,
                    state = State.SelectedValue,
                    postal_code = ZipTextBox.Text,
                    email = EmailTextBox.Text,
                    phone_number = PhoneNumberTextBox.Text,
                    transaction_type = "Credit Card",
                    status = "in-progress"
                };

                try
                {
                    if (Request.Cookies["TransactionID"] == null)
                    {
                        long transaction_id = controller.CreateCMEDShopTransaction(transaction);

                        //write the cookie of transaction_id for use later
                        Response.Cookies["TransactionID"].Value = transaction_id.ToString();

                    }

                    Cart cart = controller.LoadCart(ShoppingCartID);
                    if (cart.order_amount == 0)
                    {
                        Response.Redirect(redirectPage);
                    }

                    NVPAPICaller payPalCaller = new NVPAPICaller();
                    string retTokenMsg = "";
                    string token = "";
                    NVPCodec decoder = new NVPCodec();
                    string amt01 = cart.order_amount.ToString();

                    bool retToken = payPalCaller.ShortcutExpressCheckout(amt01, ShoppingCartID, ref token, ref retTokenMsg, true);
                    if (retToken)
                    {
                        HttpContext.Current.Session["token"] = token;
                        Response.Redirect(retTokenMsg);
                    }
                    else
                    {
                        lblErrorMessage.Text = "PayPal is not responding, please try again in a few moments.";
                    }

                }
                catch (Exception ex)
                {

                    throw ex;

                }

            }
        }
Exemplo n.º 2
0
        protected void btn_SubmitPaypal_Click(object sender, ImageClickEventArgs e)
        {
            //grab shopping cart id cookie

            if (Request.Cookies["ShoppingCartID"] != null)
            {
                ShoppingCartID = long.Parse(Request.Cookies["ShoppingCartID"].Value);
            }
            else
            {
                Response.Redirect(redirectPage);
            }

            //decimal amt = 0;

            CMEDShopTransaction transaction = new CMEDShopTransaction
            {
                order_id = ShoppingCartID,
                first_name = FirstNameTextBox.Text,
                last_name = LastNameTextBox.Text,
                address = AddressTextBox.Text,
                city = CityTextBox.Text,
                state = drpState.SelectedValue,
                postal_code = ZipTextBox.Text,
                email = EmailTextBox.Text,
                phone_number = PhoneNumberTextBox.Text,
                transaction_type = "PayPal",
                status = "in-progress"
            };

            try
            {
                //check transaction_id cookie and if there then dont call create transaction
                if (Request.Cookies["TransactionID"] == null)
                {

                    long transaction_id = controller.CreateCMEDShopTransaction(transaction);

                    //write the cookie of transaction_id for use later
                    Response.Cookies["TransactionID"].Value = transaction_id.ToString();
                }

                Cart cart = controller.LoadCart(ShoppingCartID);
                if (cart.order_amount == 0)
                {
                    Response.Redirect(redirectPage);
                }

                NVPAPICaller payPalCaller = new NVPAPICaller();
                string retTokenMsg = "";
                string token = "";
                NVPCodec decoder = new NVPCodec();
                string amt01 = cart.order_amount.ToString();

                bool retToken = payPalCaller.ShortcutExpressCheckout(amt01, ShoppingCartID, ref token, ref retTokenMsg, false);
                if (retToken)
                {
                    HttpContext.Current.Session["token"] = token;
                    Response.Redirect(retTokenMsg);
                }
                else
                {
                    lblErrorMessage.Text = "PayPal is not responding, please try again in a few moments.";
                }

            }
            catch (Exception ex)
            {

                throw ex;

            }
        }