Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 64dd0e5

Browse files
idwilliams-2joelst
authored andcommitted
Added the ability to change a subscriptions billing cycle. (#41)
1 parent f9de46b commit 64dd0e5

8 files changed

Lines changed: 105 additions & 14 deletions

docs/help/New-PartnerAccessToken.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ New-PartnerAccessToken -ApplicationId <String> [-Credential <PSCredential>] [-En
2222

2323
### ServicePrincipal
2424
```
25-
New-PartnerAccessToken -Credential <PSCredential> [-Environment <EnvironmentName>] -TenantId <String>
26-
[-TokenCache <TokenCache>] [<CommonParameters>]
25+
New-PartnerAccessToken -Credential <PSCredential> [-Environment <EnvironmentName>] [-ServicePrincipal]
26+
-TenantId <String> [-TokenCache <TokenCache>] [<CommonParameters>]
2727
```
2828

2929
## DESCRIPTION
@@ -109,6 +109,21 @@ Accept pipeline input: False
109109
Accept wildcard characters: False
110110
```
111111
112+
### -ServicePrincipal
113+
A flag indicating that a service principal will be used to authenticate.
114+
115+
```yaml
116+
Type: SwitchParameter
117+
Parameter Sets: ServicePrincipal
118+
Aliases:
119+
120+
Required: True
121+
Position: Named
122+
Default value: None
123+
Accept pipeline input: False
124+
Accept wildcard characters: False
125+
```
126+
112127
### -TenantId
113128
The Azure AD domain or tenant identifier.
114129

docs/help/Set-PartnerCustomerSubscription.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ Updates the specified customer subscription.
1616

1717
### Customer
1818
```
19-
Set-PartnerCustomerSubscription [-AutoRenew <Boolean>] -CustomerId <String> [-FriendlyName <String>]
20-
[-Quantity <Int32>] [-Status <SubscriptionStatus>] -SubscriptionId <String> [-WhatIf] [-Confirm]
21-
[<CommonParameters>]
19+
Set-PartnerCustomerSubscription [-AutoRenew <Boolean>] [-BillingCycle <BillingCycleType>] -CustomerId <String>
20+
[-FriendlyName <String>] [-Quantity <Int32>] [-Status <SubscriptionStatus>] -SubscriptionId <String> [-WhatIf]
21+
[-Confirm] [<CommonParameters>]
2222
```
2323

2424
### CustomerObject
2525
```
26-
Set-PartnerCustomerSubscription [-AutoRenew <Boolean>] -InputObject <PSCustomer> [-FriendlyName <String>]
27-
[-Quantity <Int32>] [-Status <SubscriptionStatus>] -SubscriptionId <String> [-WhatIf] [-Confirm]
28-
[<CommonParameters>]
26+
Set-PartnerCustomerSubscription [-AutoRenew <Boolean>] -InputObject <PSCustomer>
27+
[-BillingCycle <BillingCycleType>] [-FriendlyName <String>] [-Quantity <Int32>] [-Status <SubscriptionStatus>]
28+
-SubscriptionId <String> [-WhatIf] [-Confirm] [<CommonParameters>]
2929
```
3030

3131
## DESCRIPTION
@@ -57,6 +57,21 @@ Accept pipeline input: False
5757
Accept wildcard characters: False
5858
```
5959
60+
### -BillingCycle
61+
The billing cycle for the subscription.
62+
63+
```yaml
64+
Type: BillingCycleType
65+
Parameter Sets: (All)
66+
Aliases:
67+
68+
Required: False
69+
Position: Named
70+
Default value: None
71+
Accept pipeline input: False
72+
Accept wildcard characters: False
73+
```
74+
6075
### -CustomerId
6176
The customer identifier used to scope the request.
6277

src/Core.Models/Core.Models.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>Microsoft.Store.PartnerCenter.Core.Models</AssemblyName>
66
<RootNamespace>Microsoft.Store.PartnerCenter.Core.Models</RootNamespace>
7+
<Version>1.5.1811.3</Version>
8+
<Authors>Microsoft</Authors>
9+
<Company>Microsoft Corporation</Company>
10+
<PackageLicenseUrl>https://github.com/Microsoft/Partner-Center-PowerShell/blob/master/LICENSE</PackageLicenseUrl>
11+
<PackageProjectUrl>https://github.com/Microsoft/Partner-Center-PowerShell</PackageProjectUrl>
12+
<RepositoryUrl>https://github.com/Microsoft/Partner-Center-PowerShell.git</RepositoryUrl>
13+
<RepositoryType>git</RepositoryType>
714
</PropertyGroup>
815

916
<ItemGroup>

src/Core/Core.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<AssemblyName>Microsoft.Store.PartnerCenter.Core</AssemblyName>
66
<RootNamespace>Microsoft.Store.PartnerCenter.Core</RootNamespace>
7+
<Version>1.5.1811.3</Version>
8+
<Company>Microsoft Corporation</Company>
9+
<Authors>Microsoft</Authors>
10+
<RepositoryUrl>https://github.com/Microsoft/Partner-Center-PowerShell.git</RepositoryUrl>
11+
<RepositoryType>git</RepositoryType>
12+
<PackageProjectUrl>https://github.com/Microsoft/Partner-Center-PowerShell</PackageProjectUrl>
13+
<PackageIconUrl />
14+
<PackageLicenseUrl>https://github.com/Microsoft/Partner-Center-PowerShell/blob/master/LICENSE</PackageLicenseUrl>
715
</PropertyGroup>
816

917
<ItemGroup>

src/PowerShell/Commands/ConnectPartnerCenter.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ public class ConnectPartnerCenter : PSCmdlet, IModuleAssemblyInitializer
3232
private const string AccessTokenParameterSet = "AccessToken";
3333

3434
/// <summary>
35-
/// THe name of the configuration property.
35+
/// The name of the assembly version property.
36+
/// </summary>
37+
private const string AssemblyVersionProperty = "AssemblyVersion";
38+
39+
/// <summary>
40+
/// The name of the configuration property.
3641
/// </summary>
3742
private const string ConfigurationProperty = "Configuration";
3843

@@ -101,7 +106,7 @@ public class ConnectPartnerCenter : PSCmdlet, IModuleAssemblyInitializer
101106
/// <summary>
102107
/// Gets or sets a flag indicating that a service principal will be used to authenticate.
103108
/// </summary
104-
[Parameter(HelpMessage = "A flag indiicating that a service principal will be used to authenticate.", Mandatory = true, ParameterSetName = ServicePrincipalParameterSet)]
109+
[Parameter(HelpMessage = "A flag indicating that a service principal will be used to authenticate.", Mandatory = true, ParameterSetName = ServicePrincipalParameterSet)]
105110
public SwitchParameter ServicePrincipal { get; set; }
106111

107112
/// <summary>
@@ -138,13 +143,21 @@ protected override void BeginProcessing()
138143
public void OnImport()
139144
{
140145
PropertyInfo prop = PartnerService.Instance.GetType().GetProperty(
141-
ConfigurationProperty,
146+
ConfigurationProperty,
142147
BindingFlags.Instance | BindingFlags.NonPublic);
143148

144149
dynamic configuration = prop.GetValue(PartnerService.Instance);
145150

151+
// Override the value for the Partner Center client property.
146152
configuration.PartnerCenterClient = PartnerCenterClient;
147153

154+
prop = PartnerService.Instance.GetType().GetProperty(
155+
AssemblyVersionProperty,
156+
BindingFlags.Instance | BindingFlags.NonPublic);
157+
158+
// Override the value for the assembly version property.
159+
prop.SetValue(PartnerService.Instance, typeof(ConnectPartnerCenter).Assembly.GetName().Version.ToString());
160+
148161
if (PartnerSession.Instance.AuthenticationFactory == null)
149162
{
150163
PartnerSession.Instance.AuthenticationFactory = new AuthenticationFactory();

src/PowerShell/Commands/GetPartnerCustomerSubscription.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
1010
using System.Management.Automation;
1111
using System.Text.RegularExpressions;
1212
using Common;
13+
using Models.Customers;
14+
using Models.Subscriptions;
1315
using PartnerCenter.Models;
1416
using PartnerCenter.Models.Subscriptions;
15-
using PartnerCenter.PowerShell.Models.Customers;
16-
using PartnerCenter.PowerShell.Models.Subscriptions;
1717

1818
[Cmdlet(VerbsCommon.Get, "PartnerCustomerSubscription", DefaultParameterSetName = "Customer"), OutputType(typeof(PSSubscription))]
1919
public class GetPartnerCustomerSubscription : PartnerPSCmdlet

src/PowerShell/Commands/NewPartnerAccessToken.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class NewPartnerAccessToken : PSCmdlet
4848
/// <summary>
4949
/// Gets or sets a flag indicating that a service principal will be used to authenticate.
5050
/// </summary
51-
[Parameter(HelpMessage = "A flag indiicating that a service principal will be used to authenticate.", Mandatory = true, ParameterSetName = "ServicePrincipal")]
51+
[Parameter(HelpMessage = "A flag indicating that a service principal will be used to authenticate.", Mandatory = true, ParameterSetName = "ServicePrincipal")]
5252
public SwitchParameter ServicePrincipal { get; set; }
5353

5454
/// <summary>

src/PowerShell/Commands/SetPartnerCustomerSubscription.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
namespace Microsoft.Store.PartnerCenter.PowerShell.Commands
88
{
9+
using System.Collections.Generic;
910
using System.Globalization;
1011
using System.Management.Automation;
1112
using System.Text.RegularExpressions;
1213
using Models.Customers;
1314
using Models.Subscriptions;
15+
using PartnerCenter.Models.Offers;
16+
using PartnerCenter.Models.Orders;
1417
using PartnerCenter.Models.Subscriptions;
1518
using Properties;
1619

@@ -30,6 +33,13 @@ public class SetPartnerCustomerSubscription : PartnerPSCmdlet
3033
[Parameter(HelpMessage = "The customer object used to scope the request.", ParameterSetName = "CustomerObject", Mandatory = true)]
3134
public PSCustomer InputObject { get; set; }
3235

36+
/// <summary>
37+
/// Gets or sets the billing cycle for the subscription.
38+
/// </summary>
39+
[Parameter(HelpMessage = "The billing cycle for the subscription.", Mandatory = false)]
40+
[ValidateSet(nameof(BillingCycleType.Annual), nameof(BillingCycleType.Monthly))]
41+
public BillingCycleType? BillingCycle { get; set; }
42+
3343
/// <summary>
3444
/// Gets or sets the customer identifier.
3545
/// </summary>
@@ -56,6 +66,7 @@ public class SetPartnerCustomerSubscription : PartnerPSCmdlet
5666
/// </summary>
5767
[Parameter(HelpMessage = "The status of the subscription.", ParameterSetName = "Customer", Mandatory = false)]
5868
[Parameter(HelpMessage = "The status of the subscription.", ParameterSetName = "CustomerObject", Mandatory = false)]
69+
[ValidateSet(nameof(SubscriptionStatus.Active), nameof(SubscriptionStatus.Suspended))]
5970
public SubscriptionStatus? Status { get; set; }
6071

6172
/// <summary>
@@ -91,6 +102,28 @@ public override void ExecuteCmdlet()
91102
subscription.AutoRenewEnabled = AutoRenew.Value;
92103
}
93104

105+
if (BillingCycle.HasValue)
106+
{
107+
Partner.Customers[customerId].Orders[subscription.OrderId].Patch(new Order
108+
{
109+
BillingCycle = BillingCycle.Value,
110+
LineItems = new List<OrderLineItem>
111+
{
112+
new OrderLineItem
113+
{
114+
LineItemNumber = 0,
115+
OfferId = subscription.OfferId,
116+
ParentSubscriptionId = subscription.ParentSubscriptionId,
117+
SubscriptionId = subscription.Id,
118+
Quantity = subscription.Quantity
119+
}
120+
},
121+
ReferenceCustomerId = customerId
122+
});
123+
124+
subscription.BillingCycle = BillingCycle.Value;
125+
}
126+
94127
if (!string.IsNullOrEmpty(FriendlyName))
95128
{
96129
subscription.FriendlyName = FriendlyName;

0 commit comments

Comments
 (0)