private async Task SubscriptionUpdatedAsync(StripeSubscription sub) {
            var org = await _organizationRepository.GetByStripeCustomerIdAsync(sub.CustomerId).AnyContext();
            if (org == null) {
                Logger.Error().Message("Unknown customer id in updated subscription: {0}", sub.CustomerId).Write();
                return;
            }

            Logger.Info().Message("Stripe subscription updated. Customer: {0} Org: {1} Org Name: {2}", sub.CustomerId, org.Id, org.Name).Write();

            BillingStatus? status = null;
            switch (sub.Status) {
                case "trialing": {
                    status = BillingStatus.Trialing;
                    break;
                }
                case "active": {
                    status = BillingStatus.Active;
                    break;
                }
                case "past_due": {
                    status = BillingStatus.PastDue;
                    break;
                }
                case "canceled": {
                    status = BillingStatus.Canceled;
                    break;
                }
                case "unpaid": {
                    status = BillingStatus.Unpaid;
                    break;
                }
            }

            if (!status.HasValue || status.Value == org.BillingStatus)
                return;

            org.BillingStatus = status.Value;
            org.BillingChangeDate = DateTime.Now;
            if (status.Value == BillingStatus.Unpaid || status.Value == BillingStatus.Canceled) {
                org.IsSuspended = true;
                org.SuspensionDate = DateTime.Now;
                org.SuspensionCode = SuspensionCode.Billing;
                org.SuspensionNotes = $"Stripe subscription status changed to \"{status.Value}\".";
                org.SuspendedByUserId = "Stripe";
            } else if (status.Value == BillingStatus.Active || status.Value == BillingStatus.Trialing) {
                org.RemoveSuspension();
            }

            await _organizationRepository.SaveAsync(org).AnyContext();
        }
예제 #2
0
        private void SubscriptionDeleted(StripeSubscription sub) {
            var org = _organizationRepository.GetByStripeCustomerId(sub.CustomerId);
            if (org == null) {
                Log.Error().Message("Unknown customer id in deleted subscription: {0}", sub.CustomerId).Write();
                return;
            }

            Log.Info().Message("Stripe subscription deleted. Customer: {0} Org: {1} Org Name: {2}", sub.CustomerId, org.Id, org.Name).Write();

            org.BillingStatus = BillingStatus.Canceled;
            org.IsSuspended = true;
            org.SuspensionDate = DateTime.Now;
            org.SuspensionCode = SuspensionCode.Billing;
            org.SuspensionNotes = String.Format("Stripe subscription deleted.");
            org.SuspendedByUserId = "Stripe";

            org.BillingChangeDate = DateTime.Now;
            _organizationRepository.Save(org);
        }
        private async Task SubscriptionDeletedAsync(StripeSubscription sub) {
            var org = await _organizationRepository.GetByStripeCustomerIdAsync(sub.CustomerId).AnyContext();
            if (org == null) {
                Logger.Error().Message("Unknown customer id in deleted subscription: {0}", sub.CustomerId).Write();
                return;
            }

            Logger.Info().Message("Stripe subscription deleted. Customer: {0} Org: {1} Org Name: {2}", sub.CustomerId, org.Id, org.Name).Write();

            org.BillingStatus = BillingStatus.Canceled;
            org.IsSuspended = true;
            org.SuspensionDate = DateTime.Now;
            org.SuspensionCode = SuspensionCode.Billing;
            org.SuspensionNotes = "Stripe subscription deleted.";
            org.SuspendedByUserId = "Stripe";

            org.BillingChangeDate = DateTime.Now;
            await _organizationRepository.SaveAsync(org).AnyContext();
        }
예제 #4
0
        public void UpdateSubscription_ValidParameters_Successful()
        {
            //Arrange
            StripeSubscription subscription = new StripeSubscription();
            subscription.Id = subscriptionId;

            Mock<StripeSubscriptionService> custSubService = new Mock<StripeSubscriptionService>(null);
            custSubService.Setup(sub => sub.Update(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<StripeSubscriptionUpdateOptions>(), null)).Returns(subscription);
            stripeAccessor = new StripeAccessorService(custSubService.Object, charService.Object, cusService.Object);

            //Act
            string returnedId = stripeAccessor.UpdateSubscription(customerId, subscriptionId, planId);

            //Assert
            Assert.That(returnedId, Is.EqualTo(subscriptionId));
        }