private IDatabaseCustomerMarketPlace SaveSage(SageServiceInfo oEsi, AccessTokenContainer accessTokenContainer, string approvalToken)
        {
            IDatabaseCustomerMarketPlace oResult = null;

            Transactional.Execute(() => {
                int marketPlaceId = _mpTypes
                                    .GetAll()
                                    .First(a => a.InternalId == oEsi.InternalId)
                                    .Id;

                var securityData = new SageSecurityInfo {
                    ApprovalToken = approvalToken,
                    AccessToken   = accessTokenContainer.access_token,
                    TokenType     = accessTokenContainer.token_type,
                    MarketplaceId = marketPlaceId
                };

                var sageDatabaseMarketPlace = new SageDatabaseMarketPlace();

                string accountName = string.Format("SageOne Account #{0}",
                                                   _customer.CustomerMarketPlaces.Count(a => a.Marketplace.InternalId == oEsi.InternalId) + 1
                                                   );

                log.Info("Saving sage marketplace data...");
                var marketPlace = _helper.SaveOrUpdateCustomerMarketplace(accountName, sageDatabaseMarketPlace, securityData, _customer);
                log.Info("Saved sage marketplace data.");

                oResult = marketPlace;
            });

            return(oResult);
        }
Esempio n. 2
0
        }         // PayPointCallback

        private void DoApplyForLoan()
        {
            Customer customer = m_oContext.Customer;

            ms_oLog.Debug("Customer {0} applied for a loan, processing...", customer.Stringify());

            Transactional.Execute(() => {
                customer.CreditResult = null;

                customer.OfferStart      = DateTime.UtcNow;
                customer.OfferValidUntil = DateTime.UtcNow.AddHours(CurrentValues.Instance.OfferValidForHours);

                customer.ApplyCount++;

                if (customer.LastCashRequest != null && customer.LastCashRequest.HasLoans)
                {
                    m_oServiceClient.Instance.RequestCashWithoutTakenLoan(customer.Id);
                }

                m_oSession.Flush();
            });

            new MainStrategyClient(
                customer.Id,
                customer.Id,
                customer.IsAvoid,
                NewCreditLineOption.UpdateEverythingAndApplyAutoRules,
                null,
                CashRequestOriginator.RequestCashBtn
                ).ExecuteAsync();

            ms_oLog.Debug("Customer {0} applied for a loan, processing complete.", customer.Stringify());
        }         // DoApplyForLoan
Esempio n. 3
0
        public JsonResult Vip(VipModel model)
        {
            var customer = this.context.Customer;

            Transactional.Execute(() => {
                var vip = new VipRequest {
                    Customer    = customer,
                    Email       = model.VipEmail,
                    FullName    = model.VipFullName,
                    Ip          = Request.ServerVariables["REMOTE_ADDR"],
                    Phone       = model.VipPhone,
                    RequestDate = DateTime.UtcNow
                };
                this.vipRequestRepository.SaveOrUpdate(vip);


                if (customer != null)
                {
                    customer.Vip = true;
                }
            });

            var c = new ServiceClient();

            c.Instance.VipRequest(customer != null ? customer.Id : 0, model.VipFullName, model.VipEmail, model.VipPhone);
            return(Json(new {}));
        }         // Vip
        public ViewResult Success(string request_token, string verification_code)
        {
            Log.InfoFormat("PayPal Add callback, token:{0} verification code:{1}", request_token, verification_code);

            if (string.IsNullOrEmpty(verification_code) && string.IsNullOrEmpty(request_token))
            {
                Log.InfoFormat("PayPal adding was canceled by customer");
                return(View("PayPalCanceled"));
            }

            var paypal = ObjectFactory.GetInstance <PayPalDatabaseMarketPlace>();

            var customer = this.context.Customer;

            PayPalPermissionsGranted permissionsGranted;
            PayPalPersonalData       personalData;

            try
            {
                permissionsGranted = PayPalServiceHelper.GetAccessToken(request_token, verification_code);
                personalData       = PayPalServiceHelper.GetAccountInfo(permissionsGranted);
                this.mpChecker.Check(paypal.InternalId, customer, personalData.Email);
            }
            catch (PayPalException e)
            {
                Log.Warn(e);
                return(View("Error", (object)string.Join("<br />", e.ErrorDetails.Select(x => x.message).ToList())));
            }
            catch (MarketPlaceAddedByThisCustomerException)
            {
                return(View("Error", (object)DbStrings.PayPalAddedByYou));
            }
            catch (MarketPlaceIsAlreadyAddedException)
            {
                return(View("Error", (object)DbStrings.AccountAlreadyExixtsInDb));
            }

            int mpId = 0;

            Transactional.Execute(() => {
                mpId = SavePayPal(customer, permissionsGranted, personalData, paypal);
            });

            if (mpId > 0)
            {
                this.serviceClient.Instance.UpdateMarketplace(customer.Id, mpId, true, this.context.UserId);
            }

            return(View(permissionsGranted));
        }
Esempio n. 5
0
        }         // FreeAgentCallback

        private FreeAgentAccountModel SaveFreeAgentTrn(AccessTokenContainer accessTokenContainer, string approvalToken)
        {
            FreeAgentAccountModel oResult = null;

            Transactional.Execute(() => {
                var oEsi = new FreeAgentServiceInfo();

                int marketPlaceId = this.mpTypesRepo
                                    .GetAll()
                                    .First(a => a.InternalId == oEsi.InternalId)
                                    .Id;

                log.Info("Fetching company data for customer {0}...", this.customer.Name);
                FreeAgentCompany freeAgentCompany = null;

                try {
                    freeAgentCompany = this.connector.GetCompany(accessTokenContainer.access_token);
                } catch (Exception ex) {
                    log.Error(ex, "Error getting FreeAgent's company. Will use customer mail as the account display name.");
                }                 // try

                var securityData = new FreeAgentSecurityInfo {
                    ApprovalToken = approvalToken,
                    AccessToken   = accessTokenContainer.access_token,
                    ExpiresIn     = accessTokenContainer.expires_in,
                    TokenType     = accessTokenContainer.token_type,
                    RefreshToken  = accessTokenContainer.refresh_token,
                    MarketplaceId = marketPlaceId,
                    Name          = freeAgentCompany != null ? freeAgentCompany.name : this.customer.Name,
                    ValidUntil    = DateTime.UtcNow.AddSeconds(accessTokenContainer.expires_in - 60)
                };

                var freeAgentDatabaseMarketPlace = new FreeAgentDatabaseMarketPlace();

                log.Info("Saving marketplace data...");
                var marketPlace = this.dbHelper.SaveOrUpdateCustomerMarketplace(
                    securityData.Name,
                    freeAgentDatabaseMarketPlace,
                    securityData,
                    this.customer
                    );

                oResult = FreeAgentAccountModel.ToModel(marketPlace);
            });

            return(oResult);
        }         // SaveFreeAgentTrn
Esempio n. 6
0
        public JsonResult Update(string name, string password)
        {
            string errorMsg;

            if (!_validator.Validate(name, password, out errorMsg))
            {
                var errorObject = new { error = errorMsg };
                return(Json(errorObject));
            }             // if

            try {
                Transactional.Execute(() => {
                    var customer = _context.Customer;
                    var ekm      = new EkmDatabaseMarketPlace();
                    _helper.SaveOrUpdateCustomerMarketplace(name, ekm, password, customer);
                });

                return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e) {
                Log.Error(e);
                return(Json(new { error = e.Message }, JsonRequestBehavior.AllowGet));
            } // try
        }     // Update