I've been tasked with creating a one-time payment solution for the sale of a single type of item (documents) using Laravel Cashier. The documents themselves have no fixed price as they are constantly amended, so, anytime a customer purchases a document(s) through the site each document price is calculated on the fly (price per page) and I create a paymentIntent with the basket subtotal. This is then passed to Stripe's front-end form components.
This payment payment loop works fine, however, I have been asked to provide Invoices to customers that get resolved instantly on payment, for record keeping. I've been trying to create an itemized invoice but the 'tab' and 'priceTab' method require me to provide a product ID. Can I create Invoices on the fly without the product ID?
$subtotal = 0;
$basket = session()->get("basket", []);
foreach ($basket["items"] as $item) {
$subtotal += calculate_price($number_of_pages = $item->pages);
}
$order = Orders::create([
"status" => "incomplete",
"total_price" => $subtotal,
"currency" => "GBP",
"customer_id" => Auth::user()->id
]);
$subtotal = (float)$subtotal * 100;
$items = [];
foreach ($basket["items"] as $document) {
$doc_price = calculate_price($number_of_pages = $document->pages);
OrderDocuments::create([
"order_id" => $order->id,
"document_id" => $document->id,
"document_title" => $document->title,
"price" => $doc_price
]);
// This doesn't seem to be possible without a priceID
// Auth::user()->tab($document->title, $doc_price, ["price_data" => [
// "currency" => "gbp"
// ]]);
}
$intent_payload = [
"currency" => "gbp",
"metadata" => [
"order_id" => $order->id
]
];
$payment_intent = Auth::user()->pay($subtotal, $intent_payload);
// create an invoice instead of intent? Something like $payment_intent = Auth::user()->invoice(); ?
In the Docs for Cashier, it recommends the invoiceFor method for one-time purchases, however looking at the source in ManagesInvoices.php this method uses the 'tab' method which requires an "price_data" array (currency, productID etc) and throws when I don't provide this data. Am I on the right track here or am I wrong in assuming I can do invoicing this way?