Inheritance: StripeEntityWithId
Exemple #1
0
        public static Invoice Map(StripeInvoice stripeInvoice)
        {
            var invoice = new Invoice
            {
                AmountDue = stripeInvoice.AmountDue,
                ApplicationFee = stripeInvoice.ApplicationFee,
                AttemptCount = stripeInvoice.AttemptCount,
                Attempted = stripeInvoice.Attempted,
                Closed = stripeInvoice.Closed,
                Currency = stripeInvoice.Currency,
                Date = stripeInvoice.Date,
                Description = stripeInvoice.Description,
                // Discount = Map(stripeInvoice.StripeDiscount),
                EndingBalance = stripeInvoice.EndingBalance,
                Forgiven = stripeInvoice.Forgiven.HasValue && stripeInvoice.Forgiven.Value,
                NextPaymentAttempt = stripeInvoice.NextPaymentAttempt,
                Paid = stripeInvoice.Paid,
                PeriodStart = stripeInvoice.PeriodStart,
                PeriodEnd = stripeInvoice.PeriodEnd,
                ReceiptNumber = stripeInvoice.ReceiptNumber,
                StartingBalance = stripeInvoice.StartingBalance,
                StripeCustomerId = stripeInvoice.CustomerId,
                StatementDescriptor = stripeInvoice.StatementDescriptor,
                Tax = stripeInvoice.Tax,
                TaxPercent = stripeInvoice.TaxPercent,
                StripeId = stripeInvoice.Id,
                Subtotal = stripeInvoice.Subtotal,
                Total = stripeInvoice.Total,
                LineItems = Map(stripeInvoice.StripeInvoiceLineItems.Data)
            };

            return invoice;
        }
        private void InvoicePaymentFailed(StripeInvoice inv) {
            var org = _organizationRepository.GetByStripeCustomerId(inv.CustomerId);
            if (org == null) {
                Log.Error().Message("Unknown customer id in payment failed notification: {0}", inv.CustomerId).Write();
                return;
            }

            var user = _userRepository.GetById(org.BillingChangedByUserId);
            if (user == null) {
                Log.Error().Message("Unable to find billing user: {0}", org.BillingChangedByUserId).Write();
                return;
            }

            Log.Info().Message("Stripe payment failed. Customer: {0} Org: {1} Org Name: {2} Email: {3}", inv.CustomerId, org.Id, org.Name, user.EmailAddress).Write();

            _mailer.SendPaymentFailed(user, org);
        }
        private void InvoicePaymentSucceeded(StripeInvoice inv) {
            var org = _organizationRepository.GetByStripeCustomerId(inv.CustomerId);
            if (org == null) {
                Log.Error().Message("Unknown customer id in payment failed notification: {0}", inv.CustomerId).Write();
                return;
            }

            var user = _userRepository.GetById(org.BillingChangedByUserId);
            if (user == null) {
                Log.Error().Message("Unable to find billing user: {0}", org.BillingChangedByUserId).Write();
                return;
            }

            Log.Info().Message("Stripe payment succeeded. Customer: {0} Org: {1} Org Name: {2}", inv.CustomerId, org.Id, org.Name).Write();

            // TODO: Should we send an email here?
            //_mailer.SendPaymentSuccessAsync(user, org);
        }
        private async Task InvoicePaymentSucceededAsync(StripeInvoice inv) {
            var org = await _organizationRepository.GetByStripeCustomerIdAsync(inv.CustomerId).AnyContext();
            if (org == null) {
                Logger.Error().Message("Unknown customer id in payment failed notification: {0}", inv.CustomerId).Write();
                return;
            }

            var user = await _userRepository.GetByIdAsync(org.BillingChangedByUserId).AnyContext();
            if (user == null) {
                Logger.Error().Message("Unable to find billing user: {0}", org.BillingChangedByUserId).Write();
                return;
            }

            Logger.Info().Message("Stripe payment succeeded. Customer: {0} Org: {1} Org Name: {2}", inv.CustomerId, org.Id, org.Name).Write();
        }
Exemple #5
0
        void IEmailHelper.SendStripeInvoice(StripeInvoice invoice, string customerName, string customerEmail, string last4)
        {
            Guard.ArgumentNotNullOrEmptyString(customerName, "customerName");
            Guard.ArgumentNotNullOrEmptyString(customerEmail, "customerEmail");
            Guard.ArgumentNotNullOrEmptyString(last4, "last4");
            Guard.ArgumentNotNull(() => invoice);

            var values = new Dictionary<string, string>();
            decimal amount = Decimal.Divide((Decimal)invoice.AmountDueInCents, 100);
            values.Add("Last4", last4);
            values.Add("FirstName", customerName);
            values.Add("InvoiceDate", invoice.PeriodStart.ToString());
            values.Add("Amount", amount.ToString("C"));

            string fileName = String.Empty;
            if (root.Contains("~"))
            {
                fileName = System.Web.HttpContext.Current.Server.MapPath(root + "Invoice.txt");
            }
            else
            {
                fileName = root + "Invoice.txt";
            }

            var send = this as IEmailHelper;
            send.SetupEmail(values, customerEmail, fileName, "We Need You Have Subscription Information.");
        }
        private async Task InvoicePaymentFailedAsync(StripeInvoice inv) {
            var org = await _organizationRepository.GetByStripeCustomerIdAsync(inv.CustomerId).AnyContext();
            if (org == null) {
                _logger.Error("Unknown customer id in payment failed notification: {0}", inv.CustomerId);
                return;
            }

            var user = await _userRepository.GetByIdAsync(org.BillingChangedByUserId).AnyContext();
            if (user == null) {
                _logger.Error("Unable to find billing user: {0}", org.BillingChangedByUserId);
                return;
            }

            _logger.Info("Stripe payment failed. Customer: {0} Org: {1} Org Name: {2} Email: {3}", inv.CustomerId, org.Id, org.Name, user.EmailAddress);
            await _mailer.SendPaymentFailedAsync(user, org).AnyContext();
        }