public async Task NotifyChange(SubscriptionChange changeType, Subscription subscription) { var redis = this.connection.GetDatabase(); var message = string.Format("{0}|{1}", (int)changeType, subscription.Id); await redis.PublishAsync(this.subscriptionChannel, message); }
public void LookupSubscriptionPendingChanges() { var plan = new Plan(GetMockPlanCode(), GetMockPlanName()) { Description = "Lookup Subscription With Pending Changes Test" }; plan.UnitAmountInCents.Add("USD", 1500); plan.Create(); PlansToDeactivateOnDispose.Add(plan); var account = CreateNewAccountWithBillingInfo(); var sub = new Subscription(account, plan, "USD"); sub.Create(); var subChange = new SubscriptionChange() { UnitAmountInCents = 3000, TimeFrame = SubscriptionChange.ChangeTimeframe.Renewal }; Subscription.ChangeSubscription(sub.Uuid, subChange); var newSubscription = Subscriptions.Get(sub.Uuid); newSubscription.PendingSubscription.Should().NotBeNull(); newSubscription.PendingSubscription.UnitAmountInCents.Should().Be(3000); }
public Task NotifyChange(SubscriptionChange changeType, Subscription subscription) { foreach (var handler in handlers) { NotifyHandler(handler, changeType, subscription); } return(Task.FromResult(1)); }
public Task NotifyChange(SubscriptionChange changeType, Subscription subscription) { foreach (var handler in handlers) { NotifyHandler(handler, changeType, subscription); } return Task.FromResult(1); }
private void OnSubscriptionChanged(SubscriptionChange change, Subscription subscription) { if (change == SubscriptionChange.Add) { OnSubscriptionAdded(subscription); } else { OnSubscriptionRemoved(subscription); } }
static void Main(string[] args) { var client = new Recurly.Client("e9922993342845dbbc583c145b2ab811"); var subscriptionUuid = "50b8aee7610eefeb55374a4996838338"; var change = new SubscriptionChange { TimeFrame = SubscriptionChange.ChangeTimeframe.Now, // or TimeFrame = SubscriptionChange.ChangeTimeframe.Renewal // or TimeFrame = SubscriptionChange.ChangeTimeframe.BillDate PlanCode = "silver", Quantity = 2 }; // perform the update operation Subscription.ChangeSubscription(subscriptionUuid, change); }
public async Task <CallResult <SubscriptionChange> > SetFinishStateAsync(int courseId, string userId) { ThrowIfDisposed(); var subscription = await CatalogContext.Subscriptions.FindAsync(userId, courseId); if (subscription == null) { var message = string.Format(Resources.EntityNotFound_Subscription, userId, courseId); return(CallResult <SubscriptionChange> .Failed(message)); } subscription.FinishDate = DateTime.UtcNow.Date; subscription.State = LearningState.Finished; await CatalogContext.SaveChangesAsync(); var subscriptionChange = new SubscriptionChange(subscription.FinishDate.Value); return(CallResult <SubscriptionChange> .Success(subscriptionChange)); }
public void UpdateSubscription() { var plan = new Plan(GetMockPlanCode(), GetMockPlanName()) { Description = "Update Subscription Plan 1" }; plan.UnitAmountInCents.Add("USD", 1500); plan.Create(); PlansToDeactivateOnDispose.Add(plan); var plan2 = new Plan(GetMockPlanCode(), GetMockPlanName()) { Description = "Update Subscription Plan 2" }; plan2.UnitAmountInCents.Add("USD", 750); plan2.Create(); PlansToDeactivateOnDispose.Add(plan2); var account = CreateNewAccountWithBillingInfo(); var sub = new Subscription(account, plan, "USD"); sub.Create(); var subChange = new SubscriptionChange() { PlanCode = plan2.PlanCode }; Subscription.ChangeSubscription(sub.Uuid, subChange); var newSubscription = Subscriptions.Get(sub.Uuid); newSubscription.PendingSubscription.Should().BeNull(); newSubscription.Plan.Should().Be(plan2); }
public void CreateSubscriptionPlanWithAddons() { Plan plan = null; Plan plan2 = null; AddOn addon1 = null; AddOn addon2 = null; Account account = null; Subscription sub = null; Subscription sub2 = null; SubscriptionChange subChange = 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.AddOnType = AddOn.Type.Fixed; 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.AddOnType = AddOn.Type.Fixed; 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", AddOn.Type.Fixed, 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 subChange = new SubscriptionChange() { UnitAmountInCents = plan2.UnitAmountInCents["USD"], PlanCode = plan2.PlanCode, AddOns = sub.AddOns }; foreach (var addOn in subChange.AddOns) { addOn.UnitAmountInCents = plan2.UnitAmountInCents["USD"]; } Subscription.ChangeSubscription(sub.Uuid, subChange); // check if the changes were saved sub2 = Subscriptions.Get(sub.Uuid); sub2.UnitAmountInCents.Should().Equals(plan2.UnitAmountInCents["USD"]); Assert.Equal(1, sub2.AddOns.Count); foreach (var addOn in sub2.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(); } } }
private void NotifyHandler(Action <SubscriptionChange, Subscription> handler, SubscriptionChange change, Subscription subscription) { handler(change, subscription); }
private void NotifyHandler(Action<SubscriptionChange, Subscription> handler, SubscriptionChange change, Subscription subscription) { handler(change, subscription); }