public void UpgradeSubscription_ChargesProRatadAmount()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);

            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };
            var creditCard = new CreditCard
            {
                CardType = "visa",
                ExpirationMonth = 12,
                ExpirationYear = 2012,
                FirstName = "Tester",
                LastName = "Testing",
                Number = TestConstants.ValidCard,
                VerificationValue = "123"
            };

            subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                       TestConstants.MediumSubscriptionPlanId,
                                                                       creditCard);
            var upgradeInvoice = subscriberHelper.ChangeSubscriberFeatureLevelWithOnFilePayment(subscriber, TestConstants.HighSubscriptionPlanId);

            Assert.AreEqual(15, upgradeInvoice.Amount.Value);
        }
        public void Init()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);
            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };

            if (!subscriberHelper.Exists(subscriber.CustomerId))
                subscriberHelper.CreateSubscriber(subscriber.CustomerId, subscriber.Email, subscriber.ScreenName);
        }
        public void init()
        {
            _factory = new SpreedlyClientFactory(new SpreedlyParameters
                                                     {
                                                         ApiKey = TestConstants.TestApiKey,
                                                         SiteName = TestConstants.TestSiteName
                                                     });
            _subscribers = _factory.GetSubscribersClient();
            _invoices = _factory.GetInvoiceClient();

            var newSubscriber = new Subscriber
                                    {
                                        CustomerId = TestConstants.TestCustomerId,
                                        ScreenName = TestConstants.TestCustomerId,
                                        Email = "*****@*****.**"
                                    };
            _subscribers.CreateSubscriber(newSubscriber);
        }
        public void CreateSubscription_WithHelper_ReturnsInvoice()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);
            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };
            var creditCard = new CreditCard
            {
                CardType = "visa",
                ExpirationMonth = 12,
                ExpirationYear = 2012,
                FirstName = "Tester",
                LastName = "Testing",
                Number = TestConstants.ValidCard,
                VerificationValue = "123"
            };

            var invoice = subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber, TestConstants.MediumSubscriptionPlanId, creditCard);

            Assert.NotNull(invoice);
        }
        public void SubscribingSubscriber_ToExistingPlan_ReturnsAnInvoice()
        {
            var subscriber = new Subscriber
                                 {
                                     CustomerId = "Id"
                                 };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.Created, new Invoice());
            SetPayInvoiceStatusAndResult(SpreedlyStatus.Ok, new Invoice());

            var paidInvoice = _subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                                          1111,
                                                                                          new CreditCard());

            Assert.NotNull(paidInvoice);
        }
        public void CreateFreeTrialSubscription_ForExistingPlan_PassesCorrectSubscriber()
        {
            var freeTrialPlanId = 11111;
            var customerId = "111";
            var subscriber = new Subscriber
            {
                CustomerId = customerId
            };
            _subscriptionPlansClient.GetSubscriptionPlans().ReturnsForAnyArgs(new SpreedlyResponse<SubscriptionPlanList>
                                                                                  {
                                                                                      Status = SpreedlyStatus.Ok,
                                                                                      Entity = new SubscriptionPlanList
                                                                                                   {
                                                                                                       SubscriptionPlans = new List<SubscriptionPlan>
                                                                                                               {
                                                                                                                   new SubscriptionPlan
                                                                                                                       {
                                                                                                                           Id = freeTrialPlanId
                                                                                                                       }
                                                                                                               }
                                                                                                   }

                                                                                  });
            _subscriberClient.SubscribeSubscriberToFreeTrial(null, null).ReturnsForAnyArgs(new SpreedlyResponse
                                                                                               <Subscriber>
                                                                                               {
                                                                                                   Status = SpreedlyStatus.Ok,
                                                                                                   Entity = new Subscriber()
                                                                                               });

            _subscriberHelper.SubscribeToFreeTrialPlan(subscriber, freeTrialPlanId);

            _subscriberClient.Received().SubscribeSubscriberToFreeTrial(
                Arg.Is<string>(s => s == customerId),
                Arg.Is<SubscriptionPlan>(sp => sp.Id.Value == freeTrialPlanId));
        }
        public void CreateFreeTrialSubscription_ForExistingPlan_ReturnsSubscriber()
        {
            var freeTrialPlanId = 11111;
            var customerId = "111";
            var subscriber = new Subscriber
                                 {
                                     CustomerId = customerId
                                 };
            _subscriptionPlansClient.GetSubscriptionPlans().ReturnsForAnyArgs(new SpreedlyResponse<SubscriptionPlanList>
                                                                                {
                                                                                    Status = SpreedlyStatus.Ok,
                                                                                    Entity = new SubscriptionPlanList
                                                                                    {
                                                                                        SubscriptionPlans = new List<SubscriptionPlan>
                                                                                                                {
                                                                                                                    new SubscriptionPlan{ Id = freeTrialPlanId }
                                                                                                                }
                                                                                    }

                                                                                });
            _subscriberClient.SubscribeSubscriberToFreeTrial(null, null).ReturnsForAnyArgs(new SpreedlyResponse<Subscriber>
                                                                                               {
                                                                                                   Status = SpreedlyStatus.Ok,
                                                                                                   Entity = new Subscriber()
                                                                                               });

            subscriber = _subscriberHelper.SubscribeToFreeTrialPlan(subscriber, freeTrialPlanId);

            Assert.NotNull(subscriber);
        }
        public void CreateSubscription_WithGatewayTimeoutStatusForPay_ThrowsPaymentGatewayException()
        {
            var subscriber = new Subscriber
                                 {
                                     CustomerId = "Id"
                                 };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.Created, new Invoice());
            SetPayInvoiceStatusAndResult(SpreedlyStatus.GatewayTimeout, null);

            _subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                        1111,
                                                                        new CreditCard());
        }
        public void CreateSubscription_WithUnprocessableEntityStatusForPay_ThrowsUnprocessableEntityException()
        {
            var subscriber = new Subscriber
            {
                CustomerId = "Id"
            };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.Created, new Invoice());
            SetPayInvoiceStatusAndResult(SpreedlyStatus.UnprocessableEntity, null);

            _subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                        11111,
                                                                        new CreditCard());
        }
Exemplo n.º 10
0
        public void CreateSubscription_WithForbiddenStatusForPay_ThrowsForbiddenActionException()
        {
            var subscriber = new Subscriber
            {
                CustomerId = "Id"
            };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.Created, new Invoice());
            SetPayInvoiceStatusAndResult(SpreedlyStatus.Forbidden, null);

            _subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                        11111,
                                                                        new CreditCard());
        }
Exemplo n.º 11
0
        public void CreateSubscription_WithNotFoundForCreate_ThrowsNotFoundException()
        {
            var subscriber = new Subscriber
            {
                CustomerId = "Id"
            };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.NotFound, null);

            _subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber,
                                                                        11111,
                                                                        new CreditCard());
        }
Exemplo n.º 12
0
        public void ChangingSubscriptionLevelWithOnFilePayment_PaysInvoiceUsingOnFile()
        {
            var subscriber = new Subscriber
            {
                CustomerId = "Id"
            };
            SetCreateInvoiceStatusAndResult(SpreedlyStatus.Created, new Invoice());
            SetPayInvoiceStatusAndResult(SpreedlyStatus.Ok, new Invoice());

            _subscriberHelper.ChangeSubscriberFeatureLevelWithOnFilePayment(subscriber, 1111);

            _paymentsClient.Received().PayInvoice(Arg.Any<Invoice>(),
                                                  Arg.Is<Payment>(p => p.AccountType == "on-file"));
        }
        public void CreateSubscription_WithHelper_WhenGatewayTimesout_ThrowsPaymentGatewayTimeoutException()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);
            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };
            var creditCard = new CreditCard
            {
                CardType = "visa",
                ExpirationMonth = 12,
                ExpirationYear = 2012,
                FirstName = "Tester",
                LastName = "Testing",
                Number = TestConstants.GatewayUnavailableCard,
                VerificationValue = "123"
            };

            var invoice = subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber, TestConstants.MediumSubscriptionPlanId, creditCard);
        }
Exemplo n.º 14
0
 public SpreedlyResponse<Subscriber> UpdateSubscriber(Subscriber subscriber)
 {
     var customerId = subscriber.CustomerId;
     subscriber.CustomerId = null;
     return _client.Put<Subscriber>(string.Format("subscribers/{0}.xml", customerId), subscriber);
 }
Exemplo n.º 15
0
 public SpreedlyResponse<Subscriber> CreateSubscriber(Subscriber newSubscriber)
 {
     return _client.Post<Subscriber>("subscribers.xml", newSubscriber);
 }
        public void DowngradeSubscription_GivesStoreCreditToSubscriber()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);
            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };
            var creditCard = new CreditCard
            {
                CardType = "visa",
                ExpirationMonth = 12,
                ExpirationYear = 2012,
                FirstName = "Tester",
                LastName = "Testing",
                Number = TestConstants.ValidCard,
                VerificationValue = "123"
            };

            subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber, TestConstants.HighSubscriptionPlanId, creditCard);
            subscriberHelper.ChangeSubscriberFeatureLevelWithOnFilePayment(subscriber, TestConstants.LowSubscriptionPlanId);
            var downgradedSubscriber = subscriberHelper.FetchSubscriber(subscriber.CustomerId);

            Assert.GreaterOrEqual(downgradedSubscriber.StoreCredit.Value, 0);
        }
        public void CreateSubscription_WithHelper_ForFreeSubscriptionPlan_ThrowsForbiddenActionException()
        {
            var subscriberHelper = new SubscriberHelper(TestConstants.TestSiteName, TestConstants.TestApiKey);
            var subscriber = new Subscriber
            {
                CustomerId = TestConstants.TestCustomerId,
                ScreenName = TestConstants.TestCustomerId,
                Email = "*****@*****.**"
            };
            var creditCard = new CreditCard
            {
                CardType = "visa",
                ExpirationMonth = 12,
                ExpirationYear = 2012,
                FirstName = "Tester",
                LastName = "Testing",
                Number = TestConstants.ValidCard,
                VerificationValue = "123"
            };

            var invoice = subscriberHelper.SubscribeToSubscriptionPlanWithCreditCard(subscriber, TestConstants.FreePlanSubscriptionPlanId, creditCard);
        }