コード例 #1
0
        /// <summary>
        /// Validates the card details for given creditcard details control.
        /// </summary>
        /// <param name="ucCreditCardDetails">The credit card details control.</param>
        /// <returns>Is valid credit card.</returns>
        private bool ValidateCardDetails(CreditCardDetails ucCreditCardDetails)
        {
            FatZebra.Gateway.Username    = Utils.GetSystemValue("PaymentGatewayUsername");
            FatZebra.Gateway.Token       = Utils.GetSystemValue("PaymentGatewayToken");
            FatZebra.Gateway.SandboxMode = Convert.ToBoolean(Utils.GetSystemValue("PaymentGatewaySandboxMode"));
            FatZebra.Gateway.TestMode    = Convert.ToBoolean(Utils.GetSystemValue("PaymentGatewayTestMode"));

            //Get the first day of the month
            DateTime monthwithFirstday = new DateTime(ucCreditCardDetails.SelectedYear, ucCreditCardDetails.SelectedMonth, 1);
            //Add a month a reduce one date to get the last day of the month
            DateTime monthWithLastday = monthwithFirstday.AddMonths(1).AddDays(-1).Date;

            if (monthWithLastday < Today)
            {
                ucCreditCardDetails.SetNotificationDates();
                popupConfirmPaymentDetails.ShowPopup();
                Response = null;
                return(false);
            }

            Response = CreditCard.Create(ucCreditCardDetails.CreditCardHolderName, ucCreditCardDetails.CreditCardNumber, monthWithLastday, ucCreditCardDetails.CVVNumber);
            return(Response.Successful);
        }
コード例 #2
0
        /// <summary>
        /// Saves the creadit fatzibra card token.
        /// </summary>
        /// <param name="ucCreditCardDetails">The credit card details control.</param>
        /// <param name="commit">if set to <c>true</c> [commit to database].</param>
        private void SaveCreaditCardToken(CreditCardDetails ucCreditCardDetails, bool commit)
        {
            // If credit card not validated
            if (Response == null)
            {
                ValidateCardDetails(ucCreditCardDetails);
            }

            if (Response != null && Response.Successful)
            {
                #region Update existing token details if available

                CreditCardToken creditCardToken = GetCreditCardToken();
                if (creditCardToken != null)
                {
                    creditCardToken.IsActive        = false;
                    creditCardToken.LastUpdatedBy   = UserID;
                    creditCardToken.LastUpdatedDate = Now;
                }

                #endregion Update existing token details if available

                #region Add New token details

                CreditCardToken newCreditCardToken = new CreditCardToken();
                newCreditCardToken.Token            = Utils.EncryptStringAES(Response.Result.ID);
                newCreditCardToken.CreatedBy        = UserID;
                newCreditCardToken.LastUpdatedBy    = UserID;
                newCreditCardToken.LastUpdatedDate  = Now;
                newCreditCardToken.CreatedDate      = Now;
                newCreditCardToken.IsActive         = true;
                newCreditCardToken.RelatedTableName = RelatedTable;
                newCreditCardToken.RelatedId        = CompanyId;
                creditCardNumber = ucCreditCardDetails.CreditCardNumber;
                newCreditCardToken.LastFourDigitsCreditCardNumber = Utils.EncryptStringAES(creditCardNumber.Substring(creditCardNumber.Length - 4));
                DataContext.CreditCardTokens.AddObject(newCreditCardToken);

                #endregion Add New token details

                #region Check the company status and reactivate it

                var company = GetBL <CompanyBL>().GetCompany(CompanyId);
                if (company != null)
                {
                    CompanyStatusHandler.CompanyWarningInfo warningInfo = CompanyStatusHandler.GetCompanyWarningStatus(CompanyId, company.CompanyStatusCodeId, company.ExpirationDate);
                    if (warningInfo.WarningStatus == CompanyStatusHandler.CompanyWarningStatus.SuspendedForNoPaymentOptions)
                    {
                        CompanyPaymentPackage companyPaymentPackage = GetBL <FinanceBL>().GetCurrentPaymentPackageFortheCompanyIncludingFreeTrial(company.CompanyId);
                        companyPaymentPackage.PaymentMethodCodeId = Support.GetCodeIdByCodeValue("PaymentMethod", "CREDITCARD");
                        company.CompanyStatusCodeId = Support.GetCodeIdByCodeValue("CompanyStatus", "ACTIVE");

                        //update if there is summary for the period
                        CompanyPaymentSummary companyPaymentSummary = this.GetBL <FinanceBL>().GetPaymentSummaryToShouldProcess(company.CompanyId);
                        if (companyPaymentSummary != null)
                        {
                            companyPaymentSummary.ShouldProcess = true;
                        }
                    }
                }

                #endregion Check the company status and reactivate it

                if (commit)
                {
                    DataContext.SaveChanges();
                }

                ucCreditCardDetails.ClearValues();

                if (DisplayMode == ViewMode.CompanyBilling)
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "HideDiv", "HidePaymentSuccessMessage();", true);
                }

                popupConfirmPaymentDetails.HidePopup();
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                if (Response != null && Response.Errors.Count > 0)
                {
                    sb.Append(string.Join("<br />", Response.Errors));
                    ucCreditCardDetails.SetNotification(sb.ToString().Length == 0 ? "Failed to set up payment details. Please verify the payment details and retry" : sb.ToString());
                }

                popupConfirmPaymentDetails.ShowPopup();
            }
        }