Пример #1
0
    //Get PayPal Token and redirect to pay pal
    protected void ibGetPaypalToken_Click(object sender, ImageClickEventArgs e)
    {
        //set the Order object
        if (this.LiveFreeRangePage.IsValid)
        {
            //this.LiveFreeRangePage.CurrentEndUser.FirstName = this.txtFirstName.Text;
            //this.LiveFreeRangePage.CurrentEndUser.LastName = this.txtLastName.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.AddressLine = this.txtAddress.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.AddressLine2 = this.txtAddress2.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.City = this.txtCity.Text;
            //this.LiveFreeRangePage.CurrentEndUser.Address.PostalCode = this.txtPostalCode.Text;

            //this.LiveFreeRangePage.CurrentOrder = new Orders();
            //this.LiveFreeRangePage.CurrentOrder.Enduser.FirstName = this.txtFirstName.Text;
            //this.LiveFreeRangePage.CurrentOrder.Enduser.LastName = this.txtLastName.Text;

            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.AddressLine = this.txtAddress.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.AddressLine2 = this.txtAddress2.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.City = this.txtCity.Text;
            //this.LiveFreeRangePage.CurrentOrder.ShippingAddress.PostalCode = this.txtPostalCode.Text;

            //this.LiveFreeRangePage.CurrentOrder.CreditCard.CardType = this.ddlCreditCardType.SelectedItem.Value;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Number = this.txtCreditCardNumber.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.SecurityCode = this.txtSecurityCode.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.ExpMonth = int.Parse(this.ddlExpMonth.SelectedItem.Text);
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.ExpYear = int.Parse(this.ddlExpYear.SelectedItem.Text);

            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.AddressLine = this.txtBillingAddress.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.AddressLine2 = this.txtBillingAddress2.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.City = this.txtBillingCity.Text;
            //this.LiveFreeRangePage.CurrentOrder.CreditCard.Address.PostalCode = this.txtBillingPostalCode.Text;

            this.LiveFreeRangePage.CurrentOrder = new Orders();
            this.litTax.Text = this.litTax.Text.Replace("£", "");
            this.LiveFreeRangePage.CurrentOrder.Tax = Convert.ToDecimal(litTax.Text);

            this.litSubTotal.Text = this.litSubTotal.Text.Replace("£", "");
            this.LiveFreeRangePage.CurrentOrder.SubTotal = Convert.ToDecimal(this.litSubTotal.Text);

            this.LiveFreeRangePage.CurrentOrder.ShippingTotal = Convert.ToDecimal(ddlShippingOption.SelectedItem.Value);

            //add order object to paypal information object
            PayPalManager payPal = new PayPalManager();
            PayPalInformation payPalInformation = new PayPalInformation();
            payPalInformation.Order = this.LiveFreeRangePage.CurrentOrder;

            //set required url's
            string payPalSubmitUrl = string.Empty;

            if (!(PayPalManager.IsPaypalSandboxOn()))
                payPalSubmitUrl = "https://www.livefreerange.com";
            else
                payPalSubmitUrl = "http://localhost/Web/CheckOut/CheckOut.aspx";

            string payPalCancelUrl = payPalSubmitUrl;

            //pass paypal information to setexpresscheckout and return a token.
            string payPalToken = payPal.SetExpressCheckout(payPalInformation, payPalSubmitUrl, payPalCancelUrl);

            //redirect to paypal with token
            if (payPalToken.ToLower().IndexOf("error") == -1)
                Response.Redirect(PayPalManager.GetPaypalFormSubmissionUrl()
                    + "?cmd=_express-checkout&token="
                    + payPalToken);
            else
            {
                //find error placeholder, show and add error message
                Panel pnlOrderDeclined = (Panel)Page.FindControl("pnlOrderDeclined");
                pnlOrderDeclined.Visible = true;

                Label lblTransactionFailureMessage = (Label)Page.FindControl("lblTransactionFailureMessage");
                lblTransactionFailureMessage.Text = payPalToken;
            }
        }
    }
Пример #2
0
    //Get PayPal Token and redirect to pay pal
    protected void ibGetPaypalToken_Click(object sender, ImageClickEventArgs e)
    {
        //set the Order object
        if (this.IsValid)
        {
            this.CurrentOrder = new Orders();
            this.litTax.Text = this.litTax.Text.Replace("£", "");
            this.CurrentOrder.Tax = Math.Round(Convert.ToDecimal(litTax.Text),2);

            this.litSubTotal.Text = this.litSubTotal.Text.Replace("£", "");
            this.CurrentOrder.SubTotal = Math.Round(Convert.ToDecimal(this.litSubTotal.Text),2);

            this.CurrentOrder.ShippingTotal = Math.Round(Convert.ToDecimal(ddlShippingOption.SelectedItem.Value));

            //add order object to paypal information object
            PayPalManager payPal = new PayPalManager();
            PayPalInformation payPalInformation = new PayPalInformation();
            payPalInformation.Order = this.CurrentOrder;

            //set required url's
            string payPalSubmitUrl = string.Empty;

            if (!(PayPalManager.IsPaypalSandboxOn()))
                payPalSubmitUrl = "https://www.livefreerange.com";
            else
                payPalSubmitUrl = "http://localhost/Web/CheckOut/CheckOut.aspx";

            string payPalCancelUrl = payPalSubmitUrl;

            //pass paypal information to setexpresscheckout and return a token.
            string payPalToken = payPal.SetExpressCheckout(payPalInformation, payPalSubmitUrl, payPalCancelUrl);

            //redirect to paypal with token
            if (payPalToken.ToLower().IndexOf("error") == -1)
            {

                Response.Redirect(PayPalManager.GetPaypalFormSubmissionUrl() + "?cmd=_express-checkout&token=" + payPalToken);
            }
            //else
            //{
            //    //find error placeholder, show and add error message
            //    this.pnlOrderDeclined.Visible = true;
            //    this.lblTransactionFailureMessage.Text = payPalToken;
            //}

        }
    }