Beispiel #1
0
        private void DoPayPalExpressCeckout()
        {
            PayPalExpressGateway gateway
                = new PayPalExpressGateway(
                      commerceConfig.PayPalAPIUsername,
                      commerceConfig.PayPalAPIPassword,
                      commerceConfig.PayPalAPISignature,
                      commerceConfig.PayPalStandardEmailAddress);

            gateway.UseTestMode = commerceConfig.PaymentGatewayUseTestMode;

            gateway.MerchantCartId = cart.CartGuid.ToString();
            gateway.ChargeTotal    = cart.OrderTotal;

            string siteRoot = SiteUtils.GetNavigationSiteRoot();

            gateway.ReturnUrl = siteRoot + "/Services/PayPalReturnHandler.ashx";
            gateway.CancelUrl = siteRoot + Request.RawUrl;
            //Currency currency = new Currency(store.DefaultCurrencyId);
            //gateway.CurrencyCode = currency.Code;
            gateway.CurrencyCode     = siteSettings.GetCurrency().Code;
            gateway.OrderDescription = store.Name + " " + WebStoreResources.OrderHeading;

            gateway.BuyerEmail       = cart.OrderInfo.CustomerEmail;
            gateway.ShipToFirstName  = cart.OrderInfo.DeliveryFirstName;
            gateway.ShipToLastName   = cart.OrderInfo.DeliveryLastName;
            gateway.ShipToAddress    = cart.OrderInfo.DeliveryAddress1;
            gateway.ShipToAddress2   = cart.OrderInfo.DeliveryAddress2;
            gateway.ShipToCity       = cart.OrderInfo.DeliveryCity;
            gateway.ShipToState      = cart.OrderInfo.DeliveryState;
            gateway.ShipToCountry    = cart.OrderInfo.DeliveryCountry;
            gateway.ShipToPostalCode = cart.OrderInfo.DeliveryPostalCode;
            gateway.ShipToPhone      = cart.OrderInfo.CustomerTelephoneDay;

            // this tells paypal to use the shipping address we pass in
            // rather than what the customer has on file
            // when we implement shippable products we'll do shipping calculations before
            // sending the user to paypal
            //gateway.OverrideShippingAddress = true;

            //commented out the above, we want user to be able to populate shipping info from their paypal account

            bool executed = gateway.CallSetExpressCheckout();

            if (executed)
            {
                //TODO: log the raw response
                if (gateway.PayPalExpressUrl.Length > 0)
                {
                    // record the gateway.PayPalToken
                    PayPalLog payPalLog = new PayPalLog();
                    payPalLog.RawResponse  = gateway.RawResponse;
                    payPalLog.ProviderName = "WebStorePayPalHandler";
                    payPalLog.ReturnUrl    = siteRoot + Request.RawUrl;
                    payPalLog.Token        = HttpUtility.UrlDecode(gateway.PayPalToken);
                    payPalLog.RequestType  = "SetExpressCheckout";

                    cart.SerializeCartOffers();
                    payPalLog.SerializedObject = SerializationHelper.SerializeToString(cart);

                    payPalLog.CartGuid  = cart.CartGuid;
                    payPalLog.SiteGuid  = store.SiteGuid;
                    payPalLog.StoreGuid = store.Guid;
                    payPalLog.UserGuid  = cart.UserGuid;

                    payPalLog.Save();

                    Response.Redirect(gateway.PayPalExpressUrl);
                }
            }
        }
Beispiel #2
0
        private void DoPayPalExpressCeckout()
        {
            string siteRoot = SiteUtils.GetNavigationSiteRoot();

            PayPalExpressGateway gateway = new PayPalExpressGateway(
                commerceConfig.PayPalAPIUsername,
                commerceConfig.PayPalAPIPassword,
                commerceConfig.PayPalAPISignature,
                commerceConfig.PayPalStandardEmailAddress
                )
            {
                UseTestMode      = commerceConfig.PaymentGatewayUseTestMode,
                MerchantCartId   = cart.CartGuid.ToString(),
                ChargeTotal      = cart.OrderTotal,
                ReturnUrl        = siteRoot + "/Services/PayPalReturnHandler.ashx",
                CancelUrl        = siteRoot + Request.RawUrl,
                CurrencyCode     = siteSettings.GetCurrency().Code,
                OrderDescription = store.Name + " " + WebStoreResources.OrderHeading,
                BuyerEmail       = cart.OrderInfo.CustomerEmail,
                ShipToFirstName  = cart.OrderInfo.DeliveryFirstName,
                ShipToLastName   = cart.OrderInfo.DeliveryLastName,
                ShipToAddress    = cart.OrderInfo.DeliveryAddress1,
                ShipToAddress2   = cart.OrderInfo.DeliveryAddress2,
                ShipToCity       = cart.OrderInfo.DeliveryCity,
                ShipToState      = cart.OrderInfo.DeliveryState,
                ShipToCountry    = cart.OrderInfo.DeliveryCountry,
                ShipToPostalCode = cart.OrderInfo.DeliveryPostalCode,
                ShipToPhone      = cart.OrderInfo.CustomerTelephoneDay
            };

            // this tells paypal to use the shipping address we pass in
            // rather than what the customer has on file
            // when we implement shippable products we'll do shipping calculations before
            // sending the user to paypal
            //gateway.OverrideShippingAddress = true;

            //commented out the above, we want user to be able to populate shipping info from their paypal account

            bool executed = gateway.CallSetExpressCheckout();

            if (executed)
            {
                //TODO: log the raw response
                if (gateway.PayPalExpressUrl.Length > 0)
                {
                    cart.SerializeCartOffers();

                    // record the gateway.PayPalToken
                    PayPalLog payPalLog = new PayPalLog
                    {
                        RawResponse      = gateway.RawResponse,
                        ProviderName     = WebStorePayPalReturnHandler.ProviderName,
                        ReturnUrl        = siteRoot + Request.RawUrl,
                        Token            = HttpUtility.UrlDecode(gateway.PayPalToken),
                        RequestType      = "SetExpressCheckout",
                        SerializedObject = SerializationHelper.SerializeToString(cart),
                        CartGuid         = cart.CartGuid,
                        SiteGuid         = store.SiteGuid,
                        StoreGuid        = store.Guid,
                        UserGuid         = cart.UserGuid
                    };

                    payPalLog.Save();

                    Response.Redirect(gateway.PayPalExpressUrl);
                }
                else
                {
                    if (commerceConfig.PaymentGatewayUseTestMode)
                    {
                        lblMessage.Text = gateway.RawResponse;
                    }
                }
            }
            else
            {
                lblMessage.Text = WebStoreResources.TransactionNotInitiatedMessage;

                if (gateway.LastExecutionException != null)
                {
                    if (commerceConfig.PaymentGatewayUseTestMode)
                    {
                        lblMessage.Text = gateway.LastExecutionException.ToString();
                    }
                }
                else
                {
                    if (commerceConfig.PaymentGatewayUseTestMode)
                    {
                        lblMessage.Text = gateway.RawResponse;
                    }
                }
            }
        }