protected void onAuthorizeOrder(object sender, CommandEventArgs e)
        {
            var client = new WorldpayRestClient(Configuration.ServiceKey);

            string orderCode = (string)Session["orderCode"];
            var responseCode = HttpContext.Current.Request.Form["PaRes"];
            var httpRequest = HttpContext.Current.Request;
            ThreeDSecureInfo threeDSInfo = new ThreeDSecureInfo()
            {
                shopperIpAddress = httpRequest.UserHostAddress,
                shopperSessionId = HttpContext.Current.Session.SessionID,
                shopperUserAgent = httpRequest.UserAgent,
                shopperAcceptHeader = String.Join(";", httpRequest.AcceptTypes)
            };

            try
            {
                var response = client.GetOrderService().Authorize(orderCode, responseCode, threeDSInfo);
                OrderResponse.Text = "Order code: <span id='order-code'>" + response.orderCode + "</span><br />Payment Status: " +
                                            response.paymentStatus + "<br />Environment: " + response.environment;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request with order code " + orderCode, exc);
            }
        }
        protected void OnCreateOrder(object sender, CommandEventArgs e)
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string) Session["service_key"]);

            var request = new OrderRequest
                {
                    token = form["token"],
                    orderDescription = form["description"],
                    amount = (int) (Convert.ToDecimal(form["amount"])*100),
                    currencyCode = (CurrencyCode) Enum.Parse(typeof (CurrencyCode), form["currency"]),
                    orderType = OrderType.RECURRING
                };

            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);
            }
        }
Пример #3
0
        protected void OnGetOrder(object sender, CommandEventArgs e)
        {
            string orderCode = Request["orderCode"];
            if (orderCode == null)
            {
                throw new WorldpayException("Order code must be specified");
            }

            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);

            try
            {
                var response = client.GetOrderService().FindOrder(orderCode);
                ServerResponse.Text = JsonUtils.SerializeObject(response);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnGetOrder(object sender, CommandEventArgs e)
        {
            string orderCode = Request["orderCode"];
            if (orderCode == null)
            {
                throw new WorldpayException("Order code must be specified");
            }

            var client = new WorldpayRestClient(Configuration.ServiceKey);

            try
            {
                var response = client.GetOrderService().FindOrder(orderCode);
                ServerResponse.Text = JsonConvert.SerializeObject(response, Formatting.Indented);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        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);
            }
        }
 public void Setup()
 {
     var restClient = new WorldpayRestClient(Configuration.ServiceKey);
     _authService = restClient.GetAuthService();
     _tokenService = restClient.GetTokenService();
 }