/// <summary>
        /// Handles the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        public async void Handle(PayPalGetCustomerPersonalData3dPartyCommand command)
        {
            GetAdvancedPersonalDataResponse personalData = await PayPalService.GetPersonalData(command.Token, command.TokenSecret);

            var personalInfo = GetUserPersonalInfo(personalData.response);

            InfoAccumulator info = new InfoAccumulator();

            SendReply(info, command, resp => resp.UserPersonalInfo = personalInfo);
        }
Ejemplo n.º 2
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");
            }
        }