public async Task <IActionResult> AjaxCreate(string publicToken, string planNumber)
        {
            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: publicToken);

            try
            {
                var createResponse = await installmentPlanApi.InstallmentPlanCreateAsync(new CreateInstallmentPlanRequest()
                {
                    InstallmentPlanNumber = planNumber,
                    PlanApprovalEvidence  = new PlanApprovalEvidence(areTermsAndConditionsApproved: true)
                });

                return(Json(new { success = true, require3d = false }));
            }
            catch (SplititApiException ex)
            {
                if (ex.Code == "641")
                {
                    return(Json(new { success = true, require3d = true }));
                }
                else
                {
                    return(Json(new { success = false, errorCode = ex.Code, additionalInfo = ex.AdditionalInfo }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, additionalInfo = ex.Message }));
            }
        }
        public async Task <IActionResult> OrderComplete(string planNumber)
        {
            var amount = 860; // Usually this comes from DB.

            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi    = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var verifyPaymentResponse = installmentPlanApi.InstallmentPlanVerifyPayment(new VerifyPaymentRequest()
            {
                InstallmentPlanNumber = planNumber
            });

            if (verifyPaymentResponse.IsPaid == true && verifyPaymentResponse.OriginalAmountPaid == amount)
            {
                return(View(new OrderCompleteModel()
                {
                    Ok = true
                }));
            }
            else
            {
                return(View(new OrderCompleteModel()
                {
                    Ok = false
                }));
            }
        }
        public async Task <JsonResult> AjaxInitiate(
            decimal amount, int?numInstallments = null, bool?secure3d = false, bool?autoCapture = null,
            int numOptions = 6, bool pascalCase = false)
        {
            var billingAddress = new AddressData();
            var consumerModel  = new ConsumerData(isLocked: false, isDataRestricted: false);

            await this.TryUpdateModelAsync(billingAddress, "billingAddress");

            await this.TryUpdateModelAsync(consumerModel, "consumerModel");

            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var initResponse       = installmentPlanApi.InstallmentPlanInitiate(new InitiateInstallmentPlanRequest()
            {
                PlanData = new PlanData(
                    amount: new MoneyWithCurrencyCode(amount, "USD"),
                    numberOfInstallments: numInstallments,
                    attempt3DSecure: secure3d,
                    autoCapture: autoCapture),
                BillingAddress    = billingAddress,
                ConsumerData      = consumerModel,
                PaymentWizardData = new PaymentWizardData(
                    requestedNumberOfInstallments: string.Join(",", Enumerable.Range(1, numOptions)))
            });

            return(new JsonResult(initResponse));
        }
Exemple #4
0
        // Authenticate with the api
        void Login(string username, string password)
        {
            var loginApi = new LoginApi(Configuration.Sandbox);
            var request  = new LoginRequest(userName: username, password: password);

            var loginResult = loginApi.LoginPost(request);

            PlanApi = new InstallmentPlanApi(Configuration.Sandbox, sessionId: loginResult.SessionId);
        }
Exemple #5
0
        public async Task <IActionResult> AmountChangeAjaxAsync(string planNumber, decimal newAmount, string currency = "USD")
        {
            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var initResponse       = installmentPlanApi.InstallmentPlanInitiate(new InitiateInstallmentPlanRequest()
            {
                InstallmentPlanNumber = planNumber,
                PlanData = new PlanData(
                    amount: new MoneyWithCurrencyCode(newAmount, currency))
            });

            return(Json(initResponse));
        }
Exemple #6
0
        public async Task <IActionResult> EmbeddedPaymentForm(int options = 5, decimal amount = 500, bool secure3d = false, string currency = "USD")
        {
            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var initResponse       = installmentPlanApi.InstallmentPlanInitiate(new InitiateInstallmentPlanRequest()
            {
                PlanData = new PlanData(
                    amount: new MoneyWithCurrencyCode(amount, currency),
                    numberOfInstallments: options / 2,
                    attempt3DSecure: secure3d,
                    autoCapture: true),
                BillingAddress = new AddressData()
                {
                    AddressLine = "J. Street 23",
                    City        = "Birmingham",
                    Country     = "GB",
                    Zip         = "48993"
                },
                ConsumerData = new ConsumerData()
                {
                    Email = "john+" + DateTime.Now.Millisecond + "@gmail.com"                     // since john grabbed the @gmail, let him get some spam now and then :D
                },
                PaymentWizardData = new PaymentWizardData()
                {
                    RequestedNumberOfInstallments = string.Join(",", Enumerable.Range(1, options)),
                    IsOpenedInIframe = true
                }
            });

            return(View(new CommonTestModel()
            {
                PublicToken = initResponse.PublicToken,
                CheckoutUrl = initResponse.CheckoutUrl
            }));
        }
        public async Task <IActionResult> ProcessCombination(
            bool?attempt3DSecure = null,
            string pageFlow      = "single-page",
            int options          = 5,
            decimal amount       = 500,
            string currency      = "USD",
            string culture       = "en-US")
        {
            var loginApi = new LoginApi(this.FlexFieldsEnv);
            var request  = new LoginRequest(userName: SplititApiUsername, password: SplititApiPassword);

            var loginResult = await loginApi.LoginPostAsync(request);

            var installmentPlanApi = new InstallmentPlanApi(this.FlexFieldsEnv, sessionId: loginResult.SessionId);
            var initResponse       = installmentPlanApi.InstallmentPlanInitiate(new InitiateInstallmentPlanRequest()
            {
                PlanData = new PlanData(
                    amount: new MoneyWithCurrencyCode(amount, currency),
                    numberOfInstallments: options / 2,
                    attempt3DSecure: attempt3DSecure,
                    refOrderNumber: "r-" + DateTime.Now.Ticks.ToString(),
                    autoCapture: true),
                BillingAddress = new AddressData()
                {
                    AddressLine = "J. Street 23",
                    City        = "Birmingham",
                    Country     = "GB",
                    Zip         = "48993"
                },
                ConsumerData = new ConsumerData()
                {
                    FullName    = "Ivan Cesar Second",
                    CultureName = culture,
                    Email       = "john+" + DateTime.Now.Millisecond + "@gmail.com" // since john grabbed the @gmail, let him get some spam now and then :D
                },
                PaymentWizardData = new PaymentWizardData()
                {
                    RequestedNumberOfInstallments = string.Join(",", Enumerable.Range(1, options)),
                    Is3dSecureInPopup             = true
                }
            });

            if (pageFlow == "single-page")
            {
                return(View("SinglePage", new CommonTestModel()
                {
                    PublicToken = initResponse.PublicToken,
                    PlanNumber = initResponse.InstallmentPlan.InstallmentPlanNumber
                }));
            }
            else if (pageFlow == "multi-page")
            {
                return(View("MultiPage", new CommonTestModel()
                {
                    PublicToken = initResponse.PublicToken,
                    PlanNumber = initResponse.InstallmentPlan.InstallmentPlanNumber,
                    Culture = culture
                }));
            }

            return(RedirectToAction("Index", "Scenario"));
        }