C# Invoicer PDF提供null,但成员身份不提供PDF null
我现在的问题是。我必须这样做,顾客可以购买一件只付一次钱的物品。因此,将发票id和PDf分配给数据库 就目前而言,当PDF为空时,我只获得发票id 我读了更多关于这方面的内容。 如果我这样做,我会从中解脱出来。我在这里得到了我想要的发票ID,但是发票上没有显示为零的内容C# Invoicer PDF提供null,但成员身份不提供PDF null,c#,stripe-payments,C#,Stripe Payments,我现在的问题是。我必须这样做,顾客可以购买一件只付一次钱的物品。因此,将发票id和PDf分配给数据库 就目前而言,当PDF为空时,我只获得发票id 我读了更多关于这方面的内容。 如果我这样做,我会从中解脱出来。我在这里得到了我想要的发票ID,但是发票上没有显示为零的内容 { "id": "ii_1IR4UtFnB7TvDVRrzPwWo8ZW", "object": "invoiceitem", "
{
"id": "ii_1IR4UtFnB7TvDVRrzPwWo8ZW",
"object": "invoiceitem",
"amount": 2000,
"currency": "usd",
"customer": "cus_J3Aqpyt4PwqCcN",
"date": 1614815575,
"description": "Starter Setup",
"discountable": true,
"discounts": [
],
"invoice": null,
"livemode": false,
"metadata": {
},
....
}
有了这一点,我的想法是,我是否能够在某种程度上,使我成为会员,然后立即停止,但它在发票上说,购买只是一个单一的项目,而不是几个月
就会员资格而言,我是这样做的
var createCustomer = new CustomerCreateOptions
{
Source = token,
Name = model.FuldName,
Email = model.Mail
};
var addService = new CustomerService();
var customer = addService.Create(createCustomer);
var optionsProduct = new ProductCreateOptions
{
Name = $"Single buy - {DateTime.Now} - Kursus Id : {id}",
Type = "service",
};
var serviceProduct = new ProductService();
Product product = serviceProduct.Create(optionsProduct);
var optionsPlan = new PlanCreateOptions
{
Currency = "dkk",
Interval = Helpers.Stripe.interval,
Nickname =
$"Single buy - {DateTime.Now} - Kursus Id : {id}",
Amount = amount,
Product = product.Id,
IntervalCount = 1
};
var servicePlan = new PlanService();
Plan plan = servicePlan.Create(optionsPlan);
var items = new List<SubscriptionItemOptions>()
{
new SubscriptionItemOptions()
{
Plan = plan.Id,
Quantity = 1
},
};
var createSubscruptionA = new SubscriptionCreateOptions
{
Customer = customer.Id,
Items = items,
OffSession = true,
};
var addserviceA = new SubscriptionService();
Subscription subscription = addserviceA.Create(createSubscruptionA);
var invoiceId = subscription.LatestInvoiceId;
var service = new InvoiceService();
var pdf = service.Get(invoiceId).InvoicePdf;
对于一次性发票,您需要为客户创建发票项目(正如您所做的),但重要的是,您需要创建包含这些项目的发票项目 这一行对于您试图实现的目标是不正确的:
var invoiceId = invoiceItem.Id;
相反,您需要创建发票,如上面链接的文档所示:
var invoiceOptions = new InvoiceCreateOptions
{
Customer = "cus_123",
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
发票对象将具有一个Invoice\u pdf
URL()
好的,当我尝试执行您告诉我的操作时,我得到一个错误,上面写着“没有为客户开具发票”-是的,您需要先创建发票项,然后为同一客户创建发票。好的@nolan H。我已经更新/编辑了我的代码。所以你可以看看我做了什么。或者是我误解了事情的真相?好吧,现在结果如何?它起作用了吗?如果没有,会发生什么?这不起作用,这给了我同样的错误
var invoiceId = invoiceItem.Id;
var invoiceOptions = new InvoiceCreateOptions
{
Customer = "cus_123",
AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);
var service = new InvoiceService();
service.FinalizeInvoice(
"in_123"
);