Exemplo n.º 1
0
        public ActionResult Query(QueryViewModel queryViewModel)
        {
            //testing query functionality
            Query query = new Query();

            query.InitializeValues(queryViewModel.Stamp, queryViewModel.Reference,
                                   this.merchantId, queryViewModel.Amount, this.merchantSecretKey);

            //send Query to Checkout Finland
            try
            {
                ViewBag.QueryResponse = CheckoutClient.postQueryData(query.FormData());
            }
            catch (WebException ex)
            {
                //exception handling for testing
                ViewBag.PaymentResponseMessage = "error: " + ex.ToString();
                return(View("PaymentResponseError"));
            }

            //get status value
            XDocument xmlDoc      = XDocument.Parse(ViewBag.QueryResponse);
            XElement  statusNode  = (XElement)xmlDoc.FirstNode;
            string    statusValue = statusNode.Value;

            ViewBag.QueryResponseMessage =
                PaymentUtils.GetPaymentResponseStatusMessage(statusValue);

            return(View());
        }
        public SingleResponse <int> Insert(CheckoutClient checkoutClient)
        {
            SingleResponse <int> response = new SingleResponse <int>();

            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = ConnectionHelper.GetConnectionString();

            SqlCommand command = new SqlCommand();

            command.CommandText =
                "INSERT INTO CHECKOUT_CLIENTS (SAIDANOPRAZO, MULTA, IDCHECKIN, IDEMPLOYEES) VALUES (@SAIDANOPRAZO, @MULTA, @IDCHECKIN, @IDEMPLOYEES) SELECT SCOPE_IDENTITY()";
            command.Parameters.AddWithValue("@SAIDANOPRAZO", checkoutClient.ExitOnTime);
            command.Parameters.AddWithValue("@MULTA", checkoutClient.Penalty);
            command.Parameters.AddWithValue("@IDCHECKIN", checkoutClient.IDCheckin);
            command.Parameters.AddWithValue("@IDEMPLOYEES", checkoutClient.IDEmployee);

            command.Connection = connection;

            try {
                connection.Open();
                int idGerado = Convert.ToInt32(command.ExecuteScalar());
                response.Success = true;
                response.Message = "Cadastrado com sucesso.";
                response.Data    = idGerado;
            } catch (Exception ex) {
                response.Success        = false;
                response.Message        = "Erro no banco de dados, contate o administrador.";
                response.StackTrace     = ex.StackTrace;
                response.ExceptionError = ex.Message;
            } finally {
                connection.Close();
            }
            return(response);
        }
Exemplo n.º 3
0
        public void it_updates_orderid()
        {
            var client = new CheckoutClient(TestConfig.OrderBaseUri, TestConfig.MerchantId, TestConfig.SharedSecret);

            var result = client.UpdateOrderId("FZMN086AK49DDYA4YTO0JJPQKBG", "BB-ZNO-1516");

            result.ShouldBeEquivalentTo(true);
        }
Exemplo n.º 4
0
        public void TestScan(string scanValues)
        {
            try
            {
                var proxy = new CheckoutClient();

                proxy.Scan(scanValues);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 5
0
        public void TestGetTotalPrice()
        {
            try
            {
                var proxy = new CheckoutClient();

                var result = proxy.GetTotalPrice();

                if (result != 0)
                {
                    throw new Exception("GetTotalPrice Does Not Return 0");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 6
0
        public void it_gets_checkout_snippet(
            List <CartItem> cartItems,
            ShippingItem shippingItem)
        {
            var sut   = new CheckoutClient(TestConfig.OrderBaseUri, TestConfig.MerchantId, TestConfig.SharedSecret);
            var items = new List <ICartItem>();

            items.AddRange(cartItems);
            items.Add(shippingItem);

            var testUrl = "http://www.mysite.com";

            var checkoutUris = new CheckoutUris(
                new Uri(testUrl), new Uri(testUrl), new Uri(testUrl), new Uri(testUrl));

            var response = sut.Checkout(items, Locale.Norway, checkoutUris);

            response.Snippet.Should().NotBeNullOrWhiteSpace();
            response.Location.AbsoluteUri.Should().StartWith(TestConfig.OrderBaseUri.ToString());
        }
Exemplo n.º 7
0
        public void TestCalculateSingleSKUTotalPrice(string scanValues, string invalidValue)
        {
            try
            {
                var proxy = new CheckoutClient();

                proxy.Scan(scanValues);

                proxy.GetTotalPrice();

                throw new Exception("Error was expected, however no error thrown");
            }
            catch (Exception e)
            {
                var expectedError = string.Format("The SKU {0} is not a valid value", invalidValue);

                if (e.Message != expectedError)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Exemplo n.º 8
0
        public void TestCalculateSingleSKUTotalPrice(string scanValues, int expectedResult)
        {
            try
            {
                var proxy = new CheckoutClient();

                proxy.Scan(scanValues);

                var result = proxy.GetTotalPrice();

                if (result != expectedResult)
                {
                    var error = string.Format(
                        "For the input of {0}, the expected the value of {1} should be returned. Returned values from the service was {2}", scanValues, expectedResult, result);

                    throw new Exception(error);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 9
0
        public ActionResult Payment(PaymentViewModel paymentViewModel)
        {
            //the below creates for example
            //URL: http://localhost:53416/Checkout/PaymentResponse
            string urlBeginning = this.TestUrl();
            string returnURL    = urlBeginning + "/Checkout/PaymentResponse";
            string cancelURL    = urlBeginning + "/Checkout/PaymentResponse";
            string rejectURL    = urlBeginning + "/Checkout/PaymentResponse";
            string delayedURL   = urlBeginning + "/Checkout/PaymentResponse";

            //Create Payment
            Payment payment = new Payment();

            //set merchant data (required)
            payment.InitializeValues(merchantId, merchantSecretKey);

            //other required parameters
            payment.Stamp = DateTime.Now.ToString("MMddyyyyhhmmssfff");
            string modifiedAmount = PaymentUtils.ModifyAmount(paymentViewModel.Amount); // remove comma or dot

            payment.Amount       = modifiedAmount;                                      // 1 Euro minimum purchase (100 cents)
            Session["Amount"]    = modifiedAmount;                                      //store Amount in Session for Query (just for testing)
            payment.Reference    = "123456";
            payment.ReturnUrl    = returnURL;
            payment.CancelUrl    = cancelURL;
            payment.DeliveryDate = DateTime.Now.ToString("yyyyMMdd");

            payment.Language = paymentViewModel.Language; // (required param)
            payment.Country  = "FIN";                     // (required)

            payment.Device = paymentViewModel.Device;     //HTML or XML

            //Optional
            payment.RejectUrl  = rejectURL;
            payment.DelayedUrl = delayedURL;
            payment.FirstName  = paymentViewModel.FirstName;
            payment.FamilyName = paymentViewModel.FamilyName;
            payment.Address    = paymentViewModel.Address;
            payment.Postcode   = paymentViewModel.Postcode;
            payment.PostOffice = paymentViewModel.PostOffice;
            payment.Message    = paymentViewModel.Message;

            payment.Validate(); //optional validation (Checkout Finland validates data too)

            //Send payment data to Checkout Finland,
            //then make received payment options available
            //to the view in ViewBag
            try
            {
                ViewBag.BankPaymentOptions = CheckoutClient.postPaymentData(payment.FormData());
            }
            catch (WebException ex)
            {
                //exception handling for testing
                ViewBag.PaymentResponseMessage = "error: " + ex.ToString();
                return(View("PaymentResponseError"));
            }

            //if device HTML (1), then use view for HTML page
            if (payment.Device.Equals(Checkout.Payment.Device_HTML))
            {
                return(View("BankPaymentOptionsHtml"));
            }
            else //parse XML format
            {
                //pass merchant info for view (optional)
                //some of this data is also available
                //from Payment object and XML response
                ViewBag.MerchantNameAndVatId          = "Testi Oy (123456-7)";
                ViewBag.MerchantEmail                 = "*****@*****.**";
                ViewBag.MerchantAddress               = "Testikuja 1";
                ViewBag.MerchantPostCodeAndPostOffice = "12345 Testilä";
                ViewBag.MerchantPhone                 = "012-345 678";

                //translations for Xml view
                ViewBag.Translations = PaymentUtils.TranslationsForXml[payment.Language];

                //payment for view
                ViewBag.Payment = payment;

                return(View("BankPaymentOptionsXML"));
            }
        }
Exemplo n.º 10
0
 public CheckoutClientTest()
 {
     _checkoutClient = new CheckoutClient(new HttpClient(), "https://localhost:5001/");
 }
Exemplo n.º 11
0
        /// <summary>
        /// 客户端服务实例产生器
        /// </summary>
        /// <param name="type">产生的服务类型</param>
        /// <returns></returns>
        private static object build(ClientType.Type type)
        {
            switch (type)
            {
            case ClientType.Type.Account:
            {
                AccountClient temp = new AccountClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <AccountClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Action:
            {
                ActionClient temp = new ActionClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <ActionClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Brand:
            {
                BrandClient temp = new BrandClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <BrandClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.CarSummery:
            {
                CarSummeryClient temp = new CarSummeryClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <CarSummeryClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Checkout:
            {
                CheckoutClient temp = new CheckoutClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <CheckoutClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.City:
            {
                CityClient temp = new CityClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <CityClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Order:
            {
                OrderClient temp = new OrderClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <OrderClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.OrderSummery:
            {
                OrderSummeryClient temp = new OrderSummeryClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <OrderSummeryClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Province:
            {
                ProvinceClient temp = new ProvinceClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <ProvinceClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.RAP:
            {
                RAPClient temp = new RAPClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <RAPClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Salary:
            {
                SalaryClient temp = new SalaryClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <SalaryClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.SalaryAppend:
            {
                SalaryAppendClient temp = new SalaryAppendClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <SalaryAppendClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.SalaryInfoSummery:
            {
                SalaryInfoSummeryClient          temp  = new SalaryInfoSummeryClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <SalaryInfoSummeryClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.SalaryLog:
            {
                SalaryLogClient temp = new SalaryLogClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <SalaryLogClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Shop:
            {
                ShopClient temp = new ShopClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <ShopClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Type:
            {
                TypeClient temp = new TypeClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <TypeClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.Version:
            {
                VersionClient temp = new VersionClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <VersionClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.WorkRAP:
            {
                WorkRAPClient temp = new WorkRAPClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <WorkRAPClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.UserManager:
            {
                UserManagerClient temp = new UserManagerClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <UserManagerClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.UserSummery:
            {
                UserSummeryClient temp = new UserSummeryClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <UserSummeryClient>(type, temp);
                return(temp);
            }

            case ClientType.Type.GetCar:
            {
                GetCarClient temp = new GetCarClient();
                UserNamePasswordClientCredential UNPCC = temp.ClientCredentials.UserName;
                UNPCC.UserName = GlobalParams.UserName;
                UNPCC.Password = GlobalParams.Password;
                AddClient <GetCarClient>(type, temp);
                return(temp);
            }
            }
            ;
            return(null);
        }