// GET: Subscriptions public ActionResult Index() { var request = new SubscriptionSearchRequest(); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); return View(collection); }
public void ToXML_EscapesGeneratedXMLForArrayElements() { SubscriptionSearchRequest request = new SubscriptionSearchRequest(). Ids.IncludedIn("<active"); TestHelper.AssertIncludes("<ids type=\"array\"><item><active</item></ids>", request.ToXml()); }
public virtual ResourceCollection <Subscription> Search(SearchDelegate searchDelegate) { var query = new SubscriptionSearchRequest(); searchDelegate(query); return(Search(query)); }
public virtual async Task <ResourceCollection <Subscription> > SearchAsync(SubscriptionSearchRequest query) { var response = new NodeWrapper(await service.PostAsync(service.MerchantPath() + "/subscriptions/advanced_search_ids", query).ConfigureAwait(false)); return(new ResourceCollection <Subscription>(response, delegate(string[] ids) { return FetchSubscriptions(query, ids); })); }
/// <summary> /// Search for subscriptions based on PlanId, DaysPastDue and Status /// </summary> /// <example> /// Quick Start Example: /// </example> /// <code> /// BraintreeGateway gateway = new BraintreeGateway(...); /// gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) { /// search.PlanId().StartsWith("abc"); /// search.DaysPastDue().Is("30"); /// search.Status().IncludedIn(Subscription.Status.ACTIVE, Subscription.Status.CANCELED); /// }); /// </code> public virtual ResourceCollection <Subscription> Search(SubscriptionSearchRequest query) { var response = new NodeWrapper(service.Post(service.MerchantPath() + "/subscriptions/advanced_search_ids", query)); return(new ResourceCollection <Subscription>(response, delegate(string[] ids) { return FetchSubscriptions(query, ids); })); }
/// <summary> /// Search for subscriptions based on PlanId, DaysPastDue and Status /// </summary> /// <example> /// Quick Start Example: /// </example> /// <code> /// BraintreeGateway gateway = new BraintreeGateway(...); /// gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) { /// search.PlanId().StartsWith("abc"); /// search.DaysPastDue().Is("30"); /// search.Status().IncludedIn(Subscription.Status.ACTIVE, Subscription.Status.CANCELED); /// }); /// </code> public virtual ResourceCollection<Subscription> Search(SubscriptionSearchRequest query) { var response = new NodeWrapper(service.Post(service.MerchantPath() + "/subscriptions/advanced_search_ids", query)); return new ResourceCollection<Subscription>(response, delegate(string[] ids) { return FetchSubscriptions(query, ids); }); }
private List<Subscription> FetchSubscriptions(SubscriptionSearchRequest query, String[] ids) { query.Ids.IncludedIn(ids); NodeWrapper response = new NodeWrapper(Service.Post("/subscriptions/advanced_search", query)); List<Subscription> subscriptions = new List<Subscription>(); foreach (NodeWrapper node in response.GetList("subscription")) { subscriptions.Add(new Subscription(node, Service)); } return subscriptions; }
private List<Subscription> FetchSubscriptions(SubscriptionSearchRequest query, string[] ids) { query.Ids.IncludedIn(ids); var response = new NodeWrapper(service.Post(service.MerchantPath() + "/subscriptions/advanced_search", query)); var subscriptions = new List<Subscription>(); foreach (var node in response.GetList("subscription")) { subscriptions.Add(new Subscription(node, gateway)); } return subscriptions; }
private List <Subscription> FetchSubscriptions(SubscriptionSearchRequest query, string[] ids) { query.Ids.IncludedIn(ids); var response = new NodeWrapper(service.Post(service.MerchantPath() + "/subscriptions/advanced_search", query)); var subscriptions = new List <Subscription>(); foreach (var node in response.GetList("subscription")) { subscriptions.Add(new Subscription(node, gateway)); } return(subscriptions); }
private List <Subscription> FetchSubscriptions(SubscriptionSearchRequest query, String[] ids) { query.Ids.IncludedIn(ids); NodeWrapper response = new NodeWrapper(Service.Post("/subscriptions/advanced_search", query)); List <Subscription> subscriptions = new List <Subscription>(); foreach (NodeWrapper node in response.GetList("subscription")) { subscriptions.Add(new Subscription(node, Service)); } return(subscriptions); }
public void Search_OnPlanIdIncludedIn() { SubscriptionRequest request1 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 5M }; SubscriptionRequest request2 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITHOUT_TRIAL.Id, Price = 5M }; SubscriptionRequest request3 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.ADD_ON_DISCOUNT_PLAN.Id, Price = 5M }; Subscription subscription1 = gateway.Subscription.Create(request1).Target; Subscription subscription2 = gateway.Subscription.Create(request2).Target; Subscription subscription3 = gateway.Subscription.Create(request3).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). PlanId.IncludedIn(PlanFixture.ADD_ON_DISCOUNT_PLAN.Id, PlanFixture.PLAN_WITH_TRIAL.Id). Price.Is(5M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2)); Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription3)); }
public void Search_OnBillingCyclesRemainingIs() { SubscriptionRequest request1 = new SubscriptionRequest { NumberOfBillingCycles = 5, PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 4M }; SubscriptionRequest request2 = new SubscriptionRequest { NumberOfBillingCycles = 10, PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 4M }; Subscription subscription1 = gateway.Subscription.Create(request1).Target; Subscription subscription2 = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). BillingCyclesRemaining.Is(5). Price.Is(4M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2)); }
public void ToXml_DaysPastDueLessThanOrEqualTo() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.LessThanOrEqualTo(4); var xml = "<search><days-past-due><max>4</max></days-past-due></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnTransactionId() { TestPlan triallessPlan = PlanFixture.PLAN_WITHOUT_TRIAL; SubscriptionRequest request1 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = triallessPlan.Id, Price = 7M }; SubscriptionRequest request2 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = triallessPlan.Id, Price = 7M }; Subscription matchingSubscription = gateway.Subscription.Create(request1).Target; Subscription nonMatchingSubscription = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). TransactionId.Is(matchingSubscription.Transactions[0].Id); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, matchingSubscription)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, nonMatchingSubscription)); }
public void Search_OnMerchantAccountIdWithBogusMerchantId() { Random random = new Random(); String subscriptionId = random.Next(0, 100000).ToString(); var subscriptionRequest = new SubscriptionRequest { MerchantAccountId = MerchantAccountIDs.NON_DEFAULT_MERCHANT_ACCOUNT_ID, PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 2M, Id = subscriptionId }; gateway.Subscription.Create(subscriptionRequest); var searchRequest = new SubscriptionSearchRequest(). MerchantAccountId.Is(MerchantAccountIDs.NON_DEFAULT_MERCHANT_ACCOUNT_ID). Id.Is(subscriptionId). Price.Is(2M); var collection = gateway.Subscription.Search(searchRequest); Assert.AreEqual(1, collection.MaximumCount); searchRequest = new SubscriptionSearchRequest(). MerchantAccountId.IncludedIn(MerchantAccountIDs.NON_DEFAULT_MERCHANT_ACCOUNT_ID, "bogus_merchant_account_id"). Id.Is(subscriptionId). Price.Is(2M); collection = gateway.Subscription.Search(searchRequest); Assert.AreEqual(1, collection.MaximumCount); searchRequest = new SubscriptionSearchRequest(). MerchantAccountId.Is("bogus_merchant_account_id"). Id.Is(subscriptionId). Price.Is(2M); collection = gateway.Subscription.Search(searchRequest); Assert.AreEqual(0, collection.MaximumCount); }
public void Search_OnPlanIdIs() { TestPlan triallessPlan = PlanFixture.PLAN_WITHOUT_TRIAL; TestPlan trialPlan = PlanFixture.PLAN_WITH_TRIAL; SubscriptionRequest request1 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = trialPlan.Id, Price = 5M }; SubscriptionRequest request2 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = triallessPlan.Id, Price = 5M }; Subscription trialSubscription = gateway.Subscription.Create(request1).Target; Subscription triallessSubscription = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). PlanId.Is(trialPlan.Id). Price.Is(5M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, trialSubscription)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, triallessSubscription)); }
public void ToXml_DaysPastDueIs() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.Is("30"); var xml = "<search><days-past-due><is>30</is></days-past-due></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnInTrialPeriodIs() { SubscriptionRequest request1 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id }; SubscriptionRequest request2 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITHOUT_TRIAL.Id }; Subscription trial = gateway.Subscription.Create(request1).Target; Subscription noTrial = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). InTrialPeriod.Is(true); ResourceCollection<Subscription> trialResults = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(trialResults, trial)); Assert.IsFalse(TestHelper.IncludesSubscription(trialResults, noTrial)); request = new SubscriptionSearchRequest(). InTrialPeriod.Is(false); ResourceCollection<Subscription> noTrialResults = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(noTrialResults, noTrial)); Assert.IsFalse(TestHelper.IncludesSubscription(noTrialResults, trial)); }
public void ToXml_PriceLessThanOrEqualTo() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.LessThanOrEqualTo(12.34M); var xml = "<search><price><max>12.34</max></price></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void ToXml_DaysPastDueBetween() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.Between(2, 3); var xml = "<search><days-past-due><min>2</min><max>3</max></days-past-due></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void ToXml_PriceBetween() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.Between(1M, 2M); var xml = "<search><price><min>1</min><max>2</max></price></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void ToXml_PriceIs() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.Is(1M); var xml = "<search><price><is>1</is></price></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void ToXml_BillingCyclesRemainingBetween() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.Between(1, 2); var xml = "<search><billing-cycles-remaining><min>1</min><max>2</max></billing-cycles-remaining></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnDaysPastDueBetween() { SubscriptionRequest subscriptionRequest = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, }; Subscription subscription = gateway.Subscription.Create(subscriptionRequest).Target; MakePastDue(subscription, 3); SubscriptionSearchRequest request = new SubscriptionSearchRequest(). DaysPastDue.Between(2, 10); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(collection.MaximumCount > 0); foreach (Subscription foundSubscription in collection) { Assert.IsTrue(foundSubscription.DaysPastDue >= 2 && foundSubscription.DaysPastDue <= 10); } }
public void ToXml_IdEndsWith() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.EndsWith("30"); var xml = "<search><id><ends-with>30</ends-with></id></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnIdIs() { SubscriptionRequest request1 = new SubscriptionRequest { Id = String.Format("find_me{0}", new Random().Next(1000000)), PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 3M }; SubscriptionRequest request2 = new SubscriptionRequest { Id = String.Format("do_not_find_me{0}", new Random().Next(1000000)), PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 3M }; Subscription subscription1 = gateway.Subscription.Create(request1).Target; Subscription subscription2 = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). Id.StartsWith("find_me"). Price.Is(3M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2)); }
public void ToXml_IdContains() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.Contains("30"); var xml = "<search><id><contains>30</contains></id></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnMerchantAccountIdIs() { SubscriptionRequest request1 = new SubscriptionRequest { MerchantAccountId = MerchantAccountIDs.DEFAULT_MERCHANT_ACCOUNT_ID, PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 2M }; SubscriptionRequest request2 = new SubscriptionRequest { MerchantAccountId = MerchantAccountIDs.NON_DEFAULT_MERCHANT_ACCOUNT_ID, PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 2M }; Subscription defaultMerchantAccountSubscription = gateway.Subscription.Create(request1).Target; Subscription nonDefaultMerchantAccountSubscription = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). MerchantAccountId.Is(MerchantAccountIDs.NON_DEFAULT_MERCHANT_ACCOUNT_ID). Price.Is(2M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, nonDefaultMerchantAccountSubscription)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, defaultMerchantAccountSubscription)); }
public void ToXml_MerchantAccountIdIncludedIn() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().MerchantAccountId.IncludedIn("abc", "def"); var xml = "<search><merchant-account-id type=\"array\"><item>abc</item><item>def</item></merchant-account-id></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void Search_OnNextBillingDate() { TestPlan triallessPlan = PlanFixture.PLAN_WITHOUT_TRIAL; TestPlan trialPlan = PlanFixture.PLAN_WITH_TRIAL; SubscriptionRequest request1 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = triallessPlan.Id, Price = 7M }; SubscriptionRequest request2 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = trialPlan.Id, Price = 7M }; Subscription triallessSubscription = gateway.Subscription.Create(request1).Target; Subscription trialSubscription = gateway.Subscription.Create(request2).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). NextBillingDate.GreaterThanOrEqualTo(DateTime.Now.AddDays(5)); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsTrue(TestHelper.IncludesSubscription(collection, triallessSubscription)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, trialSubscription)); }
public void Search_OnPrice() { SubscriptionRequest request10 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 10M }; SubscriptionRequest request20 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 20M }; SubscriptionRequest request30 = new SubscriptionRequest { PaymentMethodToken = creditCard.Token, PlanId = PlanFixture.PLAN_WITH_TRIAL.Id, Price = 30M }; Subscription subscription10 = gateway.Subscription.Create(request10).Target; Subscription subscription20 = gateway.Subscription.Create(request20).Target; Subscription subscription30 = gateway.Subscription.Create(request30).Target; SubscriptionSearchRequest request = new SubscriptionSearchRequest(). Price.Between(15M, 20M); ResourceCollection<Subscription> collection = gateway.Subscription.Search(request); Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription10)); Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription20)); Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription30)); }
public void ToXml_BillingCyclesRemainingLessThanOrEqualTo() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.LessThanOrEqualTo(12.34); var xml = "<search><billing-cycles-remaining><max>12.34</max></billing-cycles-remaining></search>"; Assert.AreEqual(xml, request.ToXml()); }
public void ToXml_DaysPastDueGreaterThanOrEqualTo() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.GreaterThanOrEqualTo(3); var xml = "<search><days-past-due><min>3</min></days-past-due></search>"; Assert.AreEqual(xml, request.ToXml()); }
public virtual ResourceCollection<Subscription> Search(SearchDelegate searchDelegate) { var query = new SubscriptionSearchRequest(); searchDelegate(query); return Search(query); }
public void ToXml_IdIsNot() { SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.IsNot("30"); var xml = "<search><id><is-not>30</is-not></id></search>"; Assert.AreEqual(xml, request.ToXml()); }