Exemplo n.º 1
0
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(HmrcRegisterCustomerCommand command)
        {
            InfoAccumulator info = Validate(command);

            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            info = MarketPlaceQueries.ValidateCustomerMarketPlace(HmrcInternalId, command.UserName);
            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            int          customerId       = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId));
            AccountModel hmrcAccountModel = new AccountModel
            {
                login    = command.UserName,
                password = command.Password
            };

            byte[] securityData = SerializationUtils.SerializeToBinaryXml(hmrcAccountModel);
            securityData = EncryptionUtils.Encrypt(securityData);

            int marketplaceId = (int)MarketPlaceQueries.CreateNewMarketPlace(customerId, command.UserName, securityData, HmrcInternalId);

            if (marketplaceId < 1)
            {
                string msg = string.Format("could not create marketplace for customer {0}", command.CustomerId); //writes encrypted customer id
                Log.Error(msg);
                throw new Exception(msg);
            }

            var updateHistory = new CustomerMarketPlaceUpdateHistory()
            {
                CustomerMarketPlaceId = marketplaceId,
                UpdatingStart         = DateTime.UtcNow
            };

            int marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory);

            if (marketPlaceHistoryId < 1)
            {
                string message = string.Format("could not upsert marketplace history for customer: {0}", command.CustomerId);
                Log.Error(message);
                throw new Exception(message);
            }

            HmrcGetVatReturns3dPartyCommand commandToSend = new HmrcGetVatReturns3dPartyCommand {
                UserName   = command.UserName,
                Password   = command.Password,
                CustomerId = command.CustomerId
            };

            SendCommand(ThirdPartyServiceConfig.Address, commandToSend, command);
        }
        /// <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);
        }
Exemplo n.º 3
0
        private static int UpsertMarketplaceHistoryUpdate(IContainer container, int marketPlaceTableId)
        {
            var updateHistory = new CustomerMarketPlaceUpdateHistory {
                CustomerMarketPlaceId = marketPlaceTableId,
                UpdatingStart         = DateTime.UtcNow
            };

            int id = (int)container.GetInstance <IMarketPlaceQueries>()
                     .UpsertMarketPlaceUpdatingHistory(updateHistory);

            Assert.True(id > 0, "invalid marketplace history id");
            return(id);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(HmrcGetVatReturns3dPartyCommandResponse command)
        {
            InfoAccumulator info = MarketPlaceQueries.ValidateCustomerMarketPlace(HmrcInternalId, command.UserName);

            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            int          customerId       = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId));
            AccountModel hmrcAccountModel = new AccountModel {
                login    = command.UserName,
                password = command.Password
            };

            byte[] securityData = SerializationUtils.SerializeToBinaryXml(hmrcAccountModel);
            securityData = EncryptionUtils.Encrypt(securityData);

            int marketplaceId = (int)MarketPlaceQueries.CreateNewMarketPlace(customerId, command.UserName, securityData, HmrcInternalId);

            if (marketplaceId < 1)
            {
                string msg = string.Format("could not create marketplace for customer {0}", command.CustomerId); //writes encrypted customer id
                Log.Error(msg);
                throw new Exception(msg);
            }

            var updateHistory = new CustomerMarketPlaceUpdateHistory()
            {
                CustomerMarketPlaceId = marketplaceId,
                UpdatingStart         = DateTime.UtcNow
            };

            int marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory);

            if (marketPlaceHistoryId < 1)
            {
                throw new Exception("could not save marketplace history");
            }

            bool res = HmrcQueries.SaveVatReturns(command.VatReturnsPerBusiness, command.RtiMonthEntries, marketplaceId, marketPlaceHistoryId);

            if (!res)
            {
                throw new Exception("could not save vat returns");
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Upserts the market place updating updateHistory.
        /// </summary>
        /// <param name="updateHistory">The updateHistory.</param>
        /// <returns></returns>
        public Optional <int> UpsertMarketPlaceUpdatingHistory(CustomerMarketPlaceUpdateHistory updateHistory)
        {
            using (var connection = GetOpenedSqlConnection2()) {
                var upsert = GetUpsertGenerator(updateHistory)
                             .WithTableName("MP_CustomerMarketPlaceUpdatingHistory")
                             .WithMatchColumns(o => o.UpdatingStart, o => o.CustomerMarketPlaceId)
                             .WithConnection(connection.SqlConnection())
                             .WithSkipColumns(o => o.Id, o => o.UpdatingTimePassInSeconds)
                             .WithUpdateColumnIfNull(o => o.UpdatingStart)
                             .WithOutputColumns(o => o.Id);

                using (var sqlCommand = upsert.Verify()
                                        .GenerateCommand()) {
                    return(ExecuteScalarAndLog <int>(sqlCommand));
                }
            }
        }
        /// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public void Handle(HmrcProcessUploadedFilesCommand command)
        {
            InfoAccumulator info = Validate(command);

            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            var vatReturns = ParseVatReturns(command.Files, info);

            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            int      customerId = int.Parse(EncryptionUtils.SafeDecrypt(command.CustomerId));
            Customer customer   = CustomerQueries.GetCustomerById(customerId);

            info = MarketPlaceQueries.ValidateCustomerMarketPlace(HmrcInternalId, customer.Name);
            if (info.HasErrors)
            {
                SendReply(info, command);
                return;
            }

            AccountModel hmrcAccountModel = new AccountModel {
            };                                                   //TODO check it out what to put here


            byte[] securityData = SerializationUtils.SerializeToBinaryXml(hmrcAccountModel);
            securityData = EncryptionUtils.Encrypt(securityData);

            int marketplaceId = (int)MarketPlaceQueries.CreateNewMarketPlace(customerId, customer.Name, securityData, HmrcInternalId);

            if (marketplaceId < 1)
            {
                string msg = string.Format("could not create marketplace for customer {0}", command.CustomerId); //writes encrypted customer id
                Log.Error(msg);
                throw new Exception(msg);
            }

            var updateHistory = new CustomerMarketPlaceUpdateHistory()
            {
                CustomerMarketPlaceId = marketplaceId,
                UpdatingStart         = DateTime.UtcNow
            };

            int marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory);

            if (marketPlaceHistoryId < 1)
            {
                string message = string.Format("could not upsert marketplace history for customer: {0}", command.CustomerId);
                Log.Error(message);
                throw new Exception(message);
            }


            bool res = HmrcQueries.SaveVatReturns(vatReturns, null, marketplaceId, marketPlaceHistoryId);

            if (!res)
            {
                throw new Exception("could not save vat returns");
            }

            updateHistory = new CustomerMarketPlaceUpdateHistory()
            {
                CustomerMarketPlaceId = marketplaceId,
                UpdatingEnd           = DateTime.UtcNow
            };

            marketPlaceHistoryId = (int)MarketPlaceQueries.UpsertMarketPlaceUpdatingHistory(updateHistory);
            if (marketPlaceHistoryId < 1)
            {
                throw new Exception("could not save marketplace history");
            }

            SendReply(info, command);
        }
Exemplo n.º 7
0
        /// <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");
            }
        }