如何创建没有客户 ID 的条带发票

How to create a stripe invoice without customer id

我正在尝试通过条带生成发票,但 API 需要一个我不知道如何检索的客户 ID。

我正在使用会话结帐:

ajax

调用的方法
$checkout_session = Checkout\Session::create([
            'payment_method_types' => ['card'],
            'line_items' => [[
                'price_data' => [
                    'currency' => 'usd',
                    'unit_amount' => 2000,
                    'product_data' => [
                        'name' => 'Stubborn Attachments',
                        'images' => ["https://i.imgur.com/EHyR2nP.png"],
                    ],
                ],
                'quantity' => 1,
            ]],
            'customer_email' => $email,
            'mode' => 'payment',
            'success_url' => $domain. '/success/{CHECKOUT_SESSION_ID}',
            'cancel_url' => $domain. '/cancel/{CHECKOUT_SESSION_ID}',
        ]);

我收到

[
    "id" => "cs_test_xxxxxxxxxxxxxxxx"
    "object" => "checkout.session"
    "allow_promotion_codes" => null
    "amount_subtotal" => 2000
    "amount_total" => 2000
    "billing_address_collection" => null
    "cancel_url" => "http://localhost/cancel/{CHECKOUT_SESSION_ID}"
    "client_reference_id" => null
    "currency" => "usd"
    "customer" => null
    "customer_details" => null
    "customer_email" => "xxxxxxxxxxx@gmail.com"
    "livemode" => false
    "locale" => null
    "metadata" => []
    "mode" => "payment"
    "payment_intent" => "pi_xxxxxxxxxxxxx"
    "payment_method_options" => []
    "payment_method_types" => array:1 [
      0 => "card"
    ]
    "payment_status" => "unpaid"
    "setup_intent" => null
    "shipping" => null
    "shipping_address_collection" => null
    "submit_type" => null
    "subscription" => null
    "success_url" => "http://localhost/success/{CHECKOUT_SESSION_ID}"
    "total_details" => array:3 [
      "amount_discount" => 0
      "amount_shipping" => 0
      "amount_tax" => 0
    ]
  ]

Create invoice 需要一个我没有的客户 ID,也不知道从哪里获取,因为会话结账创建了一个客户而没有给我一个 ID。

payment 模式下的结帐会话将生成付款意向,而不是发票。如果您只想使用发票,那么结帐会话不是正确的解决方案。如果您不关心发票,只想向客户收取一次性付款,那么您可以继续使用 Checkout。

如果您确实只想使用发票,则需要执行以下操作:

  1. 创建 Customer
  2. 创建任意数量的 Invoice Items 时传入客户 ID
  3. 创建 Invoice 时传入客户 ID - 这将自动提取与客户相关的任何待处理发票项目。

本指南对此进行了总结:https://stripe.com/docs/invoicing/integration