Exemplo n.º 1
0
        private HttpWebRequest BuildSetRequest(PaypalExpressPart paypalExpressPart, OrderPart order)
        {
            // Create the web request
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Ensure order totals are up to date
            order.UpdateTotals();

            var pr = new PaypalRequest(paypalExpressPart, "SetExpressCheckout");

            pr.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale");
            pr.Add("PAYMENTREQUEST_0_AMT", order.SubTotal.ToString("F2"));     // before shipping and tax
            pr.Add("PAYMENTREQUEST_0_ITEMAMT", order.SubTotal.ToString("F2")); // including shipping and tax
            pr.Add("PAYMENTREQUEST_0_CURRENCYCODE", paypalExpressPart.Currency);
            pr.Add("returnUrl", paypalExpressPart.SuccessUrl);
            pr.Add("cancelUrl", paypalExpressPart.CancelUrl);

            // order details
            AddAllItems(pr, order);

            // Set Address
            SetShippingAddress(pr, order);

            // format the data
            pr.SetData(request);

            return(request);
        }
Exemplo n.º 2
0
        private HttpWebRequest BuildExpressCheckoutPaymentRequest(PaypalExpressPart paypalExpressPart, OrderPart order, string token, string payerId)
        {
            // Create the web request
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Create a paypal request
            PaypalRequest pr = new PaypalRequest(paypalExpressPart, "DoExpressCheckoutPayment", token);

            // Add data
            pr.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale");
            pr.Add("PAYERID", payerId);
            pr.Add("PAYMENTREQUEST_0_AMT", order.SubTotal.ToString("F2"));     // before shipping and tax
            pr.Add("PAYMENTREQUEST_0_ITEMAMT", order.SubTotal.ToString("F2")); // including shipping and tax
            pr.Add("PAYMENTREQUEST_0_CURRENCYCODE", paypalExpressPart.Currency);

            // order details
            AddAllItems(pr, order);

            // format the request with data from the paypal request
            pr.SetData(request);

            return(request);
        }
Exemplo n.º 3
0
        private void AddItem(PaypalRequest pr, int lineNumber, OrderDetail detail)
        {
            //var productPart = _services.ContentManager.Get<ProductPart>(detail.ProductPartRecord_Id);

            pr.Add("L_PAYMENTREQUEST_0_NAME" + lineNumber, detail.Sku);
            pr.Add("L_PAYMENTREQUEST_0_DESC" + lineNumber, detail.Description);
            pr.Add("L_PAYMENTREQUEST_0_QTY" + lineNumber, detail.Quantity.ToString("f2"));
            pr.Add("L_PAYMENTREQUEST_0_AMT" + lineNumber, detail.UnitPrice.ToString("f2"));
        }
Exemplo n.º 4
0
        private void AddAllItems(PaypalRequest pr, OrderPart order)
        {
            int lineNumber = 0;

            foreach (var item in order.Details)
            {
                AddItem(pr, ++lineNumber, item);
            }
        }
Exemplo n.º 5
0
        private HttpWebRequest BuildGetDetailsRequest(PaypalExpressPart paypalExpressPart, string token)
        {
            // Create the web request
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Create a paypal request
            PaypalRequest pr = new PaypalRequest(paypalExpressPart, "GetExpressCheckoutDetails", token);

            // format the request with data from the paypal request
            pr.SetData(request);

            return(request);
        }
Exemplo n.º 6
0
        private void SetShippingAddress(PaypalRequest pr, OrderPart order)
        {
            bool         addrOverride = true;
            CustomerPart customer     = _customerService.GetCustomer(order.CustomerId);

            // determine which address to use
            var address = _customerService.GetShippingAddress(order.CustomerId, order.Id);

            if (address == null || String.IsNullOrWhiteSpace(address.Address))
            {
                address = _customerService.GetInvoiceAddress(order.CustomerId);
            }
            if (address == null || String.IsNullOrWhiteSpace(address.Address))
            {
                addrOverride = false;
            }

            pr.Add("ADDROVERRIDE", addrOverride ? "1" : "0");
            pr.Add("NOSHIPPING", "0");
            if (addrOverride)
            {
                if (string.IsNullOrWhiteSpace(address.Name))
                {
                    pr.Add("PAYMENTREQUEST_0_SHIPTONAME", customer.FirstName + " " + customer.LastName);
                }
                else
                {
                    pr.Add("PAYMENTREQUEST_0_SHIPTONAME", address.Name);
                }
                pr.Add("PAYMENTREQUEST_0_SHIPTOSTREET", address.Address);
                pr.Add("PAYMENTREQUEST_0_SHIPTOCITY", address.City);
                pr.Add("PAYMENTREQUEST_0_SHIPTOSTATE", address.State);
                pr.Add("PAYMENTREQUEST_0_SHIPTOZIP", address.Postcode);
                pr.Add("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", address.CountryCode);

                // Set email
                UserPart user = customer.As <UserPart>();
                pr.Add("PAYMENTREQUEST_0_EMAIL", user.Email);
            }
        }
        private HttpWebRequest BuildGetDetailsRequest(PaypalExpressPart paypalExpressPart, string token)
        {
            // Create the web request  
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST  
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Create a paypal request
            PaypalRequest pr = new PaypalRequest(paypalExpressPart, "GetExpressCheckoutDetails", token);

            // format the request with data from the paypal request
            pr.SetData(request);

            return request;
        }
        private void AddItem(PaypalRequest pr, int lineNumber, OrderDetailRecord detail)
        {
            //var productPart = _services.ContentManager.Get<ProductPart>(detail.ProductPartRecord_Id);

            pr.Add("L_PAYMENTREQUEST_0_NAME" + lineNumber, detail.Sku);
            pr.Add("L_PAYMENTREQUEST_0_DESC" + lineNumber, detail.Description);
            pr.Add("L_PAYMENTREQUEST_0_QTY" + lineNumber, detail.Quantity.ToString("f2"));
            pr.Add("L_PAYMENTREQUEST_0_AMT" + lineNumber, detail.UnitPrice.ToString("f2"));
        }
 private void AddAllItems(PaypalRequest pr, OrderRecord order)
 {
     int lineNumber = 0;
     foreach (var item in order.Details)
         AddItem(pr, ++lineNumber, item);
 }
        private void SetShippingAddress(PaypalRequest pr, OrderRecord order)
        {
            bool addrOverride = true;
            CustomerPart customer = _customerService.GetCustomer(order.CustomerId);

            // determine which address to use
            var address = _customerService.GetAddress(order.CustomerId, "ShippingAddress");
            if (address == null)
                address = _customerService.GetAddress(order.CustomerId, "InvoiceAddress");
            if (address == null)
                addrOverride = false;

            pr.Add("ADDROVERRIDE", addrOverride ? "1" : "0");
            pr.Add("NOSHIPPING", "0");
            if (addrOverride)
            {
                if (string.IsNullOrWhiteSpace(address.Name))
                    pr.Add("PAYMENTREQUEST_0_SHIPTONAME", customer.FirstName + " " + customer.LastName);
                else
                    pr.Add("PAYMENTREQUEST_0_SHIPTONAME", address.Name);
                pr.Add("PAYMENTREQUEST_0_SHIPTOSTREET", address.Address);
                pr.Add("PAYMENTREQUEST_0_SHIPTOCITY", address.City);
                pr.Add("PAYMENTREQUEST_0_SHIPTOSTATE", address.State);
                pr.Add("PAYMENTREQUEST_0_SHIPTOZIP", address.Postcode);
                pr.Add("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", address.CountryCode);

                // Set email
                UserPart user = customer.As<UserPart>();
                pr.Add("PAYMENTREQUEST_0_EMAIL", user.Email);
            }
        }
        private HttpWebRequest BuildSetRequest(PaypalExpressPart paypalExpressPart, OrderRecord order)
        {
            // Create the web request  
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST  
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Ensure order totals are up to date
            order.UpdateTotals();

            var pr = new PaypalRequest(paypalExpressPart, "SetExpressCheckout");
            pr.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale");
            pr.Add("PAYMENTREQUEST_0_AMT", order.SubTotal.ToString("F2")); // before shipping and tax
            pr.Add("PAYMENTREQUEST_0_ITEMAMT", order.SubTotal.ToString("F2")); // including shipping and tax
            pr.Add("PAYMENTREQUEST_0_CURRENCYCODE", paypalExpressPart.Currency);
            pr.Add("returnUrl", paypalExpressPart.SuccessUrl);
            pr.Add("cancelUrl", paypalExpressPart.CancelUrl);

            // order details
            AddAllItems(pr, order);

            // Set Address
            SetShippingAddress(pr, order);

            // format the data
            pr.SetData(request);

            return request;
        }
        private HttpWebRequest BuildExpressCheckoutPaymentRequest(PaypalExpressPart paypalExpressPart, OrderRecord order, string token, string payerId)
        {
            // Create the web request  
            HttpWebRequest request = WebRequest.Create(paypalExpressPart.ApiUrl) as HttpWebRequest;

            // Set type to POST  
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";

            // Create a paypal request
            PaypalRequest pr = new PaypalRequest(paypalExpressPart, "DoExpressCheckoutPayment", token);

            // Add data
            pr.Add("PAYMENTREQUEST_0_PAYMENTACTION", "Sale");
            pr.Add("PAYERID", payerId);
            pr.Add("PAYMENTREQUEST_0_AMT", order.SubTotal.ToString("F2")); // before shipping and tax
            pr.Add("PAYMENTREQUEST_0_ITEMAMT", order.SubTotal.ToString("F2")); // including shipping and tax
            pr.Add("PAYMENTREQUEST_0_CURRENCYCODE", paypalExpressPart.Currency);

            // order details
            AddAllItems(pr, order);

            // format the request with data from the paypal request
            pr.SetData(request);

            return request;
        }