【问题标题】:How does one create a Stripe order with invoice?如何创建带有发票的 Stripe 订单?
【发布时间】:2019-10-16 11:08:08
【问题描述】:

我有一个监听 invoice.payment_succces webhook 事件的 api 端点。每当我收到发票时,我都会通过电子邮件将指向它的链接发送给它的用户。

到目前为止,这对订阅有效,订阅会自动创建发票,但对订单似乎不一样。

每当我提交订单时(像这样)......

const order = await stripe.orders.create({
    customer: user.stripeCustomerId as string,
    currency: "usd",
    coupon: couponCode,
    items: [{
        type: "sku",
        parent: product.sku,
    }],
});
return stripe.orders.pay(order.id, {});

...订单已记录,付款发生,但从未生成发票。

如何让stripe在提交订单时创建发票?

【问题讨论】:

  • 订单不使用发票,如下所述。您可能想看看Checkout,它取代了旧的基于订单的版本,但现在使用单一付款或订阅。

标签: node.js stripe-payments


【解决方案1】:

如果您希望按订单发送一次性发票,请先配置您的发票

例如

const stripe = require('stripe')('<test key>');

stripe.invoiceItems.create({
  amount: 1000,
  currency: 'usd',
  customer: 'cus_4fdAW5ftNQow1a',
  description: 'Set-up fee',
});

接下来,您使用 await.stripe.invoices.create 准备“草稿”发票

const stripe = require('stripe')('<test key>');

(async () => {
  const invoice = await stripe.invoices.create({
    customer: 'cus_4fdAW5ftNQow1a',
    billing: 'send_invoice',
    days_until_due: 30,
  });
})();

发票草稿可以更新,当您准备好开票时,您可以敲定它:

const stripe = require('stripe')('<test key>');

stripe.invoices.sendInvoice(invoice.id, function(err, invoice) {
  // asynchronously called
});

源码取自stripe docs

如果我误解了这个问题,请发表评论。 (听起来您是按照问题的表述方式下订单的......)

希望对你有帮助

【讨论】:

  • 我正在尝试下订单,同时仍在创建发票。发票似乎仅用于订阅或一次性。我很确定目前不可能。
  • @SephReed 如果您是下订单的人,您需要的是订单确认/收据(而不是发票)吗?如果付款到期,则会发送发票,因此,如果您已付款,则需要收据。我不确定是否在 API 中发出收据,我对所有这些都不熟悉..
  • @SephReed 看看这个.. Automatically send receipts when payments are successful 使用 await.stripe.charges.create..
  • 那种。就我而言,我们有一个订阅套件,并且有一个一次性版本作为订单。我希望能够为订单和订阅使用相同的 webhook 事件和电子邮件模板(其中包括发票链接)。唉,看来两者根本不同,没有重叠。我确实看到了收据位。虽然没有api。这并不是一个真正成熟的功能。
  • @SephReed 有 PaymentsIntent API 吗?也许这更接近您正在寻找的东西..
猜你喜欢
  • 2018-11-05
  • 2012-08-11
  • 1970-01-01
  • 1970-01-01
  • 2021-04-19
  • 1970-01-01
  • 2018-07-26
  • 2023-03-28
  • 1970-01-01
相关资源
最近更新 更多