php 为条带付款创建发票

vfh0ocws  于 2023-01-16  发布在  PHP
关注(0)|答案(2)|浏览(152)

我使用Stripe进行一次性付款和订阅。
要创建付款,我使用Stripe Checkout:

\Stripe\Checkout\Session::create([
    'customer' => 'cus_XXXXX',
    'success_url' => '',
    'cancel_url' => '',
    'payment_method_types' => ['card'],
    'mode' => ($isSubscription ? 'subscription' : 'payment'),
    'line_items' => [...]
]);

header('Location: '.$checkout_session->url);
exit;

此代码自动创建订阅模式的发票,但不是一次性付款。
我已经尝试过创建新发票,但如何才能使其与以前的付款、已关闭和已支付相关联?

$stripe = new Stripe\StripeClient('xxx');
$stripe->invoiceItems->create([
    'customer' => 'cus_XXXXX',
    'amount' => '1000',
    'currency' => 'eur',
    'description' => 'Lorem ipsum...'
]);
$invoice = $stripe->invoices->create([
    'customer' => 'cus_XXXXX',
]);
xqnpmsa8

xqnpmsa81#

我找到了一种方法来创建一个发票,为每个付款标记支付。
然而,这并不能将它们与付款联系起来。
在webhook checkout.session.completed上执行以下操作:

$stripe = new Stripe\StripeClient('xxx');

// Create invoice lines
$stripe->invoiceItems->create([
    'customer' => 'cus_XXXXX',
    'amount' => '1000',
    'currency' => 'eur',
    'description' => 'Lorem ipsum...'
]);

// Create invoice
$invoice = $stripe->invoices->create([
    'customer' => 'cus_XXXXX',
]);

// Finalize and mark invoice paid outside of Stripe
$invoice->finalizeInvoice();
$invoice->pay(['paid_out_of_band' => true]);
jtw3ybtb

jtw3ybtb2#

我相信你在找这个:https://stripe.com/docs/payments/checkout/post-payment-invoices
要启用发票创建,请在创建“ checkout ”会话时将invoice_creation[enabled]设置为true。

相关问题