public async Task <string> PrepareOrderForUnAuthenticatedCustomer([FromBody] OrderViewModel orderDetails) { var startTime = DateTime.Now; if (!ModelState.IsValid) { var 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); } // Validate & Normalize the order information. OrderNormalizer orderNormalizer = new OrderNormalizer(ApplicationDomain.Instance, orderDetails); orderDetails = await orderNormalizer.NormalizePurchaseSubscriptionOrderAsync(); // prepare the redirect url so that client can redirect to PayPal. string redirectUrl = string.Format(CultureInfo.InvariantCulture, "{0}/#ProcessOrder?ret=true&customerId={1}", Request.RequestUri.GetLeftPart(UriPartial.Authority), orderDetails.CustomerId); // execute to paypal and get paypal action URI. PayPalGateway paymentGateway = new PayPalGateway(ApplicationDomain.Instance, Resources.NewPurchaseOperationCaption); string generatedUri = await paymentGateway.GeneratePaymentUriAsync(redirectUrl, orderDetails); // 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/NewCustomerPrepareOrder", null, eventMetrics); return(generatedUri); }
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)); PayPalGateway paymentGateway = new PayPalGateway(ApplicationDomain.Instance, "ProcessingOrder"); // use payment gateway to extract order information. OrderViewModel orderToProcess = await paymentGateway.GetOrderDetailsFromPaymentAsync(payerId, paymentId, string.Empty, string.Empty); CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, customerId, paymentGateway); await commerceOperation.PurchaseAsync(orderToProcess); SubscriptionsSummary summaryResult = await this.GetSubscriptionSummaryAsync(customerId); // Capture the request for the customer summary for analysis. var eventProperties = new Dictionary <string, string> { { "CustomerId", orderToProcess.CustomerId }, { "PayerId", payerId }, { "PaymentId", paymentId } }; // 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); return(summaryResult); }
public async Task <TransactionResult> UpdateSubscription([FromBody] OrderViewModel orderUpdateInformation) { if (!ModelState.IsValid) { var 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); } string clientCustomerId = this.Principal.PartnerCenterCustomerId; orderUpdateInformation.Subscriptions.AssertNotNull(nameof(orderUpdateInformation.Subscriptions)); List <OrderSubscriptionItemViewModel> orderSubscriptions = orderUpdateInformation.Subscriptions.ToList(); if (!(orderSubscriptions.Count == 1)) { throw new PartnerDomainException(ErrorCode.InvalidInput).AddDetail("ErrorMessage", Resources.MoreThanOneSubscriptionUpdateErrorMessage); } string subscriptionId = orderSubscriptions.First().SubscriptionId; int additionalSeats = orderSubscriptions.First().Quantity; subscriptionId.AssertNotEmpty(nameof(subscriptionId)); // required for commerce operation. additionalSeats.AssertPositive(nameof(additionalSeats)); // required & should be greater than 0. string operationDescription = string.Format("Customer Id:[{0}] - Added to subscription:{1}.", clientCustomerId, subscriptionId); PayPalGateway paymentGateway = new PayPalGateway(ApplicationDomain.Instance, orderUpdateInformation.CreditCard, operationDescription); CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, clientCustomerId, paymentGateway); return(await commerceOperation.PurchaseAdditionalSeatsAsync(subscriptionId, additionalSeats)); }
public async Task <PaymentConfiguration> UpdatePaymentConfiguration(PaymentConfiguration paymentConfiguration) { // validate the payment configuration before saving. PayPalGateway.ValidateConfiguration(paymentConfiguration); PaymentConfiguration paymentConfig = await ApplicationDomain.Instance.PaymentConfigurationRepository.UpdateAsync(paymentConfiguration); return(paymentConfig); }
public async Task <PaymentConfiguration> UpdatePaymentConfiguration(PaymentConfiguration paymentConfiguration) { // validate the payment configuration before saving. PayPalGateway.ValidateConfiguration(paymentConfiguration); // check if branding configuration has been setup else don't create web experience profile. bool isBrandingConfigured = await ApplicationDomain.Instance.PortalBranding.IsConfiguredAsync(); if (isBrandingConfigured) { // create a web experience profile using the branding for the web store. BrandingConfiguration brandConfig = await ApplicationDomain.Instance.PortalBranding.RetrieveAsync(); paymentConfiguration.WebExperienceProfileId = PayPalGateway.CreateWebExperienceProfile(paymentConfiguration, brandConfig, ApplicationDomain.Instance.PortalLocalization.CountryIso2Code); } // Save the validated & complete payment configuration to repository. PaymentConfiguration paymentConfig = await ApplicationDomain.Instance.PaymentConfigurationRepository.UpdateAsync(paymentConfiguration); return(paymentConfig); }
/// <summary> /// Adds a portal subscription for the Customer. /// </summary> /// <param name="clientCustomerId">The Customer Id.</param> /// <param name="orderSubscriptions">The Order information containing credit card and list of subscriptions to add.</param> /// <returns>Transaction Result from commerce operation.</returns> private async Task <TransactionResult> AddCustomerSubscription(string clientCustomerId, OrderViewModel orderSubscriptions) { string operationDescription = string.Format("Customer Id:[{0}] - Added Subscription(s).", clientCustomerId); PayPalGateway paymentGateway = new PayPalGateway(ApplicationDomain.Instance, orderSubscriptions.CreditCard, operationDescription); CommerceOperations commerceOperation = new CommerceOperations(ApplicationDomain.Instance, clientCustomerId, paymentGateway); List <PurchaseLineItem> orderItems = new List <PurchaseLineItem>(); foreach (var orderItem in orderSubscriptions.Subscriptions) { string offerId = orderItem.OfferId; int quantity = orderItem.Quantity; offerId.AssertNotEmpty(nameof(offerId)); // required for commerce operation. quantity.AssertPositive(nameof(quantity)); // required & should be greater than 0. orderItems.Add(new PurchaseLineItem(offerId, quantity)); } return(await commerceOperation.PurchaseAsync(orderItems)); }
public PagamentoCartaoCreditoFacade(PayPalGateway payPalGateway, ConfigurationManager configurationManager) { _payPalGateway = payPalGateway; _configurationManager = configurationManager; }
public async Task <BrandingConfiguration> UpdateBrandingConfiguration() { BrandingConfiguration brandingConfiguration = new BrandingConfiguration() { OrganizationName = HttpContext.Current.Request.Form["OrganizationName"], ContactUs = new ContactUsInformation() { Email = HttpContext.Current.Request.Form["ContactUsEmail"], Phone = HttpContext.Current.Request.Form["ContactUsPhone"], }, ContactSales = new ContactUsInformation() { Email = HttpContext.Current.Request.Form["ContactSalesEmail"], Phone = HttpContext.Current.Request.Form["ContactSalesPhone"], }, }; string organizationLogo = HttpContext.Current.Request.Form["OrganizationLogo"]; var organizationLogoPostedFile = HttpContext.Current.Request.Files["OrganizationLogoFile"]; if (organizationLogoPostedFile != null && Path.GetFileName(organizationLogoPostedFile.FileName) == organizationLogo) { // there is a new organization logo to be uploaded if (!organizationLogoPostedFile.ContentType.Trim().StartsWith("image/")) { throw new PartnerDomainException(ErrorCode.InvalidFileType, Resources.InvalidOrganizationLogoFileTypeMessage).AddDetail("Field", "OrganizationLogoFile"); } brandingConfiguration.OrganizationLogoContent = organizationLogoPostedFile.InputStream; } else if (!string.IsNullOrWhiteSpace(organizationLogo)) { try { // the user either did not specify a logo or he did but changed the organization logo text to point to somewhere else i.e. a URI brandingConfiguration.OrganizationLogo = new Uri(organizationLogo, UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidOrganizationLogoUriMessage, invalidUri).AddDetail("Field", "OrganizationLogo"); } } string headerImage = HttpContext.Current.Request.Form["HeaderImage"]; var headerImageUploadPostedFile = HttpContext.Current.Request.Files["HeaderImageFile"]; if (headerImageUploadPostedFile != null && Path.GetFileName(headerImageUploadPostedFile.FileName) == headerImage) { // there is a new header image to be uploaded if (!headerImageUploadPostedFile.ContentType.Trim().StartsWith("image/")) { throw new PartnerDomainException(ErrorCode.InvalidFileType, Resources.InvalidHeaderImageMessage).AddDetail("Field", "HeaderImageFile"); } brandingConfiguration.HeaderImageContent = headerImageUploadPostedFile.InputStream; } else if (!string.IsNullOrWhiteSpace(headerImage)) { try { // the user either did not specify a header image or he did but changed the organization logo text to point to somewhere else i.e. a URI brandingConfiguration.HeaderImage = new Uri(headerImage, UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidHeaderImageUriMessage, invalidUri).AddDetail("Field", "HeaderImage"); } } if (!string.IsNullOrWhiteSpace(HttpContext.Current.Request.Form["PrivacyAgreement"])) { try { brandingConfiguration.PrivacyAgreement = new Uri(HttpContext.Current.Request.Form["PrivacyAgreement"], UriKind.Absolute); } catch (UriFormatException invalidUri) { throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.InvalidPrivacyUriMessage, invalidUri).AddDetail("Field", "PrivacyAgreement"); } } if (!string.IsNullOrWhiteSpace(HttpContext.Current.Request.Form["InstrumentationKey"])) { brandingConfiguration.InstrumentationKey = HttpContext.Current.Request.Form["InstrumentationKey"]; } var updatedBrandingConfiguration = await ApplicationDomain.Instance.PortalBranding.UpdateAsync(brandingConfiguration); bool isPaymentConfigurationSetup = await ApplicationDomain.Instance.PaymentConfigurationRepository.IsConfiguredAsync(); if (isPaymentConfigurationSetup) { // update the web experience profile. var paymentConfiguration = await ApplicationDomain.Instance.PaymentConfigurationRepository.RetrieveAsync(); paymentConfiguration.WebExperienceProfileId = PayPalGateway.CreateWebExperienceProfile(paymentConfiguration, updatedBrandingConfiguration, ApplicationDomain.Instance.PortalLocalization.CountryIso2Code); await ApplicationDomain.Instance.PaymentConfigurationRepository.UpdateAsync(paymentConfiguration); } return(updatedBrandingConfiguration); }
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 }; PayPalGateway paymentGateway = new PayPalGateway(ApplicationDomain.Instance, "ProcessingOrder"); // use payment gateway to extract order information. 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 }, { "PayerId", payerId }, { "PaymentId", paymentId } }; // 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); }