Esempio n. 1
0
        protected void OnCaptureOrder(object sender, CommandEventArgs e)
        {
            var form   = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient(Configuration.ServiceKey);

            var orderCode = form["orderCode"];
            var amount    = Int32.Parse(form["amount"]);

            try
            {
                var response = client.GetOrderService().CaptureAuthorizedOrder(orderCode, amount);

                ServerResponse.Text = "Order code:" + response.orderCode +
                                      "<br />Payment Status: " + response.paymentStatus +
                                      "<br />Environment: " + response.environment;
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request ", exc);
            }
        }
Esempio n. 2
0
        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     = Enum.Parse(typeof(CurrencyCode), form["currency"]).ToString(),
                orderType        = OrderType.RECURRING.ToString()
            };

            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);
            }
        }
        protected void OnCaptureOrder(object sender, CommandEventArgs e)
        {
            var form   = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);

            var orderCode = form["orderCode"];
            int amount    = 0;

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

            try
            {
                var response = client.GetOrderService().CaptureAuthorizedOrder(orderCode, amount);

                ServerResponse.Text = "Order code:" + response.orderCode +
                                      "<br />Payment Status: " + response.paymentStatus +
                                      "<br />Environment: " + response.environment;
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request ", exc);
            }
        }
Esempio n. 4
0
        protected void onAuthorizeOrder(object sender, CommandEventArgs e)
        {
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);

            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);
            }
        }
        public void Setup()
        {
            var restClient = new WorldpayRestClient(Configuration.ServiceKey);

            _authService  = restClient.GetAuthService();
            _orderService = restClient.GetOrderService();
        }
        protected void OnPartialRefund(object sender, CommandEventArgs e)
        {
            int refundAmount = 0;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            string orderCode = Request["orderCode"];

            if (orderCode == null)
            {
                throw new WorldpayException("Order code must be specified");
            }

            try
            {
                refundAmount = Int32.Parse(Request["amount"]);
            } catch (Exception exc) { }

            try
            {
                client.GetOrderService().Refund(orderCode, refundAmount);
                if (refundAmount == 0)
                {
                    ServerResponse.Text = String.Format("Order <span id='order-code'>{0}</span> has been refunded for the full amount", orderCode);
                }
                else
                {
                    ServerResponse.Text = String.Format("Order <span id='order-code'>{0}</span> has been refunded for {1}", orderCode, refundAmount);
                }
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnPartialRefund(object sender, CommandEventArgs e)
        {
            int    refundAmount = 0;
            var    client       = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            string orderCode    = Request["orderCode"];

            if (orderCode == null)
            {
                throw new WorldpayException("Order code must be specified");
            }

            try
            {
                refundAmount = Int32.Parse(Request["amount"]);
            } catch (Exception exc) { }

            try
            {
                client.GetOrderService().Refund(orderCode, refundAmount);
                if (refundAmount == 0)
                {
                    ServerResponse.Text = String.Format("Order <span id='order-code'>{0}</span> has been refunded for the full amount", orderCode);
                }
                else
                {
                    ServerResponse.Text = String.Format("Order <span id='order-code'>{0}</span> has been refunded for {1}", orderCode, refundAmount);
                }
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnCaptureOrder(object sender, CommandEventArgs e)
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient(Configuration.ServiceKey);

            var orderCode = form["orderCode"];
            var amount = Int32.Parse(form["amount"]);

            try
            {
                var response = client.GetOrderService().CaptureAuthorizedOrder(orderCode, amount);

                ServerResponse.Text = "Order code:" + response.orderCode +
                                        "<br />Payment Status: " + response.paymentStatus +
                                        "<br />Environment: " + response.environment;
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request ", exc);
            }
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        //Make payment when user submit the payment
        public ActionResult Pay(PayModelDTO data)
        {
            WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", "T_S_29134e84-936f-4418-8e4e-7a757f307cc6");

            var orderRequest = new OrderRequest()
            {
                token             = data.Token,
                amount            = (int)(float.Parse(Convert.ToString(Session["Payment_Total"])) * 100),
                currencyCode      = CurrencyCode.GBP.ToString(),
                name              = "test name",
                orderDescription  = "Order description",
                customerOrderCode = "Order code"
            };

            var address = new Address()
            {
                address1    = "123 House Road",
                address2    = "A village",
                city        = "London",
                countryCode = CountryCode.GB.ToString(),
                postalCode  = "EC1 1AA"
            };

            orderRequest.billingAddress = address;

            try
            {
                OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
                Console.WriteLine("Order code: " + orderResponse.orderCode);
                ViewBag.Status      = "Success";
                ViewBag.Description = String.Format("Order Code: {0} <br/> Amount: £ {1} <br /> State: {2}"
                                                    , orderResponse.orderCode, (float)orderResponse.amount / 100, orderResponse.paymentStatus);

                Payment payment = new Payment {
                    UserId       = Session["UserID"] != null ? (int)(Session["UserID"] as int?) : -1,
                    TicketId     = (int)(Session["TicketId"] as int?), Quantity = (int)(Session["Quantity"] as int?)
                    , TotalPrice = (float)(Session["Payment_Total"] as float?), PaymentMethod = 0,
                    CreatedAt    = DateTime.Now
                };
                db.Payments.Add(payment);
                db.SaveChanges();
                db.Tickets.Find(payment.TicketId).Balance -= payment.Quantity;
                db.SaveChanges();
            }
            catch (WorldpayException e)
            {
                ViewBag.Status      = "Failure";
                ViewBag.Description = String.Format("Error Code: {0} <br/> Error Description: {1} <br /> Error Message: {2}"
                                                    , e.apiError.customCode, e.apiError.description, e.apiError.message);
                Console.WriteLine("Error code:" + e.apiError.customCode);
                Console.WriteLine("Error description: " + e.apiError.description);
                Console.WriteLine("Error message: " + e.apiError.message);
            }

            return(View("~/Views/Search/payment.cshtml"));
        }
        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);
            }
        }
        public async Task <PaymentOutput> MakePaymentAsync(WorldPayCreditCardPaymentInput input, CancellationToken cancellationToken = default)
        {
            var restClient   = new WorldpayRestClient(WorldPayUrl.apiUrl, input.ServiceKey, this.httpClientFactory);
            var chargeAmount = (input.Amount * 100).ToString().Split('.')[0];

            var orderRequest = new OrderRequest()
            {
                token             = input.WorldPayToken,
                amount            = Convert.ToInt32(chargeAmount),
                currencyCode      = String.IsNullOrEmpty(input.IsoCurrencyCode) ? "CAD" : input.IsoCurrencyCode,
                name              = input.FirstName + " " + input.LastName,
                orderDescription  = input.FirstName + " " + input.LastName,
                customerOrderCode = Guid.NewGuid().ToString()
            };

            if (input.IsRecurring)
            {
                orderRequest.orderType = "RECURRING";
            }

            var address = new Address()
            {
                address1   = input.BillingLine1,
                city       = input.BillingCity,
                postalCode = input.BillingPostalCode
            };

            orderRequest.billingAddress = address;

            var response = await restClient.GetOrderService().CreateAsync(orderRequest, cancellationToken);

            var result = new PaymentOutput();

            if (String.Equals(response?.paymentStatus, "SUCCESS", StringComparison.OrdinalIgnoreCase))
            {
                result.IsSuccessful          = true;
                result.TransactionResult     = response.paymentStatus;
                result.TransactionIdentifier = response.orderCode;
                result.AuthToken             = response.token;
            }
            else
            {
                result.IsSuccessful      = false;
                result.TransactionResult = response?.paymentStatus;
            }

            result.InvoiceNumber = "MIS" + StringUtils.RandomString(6).ToUpper();

            return(result);
        }
Esempio n. 13
0
        public async Task <WorldPayRecurringPaymentOutput> MakePaymentAsync(WorldPayRecurringPaymentInput input, CancellationToken cancellationToken = default)
        {
            var worldPayAmount = Convert.ToInt32((input.Amount * 100).ToString().Split('.')[0]);

            var restClient = new WorldpayRestClient(WorldPayUrl.apiUrl, input.ServiceKey, this.httpClientFactory);

            var orderRequest = new OrderRequest()
            {
                token            = input.WorldPayToken,
                amount           = worldPayAmount,
                currencyCode     = input.IsoCurrencyCode,
                name             = input.FirstName + " " + input.LastName,
                orderType        = "RECURRING",
                orderDescription = input.InvoiceIdentifier
            };

            var address = new Address()
            {
                address1   = input.Address1,
                address2   = input.Address2,
                city       = input.City,
                postalCode = input.PostalCode
            };

            orderRequest.billingAddress = address;

            var response = await restClient.GetOrderService().CreateAsync(orderRequest, cancellationToken);

            var output = new WorldPayRecurringPaymentOutput(input);

            if (String.Equals(response.paymentStatus, "SUCCESS", StringComparison.OrdinalIgnoreCase))
            {
                output.IsSuccessful          = true;
                output.TransactionStatus     = response.paymentStatus;
                output.TransactionResult     = response.paymentStatus;
                output.TransactionIdentifier = response.token;
            }
            else
            {
                output.SetFailure(input);
                output.TransactionStatus     = response.paymentStatus;
                output.TransactionResult     = response.paymentStatus;
                output.TransactionIdentifier = response.token;
            }

            return(output);
        }
Esempio n. 14
0
        public bool MakePayment(Donation donation)
        {
            WorldpayRestClient worldpayRestClient = new WorldpayRestClient(Url, _serverToken);
            OrderRequest       orderRequest       = new OrderRequest()
            {
                token              = donation.Token,
                amount             = donation.Sum,
                currencyCode       = donation.CurrencyCode.ToString(),
                name               = donation.Person?.UserName,
                settlementCurrency = CurrencyCode.USD.ToString(),
                orderDescription   = "Donate"
            };
            OrderService  orderService  = worldpayRestClient.GetOrderService();
            OrderResponse orderResponse = orderService.Create(orderRequest);

            return(orderResponse.paymentStatus == OrderStatus.SUCCESS);
        }
Esempio n. 15
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 = JsonConvert.SerializeObject(response, Formatting.Indented);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnRefund(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
            {
                client.GetOrderService().Refund(orderCode);
                ServerResponse.Text = String.Format("Order {0} has been refunded!", orderCode);
                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  = JsonUtils.SerializeObject(response);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnCancelOrder(object sender, CommandEventArgs e)
        {
            var form = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);

            var orderCode = form["orderCode"];

            try
            {
                client.GetOrderService().CancelAuthorizedOrder(orderCode);
                ServerResponse.Text = String.Format("Authorised order {0} has been cancelled", orderCode);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request ", exc);
            }
        }
Esempio n. 19
0
        protected void OnCancelOrder(object sender, CommandEventArgs e)
        {
            var form   = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient(Configuration.ServiceKey);

            var orderCode = form["orderCode"];

            try
            {
                client.GetOrderService().CancelAuthorizedOrder(orderCode);
                ServerResponse.Text  = String.Format("Authorised order {0} has been cancelled", orderCode);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
            catch (Exception exc)
            {
                throw new InvalidOperationException("Error sending request ", exc);
            }
        }
Esempio n. 20
0
        public IActionResult Complete(PayModelView pay)
        {
            WorldpayRestClient restClient = new WorldpayRestClient("https://api.worldpay.com/v1", _settings.ServiceKey);

            var orderRequest = new OrderRequest()
            {
                token             = pay.Token,
                amount            = Convert.ToInt32(pay.Total),
                currencyCode      = CurrencyCode.GBP.ToString(),
                name              = "test name",
                orderDescription  = "Order description",
                customerOrderCode = "Order code"
            };

            var address = new Address()
            {
                address1    = "123 House Road",
                address2    = "A village",
                city        = "London",
                countryCode = CountryCode.GB.ToString(),
                postalCode  = "EC1 1AA"
            };

            orderRequest.billingAddress = address;

            try
            {
                OrderResponse orderResponse = restClient.GetOrderService().Create(orderRequest);
                Console.WriteLine("Order code: " + orderResponse.orderCode);
            }
            catch (WorldpayException e)
            {
                Console.WriteLine("Error code:" + e.apiError.customCode);
                Console.WriteLine("Error description: " + e.apiError.description);
                Console.WriteLine("Error message: " + e.apiError.message);
            }

            return(View());
        }
Esempio n. 21
0
        protected void OnRefund(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
            {
                client.GetOrderService().Refund(orderCode);
                ServerResponse.Text  = String.Format("Order {0} has been refunded!", orderCode);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        protected void OnPartialRefund(object sender, CommandEventArgs e)
        {
            string orderCode = Request["orderCode"];

            if (orderCode == null)
            {
                throw new WorldpayException("Order code must be specified");
            }

            int refundAmount = Int32.Parse(Request["amount"]);

            var client = new WorldpayRestClient(Configuration.ServiceKey);

            try
            {
                client.GetOrderService().Refund(orderCode, refundAmount);
                ServerResponse.Text  = String.Format("Order {0} has been refunded for {1}", orderCode, refundAmount);
                SuccessPanel.Visible = true;
            }
            catch (WorldpayException exc)
            {
                ErrorControl.DisplayError(exc.apiError);
            }
        }
        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);
            }
        }
        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["cvc"];
            cardRequest.name        = form["name"];
            cardRequest.expiryMonth = Convert.ToInt32(form["exp-month"]);
            cardRequest.expiryYear  = Convert.ToInt32(form["exp-year"]);
            cardRequest.type        = form["cardType"];
            int?_amount       = 0;
            var _currencyCode = "";
            Dictionary <string, string> custIdentifiers = new Dictionary <string, string>();

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

            try
            {
                if (!string.IsNullOrEmpty(form["amount"]))
                {
                    double n;
                    bool   isNumeric = double.TryParse(form["amount"], out n);
                    _amount = isNumeric ? (int)(Convert.ToDecimal(form["amount"]) * 100) : -1;
                }
            }
            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"],
                telephoneNumber = form["telephone-number"],
                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"],
                telephoneNumber = form["delivery-telephone-number"],
                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"],
                amount              = _amount,
                currencyCode        = _currencyCode,
                name                = is3DS && Session["mode"].Equals("test") ? "3D" : form["name"],
                shopperEmailAddress = form["shopper-email"],
                statementNarrative  = form["statement-narrative"],
                billingAddress      = billingAddress,
                deliveryAddress     = deliveryAddress,
                threeDSecureInfo    = is3DS ? threeDSInfo : new ThreeDSecureInfo(),
                is3DSOrder          = is3DS,
                authorizeOnly       = form["authorizeOnly"] == "on",
                orderType           = orderType.ToString(),
                customerIdentifiers = custIdentifiers,
                customerOrderCode   = form["customer-order-code"],
                orderCodePrefix     = form["order-code-prefix"],
                orderCodeSuffix     = form["order-code-suffix"]
            };

            var directOrder = form["direct-order"] == "1";

            if (directOrder)
            {
                request.shopperLanguageCode = form["language-code"];
                request.reusable            = form["chkReusable"] == "on";
                request.paymentMethod       = new CardRequest()
                {
                    name        = form["name"],
                    expiryMonth = Convert.ToInt32(form["exp-month"]),
                    expiryYear  = Convert.ToInt32(form["exp-year"]),
                    cardNumber  = form["number"],
                    cvc         = form["cvc"]
                };
            }

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

            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);
            }
        }
        private void createAPMOrder()
        {
            var form          = HttpContext.Current.Request.Form;
            var client        = new WorldpayRestClient((string)Session["apiEndpoint"], (string)Session["service_key"]);
            int?_amount       = 0;
            var _currencyCode = "";
            Dictionary <string, string> custIdentifiers = new Dictionary <string, string>();

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

            try
            {
                if (!string.IsNullOrEmpty(form["amount"]))
                {
                    double n;
                    bool   isNumeric = double.TryParse(form["amount"], out n);
                    _amount = isNumeric ? (int)(Convert.ToDecimal(form["amount"]) * 100) : -1;
                }
            }
            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"],
                telephoneNumber = form["telephone-number"],
                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"],
                telephoneNumber = form["delivery-telephone-number"],
                state           = "",
                countryCode     = Enum.Parse(typeof(CountryCode), form["delivery-countryCode"]).ToString()
            };

            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   = form["customer-order-code"],
                orderCodePrefix     = form["order-code-prefix"],
                orderCodeSuffix     = form["order-code-suffix"],
                successUrl          = form["success-url"],
                failureUrl          = form["failure-url"],
                pendingUrl          = form["pending-url"],
                cancelUrl           = form["cancel-url"]
            };

            var directOrder = form["direct-order"] == "1";

            if (directOrder)
            {
                var _apmFields = new Dictionary <string, string>();
                if (!string.IsNullOrEmpty(form["swiftCode"]))
                {
                    _apmFields.Add("swiftCode", form["swiftCode"]);
                }
                if (!string.IsNullOrEmpty(form["shopperBankCode"]))
                {
                    _apmFields.Add("shopperBankCode", form["shopperBankCode"]);
                }

                request.shopperLanguageCode = form["language-code"];
                request.reusable            = form["chkReusable"] == "on";
                request.paymentMethod       = new APMRequest()
                {
                    apmName            = form["apm-name"],
                    shopperCountryCode = form["countryCode"],
                    apmFields          = _apmFields
                };
            }

            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);
            }
        }
Esempio n. 26
0
        protected void OnCreateOrder(object sender, CommandEventArgs e)
        {
            var form   = HttpContext.Current.Request.Form;
            var client = new WorldpayRestClient((string)Session["service_key"]);

            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 = (CountryCode)Enum.Parse(typeof(CountryCode), form["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 orderType = (OrderType)Enum.Parse(typeof(OrderType), form["radOrderType"]);

            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"]),
                name                = is3DS ? "3D" : form["name"],
                billingAddress      = billingAddress,
                threeDSecureInfo    = is3DS ? threeDSInfo : new ThreeDSecureInfo(),
                is3DSOrder          = is3DS,
                authorizeOnly       = form["authoriseOnly"] == "on",
                orderType           = orderType,
                customerIdentifiers = new List <Entry>()
                {
                    new Entry()
                    {
                        key   = "my-customer-ref",
                        value = "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);
            }
        }
Esempio n. 27
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);
            }
        }
 public void Setup()
 {
     var restClient = new WorldpayRestClient(Configuration.ServiceKey);
     _authService = restClient.GetAuthService();
     _orderService = restClient.GetOrderService();
 }
Esempio n. 29
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);
            }
        }
Esempio n. 30
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);
            }
        }
Esempio n. 31
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);
            }
        }