示例#1
0
        public async Task <string> Register([FromBody] CustomerViewModel customerViewModel)
        {
            if (!ModelState.IsValid)
            {
                List <string> errorList = (from item in ModelState.Values
                                           from error in item.Errors
                                           select error.ErrorMessage).ToList();
                string errorMessage = JsonConvert.SerializeObject(errorList);
                throw new PartnerDomainException(ErrorCode.InvalidInput).AddDetail("ErrorMessage", errorMessage);
            }

            // TODO :: Loc. may need special handling for national clouds deployments (China).
            string domainName = string.Format(CultureInfo.InvariantCulture, "{0}.onmicrosoft.com", customerViewModel.DomainPrefix);

            // check domain available.

            bool isDomainTaken = await ApplicationDomain.Instance.PartnerCenterClient.Domains.ByDomain(domainName).ExistsAsync().ConfigureAwait(false);

            if (isDomainTaken)
            {
                throw new PartnerDomainException(ErrorCode.DomainNotAvailable).AddDetail("DomainPrefix", domainName);
            }

            // get the locale, we default to the first locale used in a country for now.
            PartnerCenter.Models.CountryValidationRules.CountryValidationRules customerCountryValidationRules = await ApplicationDomain.Instance.PartnerCenterClient.CountryValidationRules.ByCountry(customerViewModel.Country).GetAsync().ConfigureAwait(false);

            string billingCulture  = customerCountryValidationRules.SupportedCulturesList.FirstOrDefault();     // default billing culture is the first supported culture for the customer's selected country.
            string billingLanguage = customerCountryValidationRules.SupportedLanguagesList.FirstOrDefault();    // default billing culture is the first supported language for the customer's selected country.

            CustomerViewModel customerRegistrationInfoToPersist = new CustomerViewModel()
            {
                AddressLine1    = customerViewModel.AddressLine1,
                AddressLine2    = customerViewModel.AddressLine2,
                City            = customerViewModel.City,
                State           = customerViewModel.State,
                ZipCode         = customerViewModel.ZipCode,
                Country         = customerViewModel.Country,
                Phone           = customerViewModel.Phone,
                Language        = customerViewModel.Language,
                FirstName       = customerViewModel.FirstName,
                LastName        = customerViewModel.LastName,
                Email           = customerViewModel.Email,
                CompanyName     = customerViewModel.CompanyName,
                MicrosoftId     = Guid.NewGuid().ToString(),
                UserName        = customerViewModel.Email,
                BillingLanguage = billingLanguage,
                BillingCulture  = billingCulture,
                DomainName      = domainName,
                DomainPrefix    = customerViewModel.DomainPrefix
            };

            CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance);
            CustomerViewModel customerRegistrationInfo = await customerRegistrationRepository.AddAsync(customerRegistrationInfoToPersist).ConfigureAwait(false);

            return(customerRegistrationInfo.MicrosoftId);
        }
示例#2
0
        /// <summary>
        /// prepares Remote post by populate all the necessary fields to generate PayUMoney post request.
        /// </summary>
        /// <param name="order">order details.</param>
        /// <param name="returnUrl">return url.</param>
        /// <returns>return remote post.</returns>
        private async Task <RemotePost> PrepareRemotePost(OrderViewModel order, string returnUrl)
        {
            string fname = string.Empty;
            string phone = string.Empty;
            string email = string.Empty;
            CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance);
            CustomerViewModel customerRegistrationInfo = await customerRegistrationRepository.RetrieveAsync(order.CustomerId);

            fname = customerRegistrationInfo.FirstName;
            phone = customerRegistrationInfo.Phone;
            email = customerRegistrationInfo.Email;

            decimal       paymentTotal = 0;
            StringBuilder productSubs  = new StringBuilder();
            StringBuilder prodQuants   = new StringBuilder();

            foreach (var subscriptionItem in order.Subscriptions)
            {
                productSubs.Append(":").Append(subscriptionItem.SubscriptionId);
                prodQuants.Append(":").Append(subscriptionItem.Quantity.ToString());
                paymentTotal += Math.Round(subscriptionItem.Quantity * subscriptionItem.SeatPrice, Resources.Culture.NumberFormat.CurrencyDecimalDigits);
            }

            productSubs.Remove(0, 1);
            prodQuants.Remove(0, 1);
            System.Collections.Specialized.NameValueCollection inputs = new System.Collections.Specialized.NameValueCollection();
            PaymentConfiguration payconfig = await this.GetAPaymentConfigAsync();

            inputs.Add("key", payconfig.ClientId);
            inputs.Add("txnid", this.GenerateTransactionId());
            inputs.Add("amount", paymentTotal.ToString());
            inputs.Add("productinfo", productSubs.ToString());
            inputs.Add("firstname", fname);
            inputs.Add("phone", phone);
            inputs.Add("email", email);
            inputs.Add("udf1", order.OperationType.ToString());
            inputs.Add("udf2", prodQuants.ToString());
            inputs.Add("surl", returnUrl + "&payment=success&PayerId=" + inputs.Get("txnid"));
            inputs.Add("furl", returnUrl + "&payment=failure&PayerId=" + inputs.Get("txnid"));
            inputs.Add("service_provider", Constant.PAYUPAISASERVICEPROVIDER);
            string hashString = inputs.Get("key") + "|" + inputs.Get("txnid") + "|" + inputs.Get("amount") + "|" + inputs.Get("productInfo") + "|" + inputs.Get("firstName") + "|" + inputs.Get("email") + "|" + inputs.Get("udf1") + "|" + inputs.Get("udf2") + "|||||||||" + payconfig.ClientSecret; // payconfig.ClientSecret;
            string hash       = this.GenerateHash512(hashString);

            inputs.Add("hash", hash);

            RemotePost myremotepost = new RemotePost();

            myremotepost.SetUrl(this.GetPaymentUrl(payconfig.AccountType));
            myremotepost.SetInputs(inputs);
            return(myremotepost);
        }
        public async Task <SubscriptionsSummary> ProcessOrderForUnAuthenticatedCustomer(string customerId, string paymentId, string payerId)
        {
            var startTime = DateTime.Now;

            customerId.AssertNotEmpty(nameof(customerId));

            paymentId.AssertNotEmpty(nameof(paymentId));
            payerId.AssertNotEmpty(nameof(payerId));

            // Retrieve customer registration details persisted
            CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance);

            CustomerViewModel customerRegistrationInfoPersisted = await ApplicationDomain.Instance.CustomerRegistrationRepository.RetrieveAsync(customerId);

            var newCustomer = new Customer()
            {
                CompanyProfile = new CustomerCompanyProfile()
                {
                    Domain = customerRegistrationInfoPersisted.DomainName,
                },
                BillingProfile = new CustomerBillingProfile()
                {
                    Culture     = customerRegistrationInfoPersisted.BillingCulture,
                    Language    = customerRegistrationInfoPersisted.BillingLanguage,
                    Email       = customerRegistrationInfoPersisted.Email,
                    CompanyName = customerRegistrationInfoPersisted.CompanyName,

                    DefaultAddress = new Address()
                    {
                        FirstName    = customerRegistrationInfoPersisted.FirstName,
                        LastName     = customerRegistrationInfoPersisted.LastName,
                        AddressLine1 = customerRegistrationInfoPersisted.AddressLine1,
                        AddressLine2 = customerRegistrationInfoPersisted.AddressLine2,
                        City         = customerRegistrationInfoPersisted.City,
                        State        = customerRegistrationInfoPersisted.State,
                        Country      = customerRegistrationInfoPersisted.Country,
                        PostalCode   = customerRegistrationInfoPersisted.ZipCode,
                        PhoneNumber  = customerRegistrationInfoPersisted.Phone,
                    }
                }
            };

            // Register customer
            newCustomer = await ApplicationDomain.Instance.PartnerCenterClient.Customers.CreateAsync(newCustomer);

            var newCustomerId = newCustomer.CompanyProfile.TenantId;

            CustomerViewModel customerViewModel = new CustomerViewModel()
            {
                AddressLine1     = newCustomer.BillingProfile.DefaultAddress.AddressLine1,
                AddressLine2     = newCustomer.BillingProfile.DefaultAddress.AddressLine2,
                City             = newCustomer.BillingProfile.DefaultAddress.City,
                State            = newCustomer.BillingProfile.DefaultAddress.State,
                ZipCode          = newCustomer.BillingProfile.DefaultAddress.PostalCode,
                Country          = newCustomer.BillingProfile.DefaultAddress.Country,
                Phone            = newCustomer.BillingProfile.DefaultAddress.PhoneNumber,
                Language         = newCustomer.BillingProfile.Language,
                FirstName        = newCustomer.BillingProfile.DefaultAddress.FirstName,
                LastName         = newCustomer.BillingProfile.DefaultAddress.LastName,
                Email            = newCustomer.BillingProfile.Email,
                CompanyName      = newCustomer.BillingProfile.CompanyName,
                MicrosoftId      = newCustomer.CompanyProfile.TenantId,
                UserName         = newCustomer.BillingProfile.Email,
                Password         = newCustomer.UserCredentials.Password,
                AdminUserAccount = newCustomer.UserCredentials.UserName + "@" + newCustomer.CompanyProfile.Domain
            };

            IPaymentGateway paymentGateway = PaymentGatewayConfig.GetPaymentGatewayInstance(ApplicationDomain.Instance, "ProcessingOrder");
            OrderViewModel  orderToProcess = await paymentGateway.GetOrderDetailsFromPaymentAsync(payerId, paymentId, string.Empty, string.Empty);

            // Assign the actual customer Id
            orderToProcess.CustomerId = newCustomerId;

            CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, newCustomerId, paymentGateway);
            await commerceOperation.PurchaseAsync(orderToProcess);

            SubscriptionsSummary summaryResult = await this.GetSubscriptionSummaryAsync(newCustomerId);

            // Remove the persisted customer registration info.
            var deleteResult = ApplicationDomain.Instance.CustomerRegistrationRepository.DeleteAsync(customerId);

            // Capture the request for the customer summary for analysis.
            var eventProperties = new Dictionary <string, string> {
                { "CustomerId", orderToProcess.CustomerId }
            };

            // Track the event measurements for analysis.
            var eventMetrics = new Dictionary <string, double> {
                { "ElapsedMilliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds }
            };

            ApplicationDomain.Instance.TelemetryService.Provider.TrackEvent("api/order/NewCustomerProcessOrder", eventProperties, eventMetrics);

            summaryResult.CustomerViewModel = customerViewModel;

            return(summaryResult);
        }