/// <summary>
        /// Gets the express checkout details.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public PayPalPayer GetExpressCheckoutDetails(string token)
        {
            PayPalPayer payPalPayer = null;

            if (_paymentProviderCollection.Count > 0)
            {
                IPayPalPaymentProvider _provider = _paymentProviderCollection.Find(provider => provider.GetType().Name.Contains("PayPalProPaymentProvider")) as IPayPalPaymentProvider;
                payPalPayer = _provider.GetExpressCheckoutDetails(token);
            }
            return(payPalPayer);
        }
Beispiel #2
0
        public PayPalAgreementRequest(string planId)
        {
            Plan = new PayPalAgreementPlan
            {
                Id = planId
            };

            Payer = new PayPalPayer
            {
                PaymentMethod = "paypal"
            };

            StartDate = DateTime.UtcNow.AddMinutes(1).ToString("yyyy-MM-ddTHH:mm:ssZ");
        }
        /// <summary>
        /// Gets the express checkout details.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public PayPalPayer GetExpressCheckoutDetails(string token)
        {
            PayPalPayer payPalPayer = _payPalService.GetExpressCheckoutDetails(token);

            return(payPalPayer);
        }
        /// <summary>
        /// Gets the express checkout details.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        internal PayPalPayer GetExpressCheckoutDetails(string token)
        {
            PayPalPayer payPalPayer = new PayPalPayer();

              GetExpressCheckoutDetailsReq expressCheckoutRequest = new GetExpressCheckoutDetailsReq();
              GetExpressCheckoutDetailsRequestType expressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType();
              expressCheckoutDetailsRequest.Token = token;
              expressCheckoutDetailsRequest.Version = PayPalServiceUtility.PayPalVersionNumber;
              expressCheckoutRequest.GetExpressCheckoutDetailsRequest = expressCheckoutDetailsRequest;
              GetExpressCheckoutDetailsResponseType expressCheckoutDetailsResponse =
            payPalAPIAASoapBinding.GetExpressCheckoutDetails(expressCheckoutRequest);

              string errorList = ValidateResponse(expressCheckoutDetailsResponse);
              //if (expressCheckoutDetailsResponse.Ack != AckCodeType.Success && expressCheckoutDetailsResponse.Ack != AckCodeType.SuccessWithWarning) {
              if(IsValidResponse(expressCheckoutDetailsResponse.Ack)) {
            if (!string.IsNullOrEmpty(errorList)) {
              throw new PayPalServiceException(errorList);
            }
              }

              if (EnforceSellerProtectionPolicy) {
            if (expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.AddressStatus !=
            AddressStatusCodeType.Confirmed) {
              throw new PayPalServiceException(PayPalStrings.AddressStatusException);
            }
              }

              payPalPayer.PayPalPayerId =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID;
              payPalPayer.PayPalToken = expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.Token;
              payPalPayer.ShippingAddress.AddressType = AddressType.ShippingAddress;
              payPalPayer.ShippingAddress.Email = expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Payer;
              payPalPayer.ShippingAddress.FirstName =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.FirstName;
              payPalPayer.ShippingAddress.LastName =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerName.LastName;
              payPalPayer.ShippingAddress.Address1 =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street1;
              payPalPayer.ShippingAddress.Address2 =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Street2;
              payPalPayer.ShippingAddress.City =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CityName;
              payPalPayer.ShippingAddress.StateOrRegion =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.StateOrProvince;
              payPalPayer.ShippingAddress.PostalCode =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.PostalCode;
              if (expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.CountrySpecified) {
            payPalPayer.ShippingAddress.Country =
              expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.Address.Country.ToString();
              }
              if (expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.ContactPhone != null) {
            payPalPayer.ShippingAddress.Phone = expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.ContactPhone;
              }
              else {
            if (expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone != null) {
              payPalPayer.ShippingAddress.Phone =
            expressCheckoutDetailsResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.ContactPhone;
            }
              }

              return payPalPayer;
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event to initialize the page.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            if (Master.SiteSettings.LoginRequirement == LoginRequirement.Checkout)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect("login.aspx?ReturnUrl=/checkout.aspx", true);
                }
            }

            PaymentService paymentService = new PaymentService();

            if (paymentService.PaymentServiceSettings.DefaultProvider == "PayPalStandardPaymentProvider")
            {
                Response.Redirect("~/paypalcheckout.aspx", true);
            }

            //Keep these here - the Accordion ViewState is funky and requires things to be set early
            Label lblBillingInformation  = acCheckout.Panes[0].FindControl("lblBillingInformation") as Label;
            Label lblShippingInformation = acCheckout.Panes[1].FindControl("lblShippingInformation") as Label;
            Label lblShippingMethod      = acCheckout.Panes[2].FindControl("lblShippingMethod") as Label;
            Label lblCouponInformation   = acCheckout.Panes[3].FindControl("lblCouponInformation") as Label;
            Label lblPaymentInformation  = acCheckout.Panes[4].FindControl("lblPaymentInformation") as Label;
            Label lblOrderReview         = acCheckout.Panes[5].FindControl("lblOrderReview") as Label;

            //See if there are any coupons in the system
            //If not, then don't display the coupon stuff
            couponCollection = new CouponController().FetchAll();
            if (couponCollection.Count == 0)
            {
                hasCoupons        = false;
                acpCoupon.Visible = false;
                pnlCouponInformationDisplayTitle.Visible = false;
                pnlCouponInformationDisplay.Visible      = false;
            }

            shippingService = new ShippingService();
            if (!shippingService.ShippingServiceSettings.UseShipping)
            {
                acCheckout.Panes[1].Visible            = false;
                acCheckout.Panes[2].Visible            = false;
                pnlShippingAddressDisplayTitle.Visible = false;
                pnlShippingAddressDisplay.Visible      = false;
                pnlShippingMethodDisplayTitle.Visible  = false;
                pnlShippingMethodDisplay.Visible       = false;
            }

            //Keep these here - the Accordion ViewState is funky and requires things to be set early
            order = new OrderController().FetchOrder(WebUtility.GetUserName());

            #region PayPal Express Checkout Logic

            if (!string.IsNullOrEmpty(order.PaymentMethod))
            {
                if (order.PaymentMethod == "PayPal")
                {
                    string token = Utility.GetParameter("token");
                    if (!string.IsNullOrEmpty(token))
                    {
                        pnlCreditCardInformation.Visible = false;
                        pnlCreditCardInfo.Visible        = false;
                        lblCreditCardType.Text           = order.PaymentMethod;
                        ddlCreditCardType.SelectedValue  = "4";
                        ddlCreditCardType.Enabled        = false;
                        PayPalPayer payPalPayer = OrderController.GetExpressCheckout(token);
                        if (order.BillingAddress == null)//Then they are coming in from the cart.aspx ExpressCheckout button
                        //copy the PayPalPayer ShippingAddress and then flag it as a BillingAddress
                        {
                            Address billingAddress = new Address(payPalPayer.ShippingAddress);
                            billingAddress.AddressType = AddressType.BillingAddress;
                            Address duplicateBillingAddress = WebProfile.Current.AddressCollection.Find(
                                addressToFind =>
                                addressToFind.ToString() == billingAddress.ToString() &&
                                addressToFind.AddressType == AddressType.BillingAddress);
                            if (duplicateBillingAddress == null)
                            {
                                WebProfile.Current.AddressCollection.Add(billingAddress);
                                WebProfile.Current.Save();
                            }
                            order.BillToAddress = payPalPayer.ShippingAddress.ToXml();
                        }
                        if (!payPalPayer.ShippingAddress.Equals(order.ShippingAddress))
                        {
                            Address shippingAddress = new Address(payPalPayer.ShippingAddress);
                            shippingAddress.AddressType = AddressType.ShippingAddress;
                            Address duplicateShippingAddress = WebProfile.Current.AddressCollection.Find(
                                addressToFind =>
                                addressToFind.ToString() == shippingAddress.ToString() &&
                                addressToFind.AddressType == AddressType.ShippingAddress);
                            if (duplicateShippingAddress == null)
                            {
                                WebProfile.Current.AddressCollection.Add(shippingAddress);
                                WebProfile.Current.Save();
                            }
                            order.ShipToAddress = payPalPayer.ShippingAddress.ToXml();
                        }
                        if (order.ExtendedProperties.ContainsKey(PAYPAL_PAYER_ID))
                        {
                            order.ExtendedProperties.Remove(PAYPAL_PAYER_ID);
                        }
                        if (order.ExtendedProperties.ContainsKey(PAYPAL_TOKEN))
                        {
                            order.ExtendedProperties.Remove(PAYPAL_TOKEN);
                        }
                        order.ExtendedProperties.Add(PAYPAL_PAYER_ID, payPalPayer.PayPalPayerId);
                        order.ExtendedProperties.Add(PAYPAL_TOKEN, payPalPayer.PayPalToken);
                        order.AdditionalProperties = order.ExtendedProperties.ToXml();
                        order.Save(WebUtility.GetUserName());
                        OrderController.CalculateTax(WebUtility.GetUserName());
                        order = new OrderController().FetchOrder(WebUtility.GetUserName());
                    }
                }
            }

            #endregion

            if (!Page.IsPostBack)
            {
                SetBillingAddressDisplay();

                SetShippingAddressDisplay();

                SetShippingMethodDisplay();

                SetCouponDisplay();

                SetPaymentMethodDisplay(-1, order.CreditCardNumber, DateTime.MinValue);
            }
            base.OnInit(e);
        }