Exemplo n.º 1
0
        public async Task <bool> CreateInvoiceAsync(Domain.Order order)
        {
            var customer = await getOrCreateCustomer(order);

            var service = new StripeInvoiceItemService();

            foreach (var line in order.OrderLines)
            {
                var createInvoiceLineOptions = new StripeInvoiceItemCreateOptions
                {
                    Amount      = (int)(line.LineTotal * 100m), // inclusive of quantity & tax
                    Currency    = "nok",                        // TODO: read this from config
                    CustomerId  = customer.Id,
                    Description = !string.IsNullOrWhiteSpace(line.ProductVariantName) ? $"{line.ProductName} ({line.ProductVariantName})" : line.ProductName,
                };
                var invoiceLineItem = await service.CreateAsync(createInvoiceLineOptions);
            }

            var eventInfo            = order.Registration.EventInfo;
            var createInvoiceOptions = new StripeInvoiceCreateOptions
            {
                Billing      = StripeBilling.SendInvoice,
                DaysUntilDue = eventInfo.DateStart.HasValue ? ((eventInfo.LastCancellationDate ?? eventInfo.LastRegistrationDate ?? eventInfo.DateStart) - DateTime.UtcNow).Value.Days : 30,
                Description  = $"Deltakelse for {order.Registration.ParticipantName} på {order.Registration.EventInfo.Title} "
            };
            var createInvoiceService = new StripeInvoiceService();
            await createInvoiceService.CreateAsync(customer.Id, createInvoiceOptions);

            return(true);
        }
        public creating_and_updating_invoices_with_manual_invoicing()
        {
            var customerService    = new StripeCustomerService(Cache.ApiKey);
            var invoiceItemService = new StripeInvoiceItemService(Cache.ApiKey);
            var invoiceService     = new StripeInvoiceService(Cache.ApiKey);

            var CustomerCreateOptions = new StripeCustomerCreateOptions
            {
                Email = "*****@*****.**",
            };
            var Customer = customerService.Create(CustomerCreateOptions);

            var InvoiceItemCreateOptions = new StripeInvoiceItemCreateOptions
            {
                Amount     = 1000,
                Currency   = "usd",
                CustomerId = Customer.Id
            };
            var InvoiceItem = invoiceItemService.Create(InvoiceItemCreateOptions);

            var InvoiceCreateOptions = new StripeInvoiceCreateOptions
            {
                Billing      = StripeBilling.SendInvoice,
                DaysUntilDue = 7,
            };

            InvoiceCreated = invoiceService.Create(Customer.Id, InvoiceCreateOptions);

            var InvoiceUpdateOptions = new StripeInvoiceUpdateOptions
            {
                Paid = true,
            };

            InvoiceUpdated = invoiceService.Update(InvoiceCreated.Id, InvoiceUpdateOptions);
        }
Exemplo n.º 3
0
        public async Task <InvoiceResult> CreateInvoiceAsync(InvoiceInfo info)
        {
            var customer = await GetOrCreateCustomer(info);

            var service = new StripeInvoiceItemService();

            foreach (var line in info.Lines.Where(l => l.Type == InvoiceLineType.Product))
            {
                await service.CreateAsync(new StripeInvoiceItemCreateOptions
                {
                    Amount      = (int)(line.Total ?? 0 * 100m), // inclusive of quantity & tax
                    Currency    = line.Currency,
                    CustomerId  = customer.Id,
                    Description = line.Description,
                });
            }

            var createInvoiceOptions = new StripeInvoiceCreateOptions
            {
                Billing      = StripeBilling.SendInvoice,
                DaysUntilDue = info.DueDate.HasValue
                    ? (info.DueDate.Value - SystemClock.Instance.Today()).Days
                    : 30,
                Description = string.Join(", ", info.Lines
                                          .Where(l => l.Type == InvoiceLineType.Text)
                                          .Select(l => l.Description))
            };
            var createInvoiceService = new StripeInvoiceService();
            var stripeInvoice        = await createInvoiceService.CreateAsync(customer.Id, createInvoiceOptions);

            return(new InvoiceResult(stripeInvoice.Id));
        }
        public StripeInvoiceServiceTest()
        {
            this.service = new StripeInvoiceService();

            this.createOptions = new StripeInvoiceCreateOptions()
            {
                TaxPercent = 12.5m,
            };

            this.updateOptions = new StripeInvoiceUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new StripeInvoiceListOptions()
            {
                Limit = 1,
            };

            this.listLineItemsOptions = new StripeInvoiceListLineItemsOptions()
            {
                Limit = 1,
            };

            this.upcomingOptions = new StripeUpcomingInvoiceOptions()
            {
                SubscriptionId = "sub_123",
            };
        }