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);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Authorize a 3DS order
 /// </summary>
 /// <param name="orderCode">Order code for the orer to be authorized</param>
 /// <param name="responseCode">Authorization Response code from Issuer</param>
 /// <param name="threeDSInfo">3D Secure Information</param>
 /// <returns>Confirmation of the new order</returns>
 public OrderResponse Authorize(string orderCode, string responseCode, ThreeDSecureInfo threeDSInfo)
 {
     return Http.Put<OrderAuthorizationRequest, OrderResponse>(String.Format("{0}/orders/{1}", _baseUrl, orderCode),
                                                                 new OrderAuthorizationRequest()
                                                                 {
                                                                     threeDSResponseCode = responseCode,
                                                                     threeDSecureInfo = threeDSInfo
                                                                 });
 }
        public void ShouldAuthorise3DSOrder()
        {
            OrderRequest orderRequest = create3DSOrderRequest();
            orderRequest.token = CreateToken();

            OrderResponse response = _orderService.Create(orderRequest);

            var threeDSInfo= new ThreeDSecureInfo()
            {
                shopperIpAddress = "127.0.0.1",
                shopperSessionId = "sessionId",
                shopperUserAgent = "Mozilla/v1",
                shopperAcceptHeader = "application/json"
            };

            var authorizationResponse = _orderService.Authorize(response.orderCode, "IDENTIFIED", threeDSInfo);

               Assert.AreEqual(response.orderCode, authorizationResponse.orderCode);
               Assert.AreEqual(1999, authorizationResponse.amount);
               Assert.IsTrue(response.is3DSOrder);
               Assert.AreEqual(OrderStatus.SUCCESS, authorizationResponse.paymentStatus);
        }
        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);
            }
        }
Exemplo n.º 5
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);
            }
        }
        /// <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;
        }
        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);
            }
        }