【问题标题】:Nothing to invoice for subscription - create an invoice when the purchase is reviewed无需为订阅开具发票 - 在审核购买时创建发票
【发布时间】:2021-06-01 12:08:30
【问题描述】:

现在我正在尝试在审核购买后创建发票。

如果客户购买了会员资格,我希望将发票 ID 分配给我的数据库,因为 webhook 能够通过链接将 pdf 发票分配给数据库。

当我尝试在代码中最后生成发票时。然后我不幸遇到了这个错误。

无需为订阅开具发票

Stripe Error link

当我查看 Stripe 日志时,这来自错误。

   {
      "error": {
        "code": "invoice_no_subscription_line_items",
        "doc_url": "https://stripe.com/docs/error-codes/invoice-no-subscription-line-items",
        "message": "Nothing to invoice for subscription",
        "param": "subscription",
        "type": "invalid_request_error"
      }
    }

因此,我的请求 POST 正文是这样的:

{
  "customer": "cus_J2ltIOWhr2BSGX",
  "subscription": "sub_J2lto4EVvcfToq"
}

在这里你可以看到我如何发布请求到条带。

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

var addService = new CustomerService();
var customer = await addService.CreateAsync(createCustomer);

var optionsProduct = new ProductCreateOptions
{
    Name = $"Membership - {DateTime.Now}",
    Type = "service",
};
var serviceProduct = new ProductService();
Product product = await serviceProduct.CreateAsync(optionsProduct);

var optionsA = new PriceCreateOptions
{
    UnitAmount = amount,
    Currency = "dkk",
    Recurring = new PriceRecurringOptions
    {
        Interval = Helpers.Stripe.interval,
    },
    Product = product.Id,
};
var serviceA = new PriceService();
var price = await serviceA.CreateAsync(optionsA);

var options = new SubscriptionCreateOptions
{
    Customer = customer.Id,
    Items = new List<SubscriptionItemOptions>
    {
        new SubscriptionItemOptions
        {
            Price = price.Id,
        },
    },
};
var service = new SubscriptionService();
var subscription = await service.CreateAsync(options);

var optionsI = new InvoiceCreateOptions
{
    Customer = customer.Id,
    Subscription = subscription.Id
};
var serviceI = new InvoiceService();
var invoice = await serviceI.CreateAsync(optionsI);//I NEED INVOICE ID FROM HERE!

我试着看这里。

Adding shipping to first subscription invoice using stripe

EIDT:

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

                        var addService = new CustomerService();
                        var customer = addService.Create(createCustomer);

                        var options = new ChargeCreateOptions
                        {
                            Amount = amount,
                            Currency = "dkk",
                            Description = $"Købt kursus {DateTime.Now}",
                            Customer = customer.Id,
                        };
                        var service = new ChargeService();
                        Charge charge = service.Create(options);

【问题讨论】:

    标签: c# stripe-payments


    【解决方案1】:

    如果您使用订阅,系统会根据结算周期为您自动生成发票。

    如果打印出刚刚创建的 Subscription 对象,您可以在 latest_invoice 下找到 Invoice ID。

    -- 关于一次性付款的更新--

    费用和发票是 Stripe API 中的两个独立概念。收费非常简单,其唯一目的是创建和付款。发票更复杂,并且除了付款之外还具有附加功能(行项目、自动功能、税收等)。任何一个都可以使用,但这实际上取决于您的业务需求。

    如果您想使用发票进行一次性付款,则需要更改您的代码来创建它们(请参阅https://stripe.com/docs/api/invoices/create)。您的代码目前仅适用于 Charges - 这些不是 Stripe 的计费产品的一部分,不会自动生成发票。

    【讨论】:

    • omg...很好,感谢您的帮助!祝你有美好的一天!
    • 您是否知道,例如,您是否也使用过收费。如何获取您的发票 ID?我将它用于客户必须能够支付一次且仅一次。 :)
    • 您是在创建费用还是一次性发票?我问是因为仅创建费用不会生成发票。
    • 好的,这意味着我必须以相同的方式进行操作,并在设置中进行一些更改或什么? @karbi :)
    • 如果您总是需要发票,您应该创建一次性发票而不是费用。这里有一个简短的指南:stripe.com/docs/billing/invoices/create
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 2015-04-09
    相关资源
    最近更新 更多