コード例 #1
0
        private void createAPMOrder()
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["service_key"]);

            var billingAddress = new Address()
            {
                address1 = form["address1"],
                address2 = form["address2"],
                address3 = form["address3"],
                postalCode = form["postcode"],
                city = form["city"],
                state = "",
                countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["countryCode"])
            };

            var request = new OrderRequest()
            {
                token = form["token"],
                name = form["name"],
                orderDescription = form["description"],
                amount = (int)(Convert.ToDecimal(form["amount"]) * 100),
                currencyCode = (CurrencyCode)Enum.Parse(typeof(CurrencyCode), form["currency"]),
                billingAddress = billingAddress,
                customerIdentifiers = new List<Entry>()
                    {
                        new Entry()
                        {
                            key = "my-customer-ref",
                            value = "customer-ref"
                        }
                    },
                customerOrderCode = "A123",
                successUrl = form["successUrl"],
                failureUrl = form["failureUrl"],
                pendingUrl = form["pendingUrl"],
                cancelUrl = form["cancelUrl"]
            };

            try
            {
                var response = client.GetOrderService().Create(request);

                HandleSuccessResponse(response);

                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with token " + request.token, exc);
            }
        }
コード例 #2
0
        private void createOrder()
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["service_key"]);
            var orderType = (OrderType)Enum.Parse(typeof(OrderType), form["orderType"]);

            var cardRequest = new CardRequest();
            cardRequest.cardNumber = form["number"];
            cardRequest.cvc = form["cvv"];
            cardRequest.name = form["name"];
            cardRequest.expiryMonth = Convert.ToInt32(form["exp-month"]);
            cardRequest.expiryYear = Convert.ToInt32(form["exp-year"]);
            cardRequest.type = form["cardType"];

            var billingAddress = new Address()
            {
                address1 = form["address1"],
                address2 = form["address2"],
                address3 = form["address3"],
                postalCode = form["postcode"],
                city = form["city"],
                state = "",
                countryCode = Enum.Parse(typeof(CountryCode), form["countryCode"]).ToString()
            };

            var is3DS = form["3ds"] == "on" ? true : false;
            ThreeDSecureInfo threeDSInfo = null;
            if (is3DS)
            {
                var httpRequest = HttpContext.Current.Request;
                threeDSInfo = new ThreeDSecureInfo()
                {
                    shopperIpAddress = httpRequest.UserHostAddress,
                    shopperSessionId = HttpContext.Current.Session.SessionID,
                    shopperUserAgent = httpRequest.UserAgent,
                    shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes)
                };
            }

            var request = new OrderRequest()
            {
                token = form["token"],
                orderDescription = form["description"],
                amount = (int)(Convert.ToDecimal(form["amount"]) * 100),
                currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString(),
                name =  is3DS ? "3D" : form["name"],
                billingAddress = billingAddress,
                threeDSecureInfo = is3DS ? threeDSInfo : new ThreeDSecureInfo(),
                is3DSOrder = is3DS,
                authorizeOnly = form["authoriseOnly"] == "on",
                orderType = orderType.ToString(),
                customerIdentifiers = new Dictionary<string, string> { { "my-customer-ref", "customer-ref" } },
                customerOrderCode = "A123"
            };

            try
            {
                var response = client.GetOrderService().Create(request);

                HandleSuccessResponse(response);

                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with token " + request.token, exc);
            }
        }
コード例 #3
0
        private void createAPMOrder()
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            int? _amount = null;
            var _currencyCode = "";
            Dictionary<string, string> custIdentifiers = new Dictionary<string, string>();

            try
            {
                custIdentifiers = JsonConvert.DeserializeObject<Dictionary<string,string>>(form["customer-identifiers"]);

            }
            catch (Exception exc) { }

            try
            {
                _amount = (int)(Convert.ToDecimal(form["amount"]) * 100);
            }
            catch (Exception excAmount) { }

            try
            {
                _currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString();
            }
            catch (Exception excCurrency) { }

            var billingAddress = new Address()
            {
                address1 = form["address1"],
                address2 = form["address2"],
                address3 = form["address3"],
                postalCode = form["postcode"],
                city = form["city"],
                state = "",
                countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["countryCode"])
            };

            var deliveryAddress = new DeliveryAddress()
            {
                firstName = form["delivery-firstName"],
                lastName = form["delivery-lastName"],
                address1 = form["delivery-address1"],
                address2 = form["delivery-address2"],
                address3 = form["delivery-address3"],
                postalCode = form["delivery-postcode"],
                city = form["delivery-city"],
                state = "",
                countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["delivery-countryCode"])
            };

            var request = new OrderRequest()
            {
                token = form["token"],
                name = form["name"],
                shopperEmailAddress = form["shopper-email"],
                statementNarrative = form["statement-narrative"],
                orderDescription = form["description"],
                amount = _amount,
                currencyCode = _currencyCode,
                billingAddress = billingAddress,
                deliveryAddress = deliveryAddress,
                customerIdentifiers = custIdentifiers,
                customerOrderCode = "A123",
                successUrl = form["success-url"],
                failureUrl = form["failure-url"],
                pendingUrl = form["pending-url"],
                cancelUrl = form["cancel-url"]
            };

            if (!string.IsNullOrEmpty(form["settlement-currency"]))
            {
                request.settlementCurrency = form["settlement-currency"];
            }

            try
            {
                var response = client.GetOrderService().Create(request);

                HandleSuccessResponse(response);

                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with token " + request.token, exc);
            }
        }
コード例 #4
0
        private void createOrder()
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            var orderType = (OrderType)Enum.Parse(typeof(OrderType), form["orderType"]);

            var cardRequest = new CardRequest();
            cardRequest.cardNumber = form["number"];
            cardRequest.cvc = form["cvv"];
            cardRequest.name = form["name"];
            cardRequest.expiryMonth = Convert.ToInt32(form["exp-month"]);
            cardRequest.expiryYear = Convert.ToInt32(form["exp-year"]);
            cardRequest.type = form["cardType"];
            int? _amount = null;
            var _currencyCode = "";
            Dictionary<string, string> custIdentifiers = new Dictionary<string, string>();

            try
            {
                custIdentifiers = JsonConvert.DeserializeObject<Dictionary<string, string>>(form["customer-identifiers"]);
            }
            catch (Exception exc) { }

            try
            {
                _amount = (int)(Convert.ToDecimal(form["amount"]) * 100);
            }
            catch (Exception excAmount) { }

            try
            {
                _currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString();
            }
            catch (Exception excCurrency) { }

            var billingAddress = new Address()
            {
                address1 = form["address1"],
                address2 = form["address2"],
                address3 = form["address3"],
                postalCode = form["postcode"],
                city = form["city"],
                state = "",
                countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["countryCode"])
            };

            var deliveryAddress = new DeliveryAddress()
            {
                firstName = form["delivery-firstName"],
                lastName = form["delivery-lastName"],
                address1 = form["delivery-address1"],
                address2 = form["delivery-address2"],
                address3 = form["delivery-address3"],
                postalCode = form["delivery-postcode"],
                city = form["delivery-city"],
                state = "",
                countryCode = (CountryCode)Enum.Parse(typeof(CountryCode), form["delivery-countryCode"])
            };

            var is3DS = form["3ds"] == "on" ? true : false;
            ThreeDSecureInfo threeDSInfo = null;
            if (is3DS)
            {
                var httpRequest = HttpContext.Current.Request;
                threeDSInfo = new ThreeDSecureInfo()
                {
                    shopperIpAddress = httpRequest.UserHostAddress,
                    shopperSessionId = HttpContext.Current.Session.SessionID,
                    shopperUserAgent = httpRequest.UserAgent,
                    shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes)
                };
            }

            var request = new OrderRequest()
            {
                token = form["token"],
                orderDescription = form["description"],
                amount = _amount,
                currencyCode = _currencyCode,
                name =  is3DS ? "3D" : form["name"],
                shopperEmailAddress = form["shopper-email"],
                statementNarrative = form["statement-narrative"],
                billingAddress = billingAddress,
                deliveryAddress = deliveryAddress,
                threeDSecureInfo = is3DS ? threeDSInfo : new ThreeDSecureInfo(),
                is3DSOrder = is3DS,
                authorizeOnly = form["authoriseOnly"] == "on",
                orderType = orderType,
                customerIdentifiers = custIdentifiers,
                customerOrderCode = "A123"
            };

            if (!string.IsNullOrEmpty(form["settlement-currency"]))
            {
                request.settlementCurrency = form["settlement-currency"];
            }

            try
            {
                var response = client.GetOrderService().Create(request);

                HandleSuccessResponse(response);

                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with token " + request.token, exc);
            }
        }
コード例 #5
0
        /// <summary>
        /// Create an order request
        /// </summary>
        private OrderRequest createOrderRequest()
        {
            var orderRequest = new OrderRequest();
            orderRequest.amount = 1999;
            orderRequest.currencyCode = CurrencyCode.GBP;
            orderRequest.name = "test name";
            orderRequest.orderDescription = "test description";

            var address = new Address();
            address.address1 = "line 1";
            address.address2 = "line 2";
            address.city = "city";
            address.countryCode = CountryCode.GB;
            address.postalCode = "AB1 2CD";
            orderRequest.billingAddress = address;

            var customerIdentifiers = new List<Entry>();
            var entry = new Entry("test key 1", "test value 1");
            customerIdentifiers.Add(entry);

            orderRequest.customerIdentifiers = customerIdentifiers;
            return orderRequest;
        }
コード例 #6
0
        /// <summary>
        /// Create a 3DS order request
        /// </summary>
        private OrderRequest create3DSOrderRequest()
        {
            var orderRequest = new OrderRequest();
            orderRequest.amount = 1999;
            orderRequest.currencyCode = CurrencyCode.GBP;
            orderRequest.name = "3D";
            orderRequest.orderDescription = "test description";

            var threeDSInfo = new ThreeDSecureInfo();
            threeDSInfo.shopperIpAddress = "127.0.0.1";
            threeDSInfo.shopperSessionId = "sessionId";
            threeDSInfo.shopperUserAgent = "Mozilla/v1";
            threeDSInfo.shopperAcceptHeader = "application/json";
            orderRequest.threeDSecureInfo = threeDSInfo;
            orderRequest.is3DSOrder = true;

            var address = new Address();
            address.address1 = "line 1";
            address.address2 = "line 2";
            address.city = "city";
            address.countryCode = CountryCode.GB;
            address.postalCode = "AB1 2CD";
            orderRequest.billingAddress = address;

            var customerIdentifiers = new List<Entry>();
            var entry = new Entry("test key 1", "test value 1");
            customerIdentifiers.Add(entry);

            orderRequest.customerIdentifiers = customerIdentifiers;
            return orderRequest;
        }
コード例 #7
0
        protected void OnCreateOrder(object sender, CommandEventArgs e)
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            var orderType = (OrderType)Enum.Parse(typeof(OrderType), form["orderType"]);
            int? _amount = null;
            var _currencyCode = "";

            try
            {
                _amount = (int)(Convert.ToDecimal(form["amount"]) * 100);
            }
            catch (Exception excAmount) { }

            try
            {
                _currencyCode = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString();
            }
            catch (Exception excCurrency) { }

            var billingAddress = new Address()
            {
                address1 = form["address1"],
                address2 = form["address2"],
                address3 = form["address3"],
                postalCode = form["postcode"],
                city = form["city"],
                state = "",
                countryCode = Enum.Parse(typeof(CountryCode), form["countryCode"]).ToString()
            };

            var deliveryAddress = new DeliveryAddress()
            {
                firstName = form["delivery-firstName"],
                lastName = form["delivery-lastName"],
                address1 = form["delivery-address1"],
                address2 = form["delivery-address2"],
                address3 = form["delivery-address3"],
                postalCode = form["delivery-postcode"],
                city = form["delivery-city"],
                state = "",
                countryCode = Enum.Parse(typeof(CountryCode), form["delivery-countryCode"]).ToString()
            };

            var is3DS = form["3ds"] == "on" ? true : false;
            ThreeDSecureInfo threeDSInfo = null;
            if (is3DS)
            {
                var httpRequest = HttpContext.Current.Request;
                threeDSInfo = new ThreeDSecureInfo()
                {
                    shopperIpAddress = httpRequest.UserHostAddress,
                    shopperSessionId = HttpContext.Current.Session.SessionID,
                    shopperUserAgent = httpRequest.UserAgent,
                    shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes)
                };
            }

            var request = new OrderRequest
                {
                    token = form["token"],
                    orderDescription = form["description"],
                    statementNarrative = form["statement-narrative"],
                    billingAddress = billingAddress,
                    deliveryAddress = deliveryAddress,
                    amount = _amount,
                    currencyCode = _currencyCode,
                    name = is3DS ? "3D" : form["name"],
                    threeDSecureInfo = is3DS ? threeDSInfo : new ThreeDSecureInfo(),
                    is3DSOrder = is3DS,
                    authorizeOnly = form["authoriseOnly"] == "on",
                    orderType = orderType.ToString()
            };

            if (!string.IsNullOrEmpty(form["settlement-currency"]))
            {
                request.settlementCurrency = form["settlement-currency"];
            }

            try
            {
                var response = client.GetOrderService().Create(request);
                HandleSuccessResponse(response);
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with token " + request.token, exc);
            }
        }
コード例 #8
0
        /// <summary>
        /// Create a APM order request
        /// </summary>
        private OrderRequest createAPMOrderRequest()
        {
            var orderRequest = new OrderRequest();
            orderRequest.amount = 1999;
            orderRequest.successUrl = "http://www.testurl.com/success";
            orderRequest.cancelUrl = "http://www.testurl.com/cancel";
            orderRequest.failureUrl = "http://www.testurl.com/failure";
            orderRequest.pendingUrl = "http://www.testurl.com/pending";

            orderRequest.currencyCode = CurrencyCode.GBP;
            orderRequest.name = "Test";
            orderRequest.orderDescription = "test description";
            orderRequest.is3DSOrder = false;

            var address = new Address();
            address.address1 = "line 1";
            address.address2 = "line 2";
            address.city = "city";
            address.countryCode = CountryCode.GB;
            address.postalCode = "AB1 2CD";
            orderRequest.billingAddress = address;

            var customerIdentifiers = new Dictionary<string, string>();
            customerIdentifiers.Add("test key 1", "test value 1");

            orderRequest.customerIdentifiers = customerIdentifiers;
            return orderRequest;
        }
コード例 #9
0
        /// <summary>
        /// Create an order request
        /// </summary>
        private OrderRequest createOrderRequest()
        {
            var orderRequest = new OrderRequest();
            orderRequest.amount = 1999;
            orderRequest.currencyCode = CurrencyCode.GBP.ToString();
            orderRequest.name = "test name";
            orderRequest.orderDescription = "test description";

            var address = new Address();
            address.address1 = "line 1";
            address.address2 = "line 2";
            address.city = "city";
            address.countryCode = CountryCode.GB.ToString();
            address.postalCode = "AB1 2CD";
            orderRequest.billingAddress = address;

            var customerIdentifiers = new Dictionary<string, string>();
            customerIdentifiers["test key 1"] = "test value 1";

            orderRequest.customerIdentifiers = customerIdentifiers;
            return orderRequest;
        }