简体   繁体   English

无需为订阅开具发票 - 在审核购买时创建发票

[英]Nothing to invoice for subscription - create an invoice when the purchase is reviewed

Right now I am trying to create an invoice once the purchase has been reviewed.现在,我正在尝试在审核购买后创建发票。

It is the case that when the customer has bought the membership, I want invoice id to be assigned to my database in relation to the webhook being able to assign pdf invoice to the database with the link.在这种情况下,当客户购买了会员资格时,我希望将发票 ID 分配给我的数据库,因为 webhook 能够通过链接将 pdf 发票分配给数据库。

When I try to make invoice to last in the code.当我尝试在代码中制作发票时。 Then I am unfortunately met with this error.然后我不幸遇到了这个错误。

Nothing to invoice for subscription无需为订阅开具发票

Stripe Error link 条纹错误链接

When I look at Stripe logs this comes from errors.当我查看 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"
      }
    }

Thus, my Request POST body is like this:因此,我的请求 POST 正文是这样的:

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

And here can u see how i post request to stripe.在这里你可以看到我如何发布请求到条带。

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!

I have tried to look here.我试着看这里。

Adding shipping to first subscription invoice using stripe 使用条带将运费添加到第一张订阅发票

EIDT: 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);

If you're using Subscriptions, the Invoices will be generated automatically for you based on the billing cycle.如果您使用订阅,将根据计费周期为您自动生成发票。

If you print out the Subscription object you just created, you can find the Invoice ID under latest_invoice .如果您打印出刚刚创建的 Subscription object,您可以在latest_invoice下找到 Invoice ID。

-- UPDATE ABOUT ONE-TIME PAYMENTS -- -- 关于一次性付款的更新 --

Charges and Invoices are two separate concepts in Stripe's API.费用和发票是 Stripe 的 API 中的两个独立概念。 A Charge is very simple and it's only purpose is to create and make a payment.收费非常简单,其唯一目的是创建和付款。 Invoices are more complicated and have an added functionality (line items, automatic functionality, taxes, etc.) on top of just making a payment.发票更复杂,并且除了付款之外还具有附加功能(行项目、自动功能、税收等)。 Either one is fine to use, but it really depends on what your business needs are.任何一个都可以使用,但这实际上取决于您的业务需求。

If you want to be using Invoices for one-time payments, you will need to change your code to create them (see https://stripe.com/docs/api/invoices/create ).如果您想使用发票进行一次性付款,则需要更改代码以创建它们(请参阅https://stripe.com/docs/api/invoices/create )。 Your code currently only working with Charges - these are not part of Stripe's Billing product and will not generate an Invoice automatically.您的代码目前仅适用于费用 - 这些不是 Stripe 计费产品的一部分,不会自动生成发票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM