invoice API for PHP Laravel
Invoice API for PHP and Laravel
Create an invoice from PHP or a Laravel controller. The same endpoint serves both. Do not commit the API key.
Base URL https://invoicetxt.com Auth Authorization: Bearer itxt_live_…
POST/v1/invoices
PHP without a framework
cURL is enough. Decode the response and use the url field in the text message you send the customer.
$body = json_encode([
'client' => 'Kamau Homes',
'due' => 'net 7',
'items' => [
['description' => 'Electrical work', 'quantity' => 6, 'rate' => 45],
['description' => 'Materials', 'quantity' => 1, 'rate' => 120],
],
]);
$ch = curl_init('https://invoicetxt.com/v1/invoices');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HTTPHEADER => ['Authorization: Bearer '.getenv('INVOICETXT_API_KEY'), 'Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true,
]);
$invoice = json_decode(curl_exec($ch), true);
curl_close($ch);POST/v1/invoices
Laravel
From a controller, Http::withToken reads the key from config that points at the environment. Return your own JSON to the browser. Do not return the API key.
$invoice = Http::withToken(config('services.invoicetxt.key'))
->post('https://invoicetxt.com/v1/invoices', [
'client' => $request->string('client'),
'due' => 'on receipt',
'items' => $request->input('items'),
])->throw()->json();