Reputation: 1717
I'm using Stripe for one-time payments and subscriptions.
To create a payment, I use 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;
This code automatically create an invoice for subscription mode but not for one-time payments.
I've tried this to create a new invoice but how can I do to make it related to previous payment, closed and paid?
$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',
]);
Upvotes: 1
Views: 2589
Reputation: 111
I believe you are looking for this: https://stripe.com/docs/payments/checkout/post-payment-invoices
To enable invoice creation, set invoice_creation[enabled] to true when creating a Checkout session.
Upvotes: 0
Reputation: 1717
I found a way to create an invoice for each payment mark paid.
This, however, doesn't link them to a payment.
On the webhook checkout.session.completed
do the following:
$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]);
Upvotes: 5