Beispiel #1
0
        private void CreateAndRunForm(FormCreateRequest request)
        {
            using (FormManagerService service = new FormManagerService())
            {
                var response = service.CreateForm(request);
                Console.WriteLine(response);

                var newformResponse = service.NewForm(response.Value[0].Id);
                Console.WriteLine(newformResponse);

                var idFormInstance = newformResponse.Value;
                var formInstance   = SBSFormModel.Instance.GetFormInstance(idFormInstance);

                ManualResetEvent eventStop = new ManualResetEvent(false);
                var runformResponse        = service.RunForm(idFormInstance);
                Console.WriteLine(runformResponse);

                formInstance.Submitted += form => { eventStop.Set(); };
                formInstance.Cancelled += form => { eventStop.Set(); };
                service.RunFormEnded   += form =>
                {
                    service.SaveForm(idFormInstance);
                    if (form.Id == idFormInstance)
                    {
                        eventStop.Set();
                    }
                };

                eventStop.WaitOne();
                eventStop.Dispose();
            }
        }
        public void TestChangeFormAndFormField()
        {
            FormCreateRequest request = new FormCreateRequest
            {
                Forms = new List <FormTemplateFormDefinition>
                {
                    new FormTemplateFormDefinition
                    {
                        Title       = "Test Marc Form",
                        Name        = "MarcForm",
                        Description = "This is a test form",
                        Fields      = new List <FormTemplateFieldDefinition>
                        {
                            new FormTemplateFieldDefinition
                            {
                                Name      = "cbSmallBiz",
                                FieldType = "checkbox",
                                Prompt    = "Are you a small business?"
                            }
                        }
                    }
                }
            };

            using (FormManagerService service = new FormManagerService(new FormManagerServiceSettings {
                NoCreateRestService = true
            }))
            {
                var response = service.CreateForm(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(response.StatusCode, ResponseStatusCodes.OK);
                var formDefId = response.Value[0].Id;

                const string newTitle       = "Test Geeta Form";
                const string newPrompt      = "Are you are large business?";
                var          responseChange = service.ChangeForm(formDefId, new Dictionary <string, object>
                {
                    { "title", newTitle },
                    { "cbSmallBiz.prompt", newPrompt }
                });
                Assert.IsNotNull(responseChange);
                Assert.AreEqual(responseChange.StatusCode, ResponseStatusCodes.OK);
                Assert.IsTrue(responseChange.Value);

                var responseDef = service.FindFormDefinitionById(formDefId);
                Assert.IsNotNull(responseDef);
                Assert.AreEqual(responseDef.StatusCode, ResponseStatusCodes.OK);
                Assert.IsNotNull(responseDef.Value);
                Assert.AreEqual(responseDef.Value.Definition.Title, newTitle);
                Assert.AreEqual(responseDef.Value.Definition.Fields[0].Prompt, newPrompt);
            }
        }
Beispiel #3
0
        public ContentResult Pay(string Id,
                                 [FromServices] SessionManagerService sessionManager,
                                 [FromServices] OperationManagerService operationManager,
                                 [FromServices] FormManagerService formManager,
                                 [FromServices] PaymentSystemContext dbContext,
                                 [FromServices] FormDataCryptService cryptService)
        {
            try
            {
                var session = sessionManager.Get(Id);
                if (session.SessionType != SessionType.OneStep && session.SessionType != SessionType.TwoStep)
                {
                    return(base.Content(formManager.GetErrorForm()));
                }
                var result     = operationManager.CheckPaymentPossibility(session);
                var dictionary = new Dictionary <string, string>();
                switch (result)
                {
                case PaymentPossibility.LimitExceeded:
                case PaymentPossibility.SessionExpired:
                    return(base.Content(formManager.GetErrorForm()));

                case PaymentPossibility.AlreadyPaid:
                    return(base.Content(formManager.GetSuccessForm()));

                default:
                    var generationTime = DateTime.UtcNow;
                    session.LastFormGenerationTime = generationTime;
                    session.TryCount++;
                    dbContext.SaveChanges();
                    var formSign = new FormSign {
                        GenerationTime = generationTime, SessionId = session.Id
                    };
                    dictionary.Add("sessionId", session.ExternalId);
                    dictionary.Add("code", cryptService.Crypt(formSign));
                    return(base.Content(formManager.GetPaymentForm(dictionary)));
                }
            }
            catch (Exception)
            {
                return(base.Content(formManager.GetErrorForm()));
            }
        }
        public ContentResult Pay([FromForm] SubmitPay submitPay,
                                 [FromServices] OperationManagerService operationManager,
                                 [FromServices] FormManagerService formManager,
                                 [FromServices] PaymentSystemContext dbContext,
                                 [FromServices] FormDataCryptService cryptService)
        {
            if (string.IsNullOrEmpty(submitPay.ExternalId) || string.IsNullOrEmpty(submitPay.Code))
            {
                return(base.Content(formManager.GetErrorForm()));
            }
            var formCrypt = cryptService.DeCrypt(submitPay.Code);
            var session   = dbContext.Session.Include(x => x.Merchant).FirstOrDefault(x => x.Id == formCrypt.SessionId);

            if (session == null || session.ExternalId != submitPay.ExternalId || session.ExpireTime != formCrypt.GenerationTime)
            {
                return(base.Content(formManager.GetErrorForm()));
            }

            var paymentData = new PaymentData(submitPay.Pan, submitPay.Year, submitPay.Month, submitPay.Cvv);

            var result = operationManager.Deposit(session.Merchant, session, paymentData);

            switch (result.OperationStatus)
            {
            case OperationStatus.AdditionalAuth:
                return(base.Content(formManager.Get3DsForm(result.AdditionalAuth)));

            case OperationStatus.Pending:
                return(base.Content(formManager.GetPendingForm()));

            case OperationStatus.Success:
                return(base.Content(formManager.GetSuccessForm()));

            case OperationStatus.Redirected:
                return(base.Content(formManager.GetRedirectForm(result.RedirectedUrl)));

            case OperationStatus.Error:
                return(session.CanTryToPayAnotherTime ? base.Content(formManager.GetRedirectForm("/form/v1/pay")) : base.Content(formManager.GetErrorForm()));

            default:
                return(base.Content(formManager.GetErrorForm()));
            }
        }
        public ContentResult From3Ds([FromForm] Submit3Ds submit3Ds,
                                     [FromServices] OperationManagerService operationManager,
                                     [FromServices] FormManagerService formManager,
                                     [FromServices] PaymentSystemContext dbContext)
        {
            var operation3ds = dbContext.Operation3ds.Include(x => x.Operation).FirstOrDefault(x => x.LocalMd == submit3Ds.MD);

            if (operation3ds == null || operation3ds.Operation.OperationStatus != OperationStatus.AdditionalAuth)
            {
                return(base.Content(formManager.GetErrorForm()));
            }
            var session     = dbContext.Session.Include(x => x.Operation).First(x => x.Id == operation3ds.Operation.SessionId);
            var possibility = operationManager.CheckPaymentPossibility(session, operation3ds.Operation);

            if (possibility != PaymentPossibility.PaymentAllowed)
            {
                return(base.Content(formManager.GetErrorForm()));
            }

            var result = operationManager.Deposit(session, operation3ds, submit3Ds);

            switch (result.OperationStatus)
            {
            case OperationStatus.Pending:
                return(base.Content(formManager.GetPendingForm()));

            case OperationStatus.Success:
                return(base.Content(formManager.GetSuccessForm()));

            case OperationStatus.Redirected:
                return(base.Content(formManager.GetRedirectForm(result.RedirectedUrl)));

            case OperationStatus.Error:
                return(session.CanTryToPayAnotherTime ? base.Content(formManager.GetRedirectForm("/form/v1/pay")) : base.Content(formManager.GetErrorForm()));

            default:
                return(base.Content(formManager.GetErrorForm()));
            }
        }
        private void CreateAndRunForm(FormCreateRequest request)
        {
            using (FormManagerService service = new FormManagerService(new FormManagerServiceSettings {
                AutomatedInput = true
            }))
            {
                var response = service.CreateForm(request);
                Assert.IsNotNull(response);
                Assert.AreEqual(response.StatusCode, ResponseStatusCodes.OK);

                var formDefId = response.Value[0].Id;

                var newformResponse = service.NewForm(formDefId);
                Assert.IsNotNull(newformResponse);
                Assert.AreEqual(newformResponse.StatusCode, ResponseStatusCodes.OK);

                var idFormInstance = newformResponse.Value;
                var formInstance   = SBSFormModel.Instance.GetFormInstance(idFormInstance);
                Assert.IsNotNull(formInstance);

                ManualResetEvent eventStop = new ManualResetEvent(false);
                formInstance.Submitted += form => { eventStop.Set(); };
                formInstance.Cancelled += form => { eventStop.Set(); };
                service.RunFormEnded   += form =>
                {
                    if (form.Id == idFormInstance)
                    {
                        eventStop.Set();
                    }
                };

                var runformResponse = service.RunForm(idFormInstance);
                Assert.IsNotNull(runformResponse);
                Assert.AreEqual(runformResponse.StatusCode, ResponseStatusCodes.OK);

                bool rc = eventStop.WaitOne(5 * 1000);
                Assert.IsTrue(rc, "The test timed out");
            }
        }
        public void TestCreateAndRunDIYOnboardingForm()
        {
            var serviceSettings = new FormManagerServiceSettings
            {
                AutomatedInput        = true,
                NoCreateRestService   = true,
                NoMessaging           = true,
                NoPersistence         = true,
                MaxRepeaterIterations = 1
            };

            using (FormManagerService service = new FormManagerService(serviceSettings))
            {
                // Load the form definition
                var loadDefResponse = service.LoadFormDefinitionFromFile("./DIYOnboardingForm.json");
                Assert.IsNotNull(loadDefResponse);
                Assert.AreEqual(loadDefResponse.StatusCode, ResponseStatusCodes.OK);

                var createRequest = Json.Deserialize <FormCreateRequest>(loadDefResponse.Value);
                Assert.IsNotNull(createRequest);

                // Create the internal form definition
                var createResponse = service.CreateForm(createRequest);
                Assert.IsNotNull(createResponse);
                Assert.AreEqual(createResponse.StatusCode, ResponseStatusCodes.OK);
                Assert.IsNotNull(createResponse.Value);

                // We should get back an array of name/value pairs
                var formDefId = createResponse.Value[0].Id;

                // Create an instance of the DIYOnboarding form from the template
                var newformResponse = service.NewForm(formDefId);
                Assert.IsNotNull(newformResponse);
                Assert.AreEqual(newformResponse.StatusCode, ResponseStatusCodes.OK);

                // Read the instance and make sure it really exists
                var idFormInstance = newformResponse.Value;
                var formInstance   = SBSFormModel.Instance.GetFormInstance(idFormInstance);
                Assert.IsNotNull(formInstance);

                // Detect when the form is done running
                ManualResetEvent eventStop = new ManualResetEvent(false);
                formInstance.Submitted += form =>
                {
//                    eventStop.Set();
                };
                formInstance.Cancelled += form =>
                {
                    eventStop.Set();
                };
                service.RunFormEnded += form =>
                {
                    if (form.Id == idFormInstance)
                    {
                        eventStop.Set();
                    }
                };

                // Run the form asynchronously
                var runformResponse = service.RunForm(idFormInstance);
                Assert.IsNotNull(runformResponse);
                Assert.AreEqual(runformResponse.StatusCode, ResponseStatusCodes.OK);

                // Wait for the form to end
                bool rc = eventStop.WaitOne();
                eventStop.Dispose();
                Assert.IsTrue(rc, "The test timed out");
            }

            Console.WriteLine("TestCreateAndRunDIYOnboardingForm: We reached the end of the test");
        }
        public void TestRepeaterGroup()
        {
            FormCreateRequest request = new FormCreateRequest
            {
                Forms = new List <FormTemplateFormDefinition>
                {
                    new FormTemplateFormDefinition
                    {
                        Title       = "Test Repeater Marc Form",
                        Name        = "RepeaterGroupForm",
                        Description = "This is a form for testing a repeater group",
                        Fields      = new List <FormTemplateFieldDefinition>
                        {
                            new FormTemplateFieldDefinition {
                                Name = "fieldOne", FieldType = "edit", Prompt = "Hit anything", DefaultValue = "foo"
                            },
                            new FormTemplateFieldDefinition
                            {
                                Name       = "employeeDetailsGroup",
                                FieldType  = "repeater",
                                Properties = new Properties
                                {
                                    { "groupname", "Employees" },
                                    { "suffix", "${index}" },
                                    { "end", "cbAddAnother" },
                                    { "continuevalue", true }      // if the value of cbAddAnother is true, then loop back
                                }
                            },
                            new FormTemplateFieldDefinition {
                                Name = "a", FieldType = "edit", Prompt = "a"
                            },
                            new FormTemplateFieldDefinition {
                                Name = "b", FieldType = "edit", Prompt = "b"
                            },
                            new FormTemplateFieldDefinition {
                                Name = "c", FieldType = "edit", Prompt = "c"
                            },
                            new FormTemplateFieldDefinition
                            {
                                Name = "btnSave", FieldType = "button", Prompt = "Save Employee", SubmissionFunctions = new List <FormSubmissionFunction>
                                {
                                    new FormSubmissionFunction
                                    {
                                        Workflow   = "rest://localhost:8089/DIYOnboardingService/form/${var:RepeaterGroupForm.Id}/employee/add",
                                        Properties = new Properties
                                        {
                                            { "method", "post" },
                                            { "body", "${form:RepeaterGroupForm}" },
                                            { "bodyFormat", "json" }
                                        }
                                    }
                                }
                            },
                            new FormTemplateFieldDefinition {
                                Name = "cbAddAnother", FieldType = "checkbox", Prompt = "Add another employee"
                            },
                            new FormTemplateFieldDefinition {
                                Name = "fieldTwo", FieldType = "edit", Prompt = "Hit anything", DefaultValue = "baz"
                            },
                        }
                    }
                }
            };

            // Make sure that this request is serializable into Json
            Json.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            var json = Json.Serialize(request);

            Assert.IsNotNull(json);

            using (FormManagerService service = new FormManagerService(new FormManagerServiceSettings {
                NoCreateRestService = true, NoMessaging = true, AutomatedInput = true
            }))
            {
                // Create the form definition
                var responseCreate = service.CreateForm(request);
                Assert.IsNotNull(responseCreate);
                Assert.AreEqual(responseCreate.StatusCode, ResponseStatusCodes.OK);

                // Create an instance of the form.
                // This will exercise the logic that creates the SBSRepeaterField
                var formDefId       = responseCreate.Value[0].Id;
                var responseNewForm = service.NewForm(formDefId);
                Assert.IsNotNull(responseNewForm);
                Assert.AreEqual(responseNewForm.StatusCode, ResponseStatusCodes.OK);

                var idFormInstance = responseNewForm.Value;

                // Make sure that we can find the repeater field within the form
                var responseField = service.GetField(idFormInstance, "employeeDetailsGroup");
                Assert.IsNotNull(responseField);
                Assert.AreEqual(responseField.StatusCode, ResponseStatusCodes.OK);
                Assert.IsNotNull(responseField.Value);

                var field = responseField.Value;
                Assert.IsTrue(field is SBSRepeaterField);

                // Make sure that the properties took hold
                SBSRepeaterField repeaterField = (SBSRepeaterField)field;
                Assert.AreEqual(repeaterField.EndingFieldName, "cbAddAnother");

                // Get the instance of the form
                var formInstance = SBSFormModel.Instance.GetFormInstance(idFormInstance);
                Assert.IsNotNull(formInstance);

                // Prepare for the form to run asynchronously
                ManualResetEvent eventStop = new ManualResetEvent(false);
                formInstance.Submitted += form => { eventStop.Set(); };
                formInstance.Cancelled += form => { eventStop.Set(); };
                service.RunFormEnded   += form =>
                {
                    if (form.Id == idFormInstance)
                    {
                        eventStop.Set();
                    }
                };

                // Run the form asynchronously
                var runformResponse = service.RunForm(idFormInstance);
                Assert.IsNotNull(runformResponse);
                Assert.AreEqual(runformResponse.StatusCode, ResponseStatusCodes.OK);

                // Wait for the form to be finished
                bool rc = eventStop.WaitOne();
                Assert.IsTrue(rc, "The test failed");
            }
        }