Merge pull request #2 from jonahlytleMSFT/jonahlytleMSFT-NewCommerceMigrationWithAddOn

Adding Migration Example with Add-on
This commit is contained in:
jonahlytleMSFT 2022-04-04 10:45:57 -07:00 коммит произвёл GitHub
Родитель 0befc7780e cda6c94bae
Коммит 3d1f2b4c3e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 102 добавлений и 14 удалений

Просмотреть файл

@ -0,0 +1,87 @@
// -----------------------------------------------------------------------
// <copyright file="ValidateAndCreateNewCommerceMigrationWithAddOn.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Microsoft.Store.PartnerCenter.Samples.NewCommerceMigrations
{
using Microsoft.Store.PartnerCenter.Models.NewCommerceMigrations;
using System;
using System.Collections.Generic;
/// <summary>
/// A scenario that validates a New-Commerce migration with an add-on and then creates it.
/// </summary>
public class ValidateAndCreateNewCommerceMigrationWithAddOn : BasePartnerScenario
{
/// <summary>
/// Initializes a new instance of the <see cref="ValidateAndCreateNewCommerceMigrationWithAddOn"/> class.
/// </summary>
/// <param name="context">The scenario context.</param>
public ValidateAndCreateNewCommerceMigrationWithAddOn(IScenarioContext context) : base("Validate and create a New-Commerce migration with add-on", context)
{
}
/// <summary>
/// Executes the scenario.
/// </summary>
protected override void RunScenario()
{
var partnerOperations = this.Context.UserPartnerOperations;
string customerId = this.ObtainCustomerId("Enter the ID of the customer making the purchase");
string subscriptionId = this.ObtainSubscriptionId(customerId, "Enter the ID of the subscription to be migrated to New-Commerce");
string addOnSubscriptionId = this.ObtainSubscriptionId(customerId, "Enter the ID of the add-on subscription to be migrated to New-Commerce");
// Get the add-on subscription and display information.
var addOnSubscription = partnerOperations.Customers.ById(customerId).Subscriptions.ById(addOnSubscriptionId).Get();
this.Context.ConsoleHelper.WriteObject(addOnSubscription, "Add-on Subscription");
Console.WriteLine();
string addOnSubscriptionTermDuration = this.ObtainRenewalTermDuration("Enter a term duration for the add-on subscription [example: P1Y, P1M]");
string addOnSubscriptionBillingCycle = this.ObtainBillingCycle("Enter a billing cycle for the add-on subscription [example: Annual or Monthly]");
string addOnSubscriptionQuantityString = this.ObtainQuantity("Enter the quantity for the add-on subscription");
var addOnSubscriptionQuantity = int.Parse(addOnSubscriptionQuantityString);
var newCommerceMigration = new NewCommerceMigration
{
CurrentSubscriptionId = subscriptionId,
AddOnMigrations = new List<NewCommerceMigration>
{
new NewCommerceMigration
{
CurrentSubscriptionId = addOnSubscriptionId,
TermDuration = addOnSubscriptionTermDuration,
BillingCycle = addOnSubscriptionBillingCycle,
Quantity = addOnSubscriptionQuantity,
}
},
};
var newCommerceMigrationOperations = partnerOperations.Customers.ById(customerId).NewCommerceMigrations;
this.Context.ConsoleHelper.StartProgress("Validating New-Commerce migration");
var newCommerceEligibility = newCommerceMigrationOperations.Validate(newCommerceMigration);
this.Context.ConsoleHelper.WriteObject(newCommerceEligibility, "New-Commerce eligibility for the specified subscription");
this.Context.ConsoleHelper.StopProgress();
if (newCommerceEligibility.IsEligible)
{
this.Context.ConsoleHelper.StartProgress("Creating New-Commerce migration");
newCommerceMigration = newCommerceMigrationOperations.Create(newCommerceMigration);
this.Context.ConsoleHelper.WriteObject(newCommerceEligibility, "New-Commerce migration created for the specified subscription");
newCommerceMigration = newCommerceMigrationOperations.ById(newCommerceMigration.Id).Get();
this.Context.ConsoleHelper.WriteObject(newCommerceMigration, "Final New-Commerce migration");
this.Context.ConsoleHelper.StopProgress();
}
else
{
this.Context.ConsoleHelper.Warning("The specified subscription is not eligibile for migrating to New-Commerce.");
}
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
// <copyright file="Program.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
@ -20,8 +20,8 @@ namespace Microsoft.Store.PartnerCenter.Samples
using DevicesDeployment;
using Entitlements;
using IndirectModel;
using Invoice;
using Microsoft.Store.PartnerCenter.Samples.SelfServePolicies;
using Invoice;
using Microsoft.Store.PartnerCenter.Samples.SelfServePolicies;
using Models.Auditing;
using Models.Customers;
using Models.Query;
@ -29,7 +29,7 @@ namespace Microsoft.Store.PartnerCenter.Samples
using Offers;
using Orders;
using Products;
using Profile;
using Profile;
using PromotionEligibilities;
using RateCards;
using RatedUsage;
@ -286,8 +286,8 @@ namespace Microsoft.Store.PartnerCenter.Samples
private static IPartnerScenario GetProductScenarios(IScenarioContext context)
{
var productScenarios = new IPartnerScenario[]
{
new GetProductPromotions(context),
{
new GetProductPromotions(context),
new GetProductPromotion(context),
new GetProducts(context),
new GetProductsByTargetSegment(context),
@ -663,14 +663,14 @@ namespace Microsoft.Store.PartnerCenter.Samples
/// </summary>
/// <param name="context">A scenario context</param>
/// <returns>The post promotion eligibilities scenarios.</returns>
private static IPartnerScenario PostPromotionEligibilitiesScenarios(IScenarioContext context)
{
var postPromotionEligibilitiesScenarios = new IPartnerScenario[]
{
new PostPromotionEligibilities(context)
};
return new AggregatePartnerScenario("Post Promotion Eligibilities Scenarios", postPromotionEligibilitiesScenarios, context);
private static IPartnerScenario PostPromotionEligibilitiesScenarios(IScenarioContext context)
{
var postPromotionEligibilitiesScenarios = new IPartnerScenario[]
{
new PostPromotionEligibilities(context)
};
return new AggregatePartnerScenario("Post Promotion Eligibilities Scenarios", postPromotionEligibilitiesScenarios, context);
}
/// <summary>
@ -683,6 +683,7 @@ namespace Microsoft.Store.PartnerCenter.Samples
var profileScenarios = new IPartnerScenario[]
{
new ValidateAndCreateNewCommerceMigration(context),
new ValidateAndCreateNewCommerceMigrationWithAddOn(context),
};
return new AggregatePartnerScenario("New-Commerce migration samples", profileScenarios, context);