/// <summary> /// Upserts the market place. /// </summary> /// <param name="marketPlace">The market place.</param> /// <param name="marketPlaceTypeId">The market place type identifier.</param> /// <returns>marketplace's id</returns> public Optional <int> UpsertMarketPlace(CustomerMarketPlace marketPlace, Guid marketPlaceTypeId) { var marketPlaceId = GetMarketPlaceIdFromTypeId(marketPlaceTypeId); if (!marketPlaceId.HasValue) { return(-1); } DateTime utcNow = DateTime.UtcNow; marketPlace.MarketPlaceId = marketPlaceId.GetValue(); marketPlace.Updated = utcNow; if (!marketPlace.Created.HasValue) { marketPlace.Created = utcNow; } var upsert = GetUpsertGenerator(marketPlace); upsert.WithTableName(mpCustomermarketplace) .WithMatchColumns(o => o.CustomerId, o => o.MarketPlaceId, o => o.DisplayName) .WithSkipColumns(o => o.Id) .WithUpdateColumnIfNull(o => o.Created) .WithOutputColumns(o => o.Id); using (var connection = GetOpenedSqlConnection2()) { using (var sqlCommand = upsert.Verify() .GenerateCommand()) { sqlCommand.Connection = connection.SqlConnection(); return(ExecuteScalarAndLog <int>(sqlCommand)); } } }
/// <summary> /// Handles the specified command. /// </summary> /// <param name="command">The command.</param> public void Handle(EbayRegisterCustomerCommand command) { //validates market place InfoAccumulator info = MarketPlaceQueries.ValidateCustomerMarketPlace(EbayInternalId, command.MarketplaceName); if (info.HasErrors) { SendReply(info, command); return; } int marketPlaceId = MarketPlaceQueries.GetMarketPlaceIdFromTypeId(EbayInternalId) .GetValue(); CustomerMarketPlace marketPlace = new CustomerMarketPlace { CustomerId = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId)), DisplayName = command.MarketplaceName, MarketPlaceId = marketPlaceId, SecurityData = SerializationUtils.SerializeToBinaryXml(new EbaySecurityInfo { Token = command.Token }) }; int marketPlaceTableId = GetIdIfValidOrThrowException(MarketPlaceQueries.UpsertMarketPlace(marketPlace, EbayInternalId), marketplaceUpsertFailed); var updateHistory = new CustomerMarketPlaceUpdateHistory() { CustomerMarketPlaceId = marketPlaceTableId, UpdatingStart = DateTime.UtcNow }; int marketPlaceHistoryId = GetIdIfValidOrThrowException(MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory) .Value, marketplaceHistoryUpsertFailed); var validateUserAccountCommand = new EbayValidationCommand(); validateUserAccountCommand.IsValidateUserAccount = true; validateUserAccountCommand.Token = command.Token; validateUserAccountCommand.PayLoad = new Dictionary <string, object> { { CustomerId, command.CustomerId }, { SessionId, command.SessionId }, { MarketplaceId, marketPlaceId }, { MarketPlaceUpdatingHistoryId, marketPlaceHistoryId } }; //sends command to validate user account //the response to this command is handled in this class by another handler method with appropriate response class SendCommand(ThirdPartyService.Address, validateUserAccountCommand, command); }
/// <summary> /// Creates the new market place. /// </summary> /// <param name="customerId">The customer identifier.</param> /// <param name="displayName">The display name.</param> /// <param name="securityData">The security data.</param> /// <param name="marketPlaceInternalId">The market place internal identifier.</param> /// <returns></returns> public Optional <int> CreateNewMarketPlace(int customerId, string displayName, byte[] securityData, Guid marketPlaceInternalId) { CustomerMarketPlace marketPlace = new CustomerMarketPlace { CustomerId = customerId, DisplayName = displayName, SecurityData = securityData }; return(UpsertMarketPlace(marketPlace, marketPlaceInternalId)); }
private static int UpsertMarketPlace(IContainer container, AmazonGetCustomerInfo3dPartyCommandResponse customerInfoResponse) { IMarketPlaceQueries marketPlaceQueries = container.GetInstance <IMarketPlaceQueries>(); int marketPlaceId = (int)marketPlaceQueries.GetMarketPlaceIdFromTypeId(amazonInternalId); CustomerMarketPlace marketPlace = new CustomerMarketPlace { CustomerId = 17171717, DisplayName = customerInfoResponse.BusinessName, MarketPlaceId = marketPlaceId, SecurityData = SerializationUtils.SerializeToBinaryXml(securityInfo), Created = DateTime.UtcNow }; int id = (int)marketPlaceQueries.UpsertMarketPlace(marketPlace, amazonInternalId); Assert.IsTrue(id > 0, "error upserting marketplace"); return(id); }
/// <summary> /// Handles the specified command. (Sent from REST endpoint) /// </summary> /// <param name="command">The command.</param> public async void Handle(PayPalRegisterCustomerCommand command) { var getAccessTokenCommand = new PayPalGetAccessToken3dPartyCommand { RequestToken = command.RequestToken, VerificationCode = command.VerificationToken, }; //get access token var accessTokenResponse = await GetAccessTokenSendReceive.SendAsync(ThirdPartyServiceConfig.Address, getAccessTokenCommand); var getPersonalDataCommand = new PayPalGetCustomerPersonalData3dPartyCommand { TokenSecret = accessTokenResponse.TokenSecret, Token = accessTokenResponse.Token }; //get account info var personalDataResponse = await GetCustomerPersonalDataSendReceive.SendAsync(ThirdPartyServiceConfig.Address, getPersonalDataCommand); InfoAccumulator info = new InfoAccumulator(); //validates market place if (!MarketPlaceQueries.IsMarketPlaceInWhiteList(PayPalInternalId, personalDataResponse.UserPersonalInfo.EMail)) { if (MarketPlaceQueries.IsMarketPlaceExists(PayPalInternalId, personalDataResponse.UserPersonalInfo.EMail)) { string msg = string.Format("the market place with already exists"); info.AddError(msg); SendReply(info, command); return; } } int marketPlaceId = MarketPlaceQueries.GetMarketPlaceIdFromTypeId(PayPalInternalId) .GetValue(); CustomerMarketPlace marketPlace = new CustomerMarketPlace { CustomerId = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId)), DisplayName = personalDataResponse.UserPersonalInfo.EMail, MarketPlaceId = marketPlaceId, SecurityData = SerializationUtils.SerializeToBinaryXml(new PayPalSecurityInfo { TokenSecret = accessTokenResponse.TokenSecret, AccessToken = accessTokenResponse.Token, VerificationCode = command.RequestToken, RequestToken = command.RequestToken, UserId = personalDataResponse.UserPersonalInfo.EMail }) }; int marketPlaceTableId = (int)MarketPlaceQueries.UpsertMarketPlace(marketPlace, PayPalInternalId); personalDataResponse.UserPersonalInfo.CustomerMarketPlaceId = marketPlaceId; var updateHistory = new CustomerMarketPlaceUpdateHistory { CustomerMarketPlaceId = marketPlaceTableId, UpdatingStart = DateTime.UtcNow }; int marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory); PayPalQueries.SavePersonalInfo(personalDataResponse.UserPersonalInfo); DateTime startDate; var lastTransactionTime = PayPalQueries.GetLastTransactionDate(marketPlaceTableId); if (!lastTransactionTime.HasValue) { startDate = DateTime.UtcNow.AddMonths(-Config.TransactionSearchMonthsBack); } else { startDate = (DateTime)lastTransactionTime; } var getTransactionsCommand = new PayPalGetTransations3dPartyCommand { AccessToken = accessTokenResponse.Token, AccessTokenSecret = accessTokenResponse.TokenSecret, UtcDateFrom = startDate, UtcDateTo = DateTime.UtcNow }; var response = await GetTransactionsSendReceive.SendAsync(ThirdPartyServiceConfig.Address, getTransactionsCommand); SaveTransactions(response.Transactions, marketPlaceTableId, marketPlaceHistoryId); updateHistory = new CustomerMarketPlaceUpdateHistory { CustomerMarketPlaceId = marketPlaceTableId, UpdatingEnd = DateTime.UtcNow }; marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory); if (marketPlaceTableId < 1) { throw new InvalidOperationException("could not save market place history update"); } }