コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            NVPAPICaller PPAPICaller = new NVPAPICaller();
            NVPCodec decoder = new NVPCodec();
            string token = string.Empty;
            string payerID = string.Empty;
            string finalPaymentAmount = string.Empty;
            string retMsg = string.Empty;
            string currency = string.Empty;

            token = Session["token"].ToString();

            //use the PayPal token to get the details of payment - this could include shipping details
            bool ret = PPAPICaller.GetCheckoutDetails(token, ref decoder, ref retMsg);
            if (ret)
            {
                payerID = decoder["PayerID"];
                token = decoder["token"];
                finalPaymentAmount = decoder["PAYMENTREQUEST_0_AMT"];
                currency = decoder["CURRENCYCODE"];

            }
            else
            {
                //error.LogError();
                return;
            }

            NVPCodec confirmdecoder = new NVPCodec();

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

            //confirm that payment was taken
            bool ret2 = PPAPICaller.DoCheckoutPayment(finalPaymentAmount, ShoppingCartID, token, payerID, ref confirmdecoder, ref retMsg);
            if (ret2)
            {
                //if payment was taken do some back end processing to mark order as paid
                //use token to work out which order to mark as paid

                token = confirmdecoder["token"];
                string auth_status = "approved";
                string auth_code = token;
                string auth_message = "paypal transaction approved";
                string auth_response_code = string.Empty;
                string auth_transaction_id = token;

                try
                {
                    controller.UpateCMEDShopTransactionByOrderID(ShoppingCartID,
                                        auth_status,
                                        auth_code,
                                        auth_message,
                                        auth_response_code,
                                        auth_transaction_id);

                    //create order from cart
                    long order_id = controller.CreateOrderFromCart(ShoppingCartID);

                    HttpCookie Checkout = new HttpCookie("Confirmation");
                    Checkout["Email"] = Request.Cookies["email"].Value;
                    Checkout["WorkShopName"] = Request.Cookies["WorkShopName"].Value;
                    Checkout.Expires = DateTime.Now.AddMinutes(30);
                    Response.Cookies.Add(Checkout);

                    CMEDShopOrder order = controller.LoadOrder(order_id);

                    CMEDShopTransaction transaction = controller.GetCMEDShopTransactionByOrderID(order_id);
                    Util.SendWelcomeMailWorkShopBalance(transaction, decimal.Parse(Request.Cookies["Balance"].Value), Request.Cookies["WorkShopName"].Value);

                    String s = "CMEDWorkshopPurchaseThankYou.aspx";

                    Response.Redirect(s);

                }
                catch (PayPalAuthourize ex)
                {
                    throw ex;

                }

            }
            else
            {
                string msg = "PayPal is not responding, please try again in a few moments.";
                throw new PayPalAuthourize(msg);

            }
        }
コード例 #2
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;

                }

            }
        }
コード例 #3
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;

            }
        }