It is the case that I would very much like to get the invoice ID in the database or that I basically get the invoice url that I can throw in the database. Where the customer will be able to pick up the invoice.
I have found that it is after CREATING the invoice that I will first be able to download the urls that I will be able to use or when I have created it.
Basically, the mistake is that I have tried for several hours to find out how to retrieve the url for the invoice or that I just get the invoice url back that I want to be able to go through in the database.
var token = model.Source;
var trailDay = PricRules.PayUser.TrailDay;
var createCustomer = new CustomerCreateOptions
{
Source = token,
Email = userClass.Mail,
Name = userClass.FullName,
Description = $"UserId: {userClass.UserId} - CVR: {business.Cvr} - Navn: {business.Name} - TrailDay: {trailDay}"
};
var addService = new CustomerService();
var customer = await addService.CreateAsync(createCustomer);
var optionsProduct = new ProductCreateOptions
{
Name = $"Medlemskab - Brugerid: {userClass.UserId}",
Type = "service",
};
var serviceProduct = new ProductService();
Product product = serviceProduct.Create(optionsProduct);
var optionsPlan = new PlanCreateOptions
{
Currency = "dkk",
Interval = Stripe.interval,
Nickname = $"Medlemskab - InterVal: {Stripe.interval} Name: {userClass.FullName} - {DateTime.Now}",
Amount = amount,
Product = product.Id,
IntervalCount = getPriceClass.Month,
};
var servicePlan = new PlanService();
Plan plan = servicePlan.Create(optionsPlan);
var items = new List<SubscriptionItemOptions>()
{
new SubscriptionItemOptions()
{
Plan = plan.Id
}
};
var createSubscruption = new SubscriptionCreateOptions
{
Customer = customer.Id,
TrialEnd = new AnyOf<DateTime?, SubscriptionTrialEnd>(DateTime.Now.AddDays(trailDay)),
Items = items,
OffSession = true
};
var Addservice = new SubscriptionService();
Subscription subscription = Addservice.Create(createSubscruption);
var invoiceLink = ""; // HOW TO GET INVOICE URL/LINK HER? or Invoice Id
As you can see here at the bottom of code. So it basically does not matter if I get the invoice id or if it is the url. I am aware of how I make use of them.
You won't get an invoice link straight away, because it's dependent on an attempt to take a payment first.
You should setup a webhook to listen for invoice.created
events. Each event will contain an invoice
object, from which you can access the customer's id, the subscription id, and a link to the invoice, thus giving you enough information to link the invoice back to the correct customer.