Invoicer PDF 给出 null 但 Membership 不给出 PDF null

Invoicer PDF gives null but Membership does not give PDF null

我现在的问题。我一定是做了这样一个客户可以购买一件只需支付一次的商品。这样就把Invoice id和PDf赋给了数据库。

因为现在我只能在 PDF 为空时获取发票 ID。

我已经阅读了更多相关内容。 Invoice Id return with null after change using Stripe

var options = new ProductCreateOptions
{
    Name = "Starter Setup",
};

var service = new ProductService();
var product = service.Create(options);

var optionsA = new PriceCreateOptions
{
    Product = product.Id,
    UnitAmount = 2000,
    Currency = "usd",
};

var serviceA = new PriceService();
var price = serviceA.Create(optionsA);

var optionsB = new CustomerCreateOptions
{
    Email = model.Mail,
    Name = model.FuldName,
    Source = token
};

var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);

var optionsC = new InvoiceItemCreateOptions
{
    Customer = customer.Id,
    Price = price.Id,
};

var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);

var invoiceId = invoiceItem.Id;

var serviceE = new InvoiceService();
var f = serviceE.Get(invoiceId);

var pdf = f.InvoicePdf;// This here gives zero.

如果我这样做,我会解决这个问题。我在这里得到了我想要的发票 ID,但我在发票上没有看到任何显示它为零的信息。

{
"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;

我想通过这个实现的。它是我可以获得 PDF 和发票 ID,因为我将来会在我的系统中使用它等等。

编辑

var optionsB = new CustomerCreateOptions
{
    Email = model.Mail,
    Name = model.FuldName,
    Source = token
};

var serviceB = new CustomerService();
var customer = serviceB.Create(optionsB);

var optionsC = new InvoiceItemCreateOptions
{
    Customer = customer.Id,
    Price = price.Id,
};

var serviceC = new InvoiceItemService();
var invoiceItem = serviceC.Create(optionsC);

var invoiceId = invoiceItem.Id;

var invoiceOptions = new InvoiceCreateOptions
{
    Customer = customer.Id,
    AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);

对于一次性发票,您需要为客户创建发票项目(正如您所做的那样),但重要的是您随后需要 create an Invoice 包含这些项目。

此行不符合您要完成的目标:

var invoiceId = invoiceItem.Id;

相反,您需要创建发票,如上面链接的文档所示:

var invoiceOptions = new InvoiceCreateOptions
{
  Customer = "cus_123",
  AutoAdvance = true,
};
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(invoiceOptions);

Invoice 对象将有一个 invoice_pdf URL (docs) after you finalize 它。

var service = new InvoiceService();
service.FinalizeInvoice(
  "in_123"
);