本文整理汇总了C#中Plan.GetAddOn方法的典型用法代码示例。如果您正苦于以下问题:C# Plan.GetAddOn方法的具体用法?C# Plan.GetAddOn怎么用?C# Plan.GetAddOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plan
的用法示例。
在下文中一共展示了Plan.GetAddOn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSubscriptionPlanWithAddons
public void CreateSubscriptionPlanWithAddons()
{
Plan plan = null;
Plan plan2 = null;
AddOn addon1 = null;
AddOn addon2 = null;
Account account = null;
Subscription sub = null;
Subscription sub2 = null;
Subscription sub3 = null;
try
{
plan = new Plan(GetMockPlanCode(), "aarons test plan")
{
Description = "Create Subscription Plan With Addons Test"
};
plan.UnitAmountInCents.Add("USD", 100);
plan.Create();
addon1 = plan.NewAddOn("addon1", "addon1");
addon1.DisplayQuantityOnHostedPage = true;
addon1.UnitAmountInCents.Add("USD", 100);
addon1.DefaultQuantity = 1;
addon1.Create();
plan = Plans.Get(plan.PlanCode);
var addon_test_1 = plan.GetAddOn("addon1");
Assert.Equal(addon1.UnitAmountInCents["USD"], addon_test_1.UnitAmountInCents["USD"]);
plan2 = new Plan(GetMockPlanCode(), "aarons test plan 2")
{
Description = "Create Subscription Plan With Addons Test 2"
};
plan2.UnitAmountInCents.Add("USD", 1900);
plan2.Create();
addon2 = plan2.NewAddOn("addon1", "addon2");
addon2.DisplayQuantityOnHostedPage = true;
addon2.UnitAmountInCents.Add("USD", 200);
addon2.DefaultQuantity = 1;
addon2.Create();
var addon_test_2 = plan2.GetAddOn("addon1");
Assert.Equal(addon2.UnitAmountInCents["USD"], addon_test_2.UnitAmountInCents["USD"]);
account = CreateNewAccountWithBillingInfo();
sub = new Subscription(account, plan, "USD");
sub.AddOns.Add(new SubscriptionAddOn("addon1", 100, 1)); // TODO allow passing just the addon code
sub.Create();
// confirm that Create() doesn't duplicate the AddOns
Assert.Equal(1, sub.AddOns.Count);
sub.ActivatedAt.Should().HaveValue().And.NotBe(default(DateTime));
sub.State.Should().Be(Subscription.SubscriptionState.Active);
// test changing the plan of a subscription
sub2 = Subscriptions.Get(sub.Uuid);
sub2.UnitAmountInCents = plan2.UnitAmountInCents["USD"];
sub2.Plan = plan2;
foreach (var addOn in sub2.AddOns)
{
addOn.UnitAmountInCents = plan2.UnitAmountInCents["USD"];
}
sub2.ChangeSubscription(Subscription.ChangeTimeframe.Now);
// check if the changes were saved
sub3 = Subscriptions.Get(sub2.Uuid);
sub3.UnitAmountInCents.Should().Equals(plan2.UnitAmountInCents["USD"]);
Assert.Equal(1, sub3.AddOns.Count);
foreach (var addOn in sub3.AddOns)
{
addOn.UnitAmountInCents.Should().Equals(plan2.UnitAmountInCents["USD"]);
}
} finally {
if (sub != null) sub.Cancel();
if (plan2 != null) plan2.Deactivate();
if (plan != null) plan.Deactivate();
if (account != null) account.Close();
}
}