public void CreateInvoiceForUser_ReturnsInvoice()
        {
            var invoice = _invoices.CreateInvoice(new Invoice
                                                      {
                                                          SubscriptionPlanId = 14143,
                                                          Subscriber = new Subscriber
                                                                           {
                                                                               CustomerId = TestConstants.TestCustomerId,
                                                                               ScreenName = TestConstants.TestCustomerId,
                                                                               Email = "*****@*****.**"
                                                                           }
                                                      });
            
            Assert.AreEqual(SpreedlyStatus.Created, invoice.Status);

            var payment = new Payment
                              {
                                  AccountType = "credit-card",
                                  CreditCard = new CreditCard
                                                   {
                                                       CardType = "visa",
                                                       ExpirationMonth = 12,
                                                       ExpirationYear = 2012,
                                                       FirstName = "Tester",
                                                       LastName = "Testing",
                                                       Number = TestConstants.ValidCard,
                                                       VerificationValue = "123"
                                                   }
                              };

            var paymentResult = _invoices.PayInvoice(invoice.Entity, payment);

            Assert.AreEqual(SpreedlyStatus.Ok, paymentResult.Status);

        }
        public void UpgradeSubscriberThenDowngradeToFreePlan_ReturnsDowngradedSubscriber()
        {
            var custId = TestConstants.TestCustomerId;
            var sub = _subscribers.GetSubscriberByCustomerId(custId);
            var subscriber = sub.Entity;
            Assert.AreEqual(custId, subscriber.CustomerId);

            var planFactory = _factory.GetSubscriptionPlanClient();
            var invoiceFactory = _factory.GetInvoiceClient();

            var plans = planFactory.GetSubscriptionPlans();
            var freePlan = plans.Entity.SubscriptionPlans.FirstOrDefault(p => p.Id.Value == TestConstants.FreePlanSubscriptionPlanId);
            var paidPlan = plans.Entity.SubscriptionPlans.FirstOrDefault(p => p.Id.Value == TestConstants.MediumSubscriptionPlanId);

            Assert.NotNull(freePlan);
            Assert.NotNull(paidPlan);

            var creditCard = new CreditCard
                    {
                        CardType = "visa",
                        ExpirationMonth = 12,
                        ExpirationYear = 2012,
                        FirstName = "Tester",
                        LastName = "Testing",
                        Number = TestConstants.ValidCard,
                        VerificationValue = "123"
                    };

            var payment = new Payment
                  {
                      AccountType = "credit-card",
                      CreditCard = creditCard
                  };
            
            _subscribers.SubscribeSubscriberToFreeTrial(subscriber.CustomerId, freePlan);

            var invoiceResponse = invoiceFactory.CreateInvoice(new Invoice
            {
                SubscriptionPlanId = paidPlan.Id,
                Subscriber = subscriber
            });

            var invoice = invoiceResponse.Entity;

            Assert.NotNull(invoice);

            invoiceFactory.PayInvoice(invoice, payment);

            _subscribers.AllowSubscriberAnotherFreeTrial(subscriber.CustomerId);

            _subscribers.SubscribeSubscriberToFreeTrial(sub.Entity.CustomerId, freePlan);
        }
Example #3
0
 public SpreedlyResponse<Invoice> PayInvoice(Invoice invoice, Payment payment)
 {
     var urlSegment = string.Format("invoices/{0}/pay.xml", invoice.Token);
     return _client.Put<Invoice>(urlSegment, payment);
 }