static void TestCreateInvoiceItems(StripePayment payment) { StripeCustomer cust = payment.CreateCustomer(new StripeCustomerInfo()); StripeInvoiceItemInfo info = GetInvoiceItemInfo(); info.CustomerID = cust.ID; StripeInvoiceItem item = payment.CreateInvoiceItem(info); StripeInvoiceItemInfo newInfo = GetInvoiceItemInfo(); newInfo.Description = "Invoice item: " + Guid.NewGuid().ToString(); StripeInvoiceItem item2 = payment.UpdateInvoiceItem(item.ID, newInfo); StripeInvoiceItem item3 = payment.GetInvoiceItem(item2.ID); if (item.Description == item3.Description) { throw new Exception("Update failed"); } StripeInvoiceItem deleted = payment.DeleteInvoiceItem(item2.ID); if (!deleted.Deleted.HasValue && deleted.Deleted.Value) { throw new Exception("Delete failed"); } var items = payment.GetInvoiceItems(10, 10, null); Console.WriteLine(items.Total); payment.DeleteCustomer(cust.ID); }
public async Task <InvoiceItemResult> InvoiceItemCreated(InvoiceItem invoiceItem) { _logger.LogInformation(GetLogMessage("Item Id: {0}"), invoiceItem.Id); var retVal = new InvoiceItemResult() { InvoiceItemId = invoiceItem.Id }; var entity = new StripeInvoiceItem { ObjectState = ObjectState.Added, Id = invoiceItem.Id, Created = invoiceItem.Date, PeriodStart = invoiceItem.Period.Start, PeriodEnd = invoiceItem.Period.End, IsDeleted = invoiceItem.Deleted.GetValueOrDefault() }; entity.InjectFrom(invoiceItem); if (invoiceItem.Metadata.ContainsKey("contract-id")) { _logger.LogDebug(GetLogMessage("contract id found in metadata: {0}"), invoiceItem.Metadata["contract-id"]); entity.ContractId = Guid.Parse(invoiceItem.Metadata["contract-id"]); retVal.ContractId = entity.ContractId.Value; } else { _logger.LogDebug(GetLogMessage("Contract id not found in metadata")); } var entityRecords = _items.InsertOrUpdateGraph(entity, true); _logger.LogDebug(GetLogMessage("{0} records updated"), entityRecords); if (entityRecords > 0) { retVal.Succeeded = true; } var contract = await _contracts .Queryable() .Include(x => x.TimeEntries) .Where(x => x.Id == retVal.ContractId) .FirstAsync(); var timeEntriesToProcess = contract .TimeEntries .Where(x => x.Status == TimeStatus.Approved && x.InvoiceItemId == null) .ToList(); _logger.LogDebug(GetLogMessage("Ready to process {0} time entries"), timeEntriesToProcess.Count); foreach (var entry in timeEntriesToProcess) { _logger.LogDebug(GetLogMessage("Entry: {0}; Invoice Item: {1}"), entry.Id, invoiceItem.Id); entry.InvoiceItemId = invoiceItem.Id; entry.ObjectState = ObjectState.Modified; entry.Updated = DateTimeOffset.UtcNow; } if (timeEntriesToProcess.Count > 0) { _logger.LogDebug(GetLogMessage("Preparing to update database with updated data")); retVal.TimeEntriesUpdated = timeEntriesToProcess.Count; var records = _contracts.InsertOrUpdateGraph(contract, true); _logger.LogDebug(GetLogMessage("{0} Records Updated"), records); } return(retVal); }