|
| 1 | + |
| 2 | + |
| 3 | +# Invoice Parser for PHP 8 |
| 4 | + |
| 5 | +## 🎯 Extract structured data from invoices (PDF/DOC/DOCX/TXT/RTF) — powered by SharpAPI AI. |
| 6 | + |
| 7 | +[](https://packagist.org/packages/sharpapi/php-finance-parse-invoice) |
| 8 | +[](https://packagist.org/packages/sharpapi/php-finance-parse-invoice) |
| 9 | + |
| 10 | +Check the full documentation on the [Invoice Parsing API](https://sharpapi.com/en/catalog/ai/finance/invoice-parsing) page. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +## Quick Links |
| 15 | + |
| 16 | +| Resource | Link | |
| 17 | +|----------|------| |
| 18 | +| **Main API Documentation** | [Authorization, Webhooks, Polling & More](https://documenter.getpostman.com/view/31106842/2s9Ye8faUp) | |
| 19 | +| **Postman Documentation** | [View Docs](https://documenter.getpostman.com/view/31106842/2sBXVeGsaE) | |
| 20 | +| **Product Details** | [SharpAPI.com](https://sharpapi.com/en/catalog/ai/finance/invoice-parsing) | |
| 21 | +| **SDK Libraries** | [GitHub - SharpAPI SDKs](https://github.com/sharpapi) | |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Requirements |
| 26 | + |
| 27 | +- PHP >= 8.0 |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Installation |
| 32 | + |
| 33 | +### Step 1. Install the package via Composer: |
| 34 | + |
| 35 | +```bash |
| 36 | +composer require sharpapi/php-finance-parse-invoice |
| 37 | +``` |
| 38 | + |
| 39 | +### Step 2. Visit [SharpAPI](https://sharpapi.com/) to get your API key. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## What it does |
| 44 | + |
| 45 | +This package uploads an invoice file to the SharpAPI AI endpoint and returns a status URL to poll for results. When the job completes, you can fetch a structured JSON containing parsed invoice data (seller, buyer, line items, financials, tax details, and more). |
| 46 | + |
| 47 | +--- |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +```php |
| 52 | +<?php |
| 53 | + |
| 54 | +require __DIR__ . '/vendor/autoload.php'; |
| 55 | + |
| 56 | +use SharpAPI\FinanceParseInvoice\InvoiceParserClient; |
| 57 | +use GuzzleHttp\Exception\GuzzleException; |
| 58 | + |
| 59 | +$invoicePath = __DIR__ . '/invoice.pdf'; // make sure this file exists |
| 60 | + |
| 61 | +$client = new InvoiceParserClient(apiKey: 'your_api_key_here'); |
| 62 | + |
| 63 | +try { |
| 64 | + // submit parsing job |
| 65 | + $statusUrl = $client->parseInvoice($invoicePath); |
| 66 | + |
| 67 | + // Optional: adjust polling settings |
| 68 | + $client->setApiJobStatusPollingInterval(10); // seconds |
| 69 | + $client->setApiJobStatusPollingWait(180); // seconds total wait |
| 70 | + |
| 71 | + // fetch results when ready |
| 72 | + $result = $client->fetchResults($statusUrl)->toArray(); |
| 73 | + print_r($result); |
| 74 | +} catch (GuzzleException $e) { |
| 75 | + // Handle SharpAPI or network errors |
| 76 | + echo $e->getMessage(); |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Example Response |
| 83 | + |
| 84 | +```json |
| 85 | +{ |
| 86 | + "data": { |
| 87 | + "type": "api_job_result", |
| 88 | + "id": "c09ad101-209f-460f-afaf-4fd9a735f79d", |
| 89 | + "attributes": { |
| 90 | + "status": "success", |
| 91 | + "type": "invoice_parse", |
| 92 | + "result": { |
| 93 | + "document": { |
| 94 | + "type": "invoice", |
| 95 | + "original_type_label": "", |
| 96 | + "is_copy": false, |
| 97 | + "copy_type": null |
| 98 | + }, |
| 99 | + "invoice": { |
| 100 | + "invoice_number": "D7BDFA00-0019", |
| 101 | + "issue_date": "2025-12-07", |
| 102 | + "due_date": "2025-12-07", |
| 103 | + "document_date": null, |
| 104 | + "order_date": null, |
| 105 | + "delivery_date": null, |
| 106 | + "shipping_date": null, |
| 107 | + "pricing_date": null, |
| 108 | + "currency": "USD", |
| 109 | + "exchange_rate": null, |
| 110 | + "page_info": "1 of 1", |
| 111 | + "amount_in_words": "", |
| 112 | + "notes": "", |
| 113 | + "remarks": "", |
| 114 | + "delivery_instructions": "", |
| 115 | + "terms_and_conditions": [], |
| 116 | + "late_payment_interest_rate": null |
| 117 | + }, |
| 118 | + "references": { |
| 119 | + "delivery_order_number": "", |
| 120 | + "purchase_order_number": "", |
| 121 | + "sales_order_number": "", |
| 122 | + "customer_reference": "", |
| 123 | + "external_document_number": "", |
| 124 | + "grn_number": "", |
| 125 | + "route_number": "", |
| 126 | + "lorry_number": "", |
| 127 | + "serial_number": "", |
| 128 | + "batch_number": "", |
| 129 | + "other_references": [] |
| 130 | + }, |
| 131 | + "e_invoice": { |
| 132 | + "uuid": "", |
| 133 | + "e_invoice_code": "", |
| 134 | + "e_invoice_type": "", |
| 135 | + "e_invoice_version": "", |
| 136 | + "submission_id": "", |
| 137 | + "submission_document_id": "", |
| 138 | + "submission_long_id": "", |
| 139 | + "submission_status": "", |
| 140 | + "validation_datetime": null, |
| 141 | + "digital_signature_present": false, |
| 142 | + "validated_link": "", |
| 143 | + "original_e_invoice_ref": "", |
| 144 | + "qr_code_present": false |
| 145 | + }, |
| 146 | + "seller": { |
| 147 | + "name": "OpenAl, LLC", |
| 148 | + "trade_name": "OpenAl", |
| 149 | + "registration_number": "", |
| 150 | + "tin": "", |
| 151 | + "sst_id": "", |
| 152 | + "gst_id": "", |
| 153 | + "vat_id": "GB434338990", |
| 154 | + "msic_code": "", |
| 155 | + "business_activity": "", |
| 156 | + "address": { |
| 157 | + "street_line_1": "548 Market Street", |
| 158 | + "street_line_2": "PMB 97273", |
| 159 | + "city": "San Francisco", |
| 160 | + "state": "California", |
| 161 | + "postcode": "94104-5401", |
| 162 | + "country": "US" |
| 163 | + }, |
| 164 | + "phone": "", |
| 165 | + "fax": "", |
| 166 | + "email": "", |
| 167 | + "website": "", |
| 168 | + "bank_details": [], |
| 169 | + "contact_person": { |
| 170 | + "name": "", |
| 171 | + "role": "", |
| 172 | + "phone": "", |
| 173 | + "email": "" |
| 174 | + } |
| 175 | + }, |
| 176 | + "buyer": { |
| 177 | + "name": "A2Z WEB LTD", |
| 178 | + "trade_name": "", |
| 179 | + "registration_number": "", |
| 180 | + "tin": "", |
| 181 | + "brn": "", |
| 182 | + "sst_id": "", |
| 183 | + "gst_id": "", |
| 184 | + "vat_id": "", |
| 185 | + "customer_account_number": "", |
| 186 | + "billing_address": { |
| 187 | + "location_name": "", |
| 188 | + "street_line_1": "Unit 4e Enterprise Court, Farfield", |
| 189 | + "street_line_2": "Park", |
| 190 | + "city": "Rotherham", |
| 191 | + "state": "", |
| 192 | + "postcode": "S63 5DB", |
| 193 | + "country": "GB" |
| 194 | + }, |
| 195 | + "delivery_address": { |
| 196 | + "recipient_name": "", |
| 197 | + "location_name": "", |
| 198 | + "street_line_1": "Unit 10 Enterprise Court", |
| 199 | + "street_line_2": "Farfield Park", |
| 200 | + "city": "Rotherham", |
| 201 | + "state": "", |
| 202 | + "postcode": "S63 5DB", |
| 203 | + "country": "GB" |
| 204 | + }, |
| 205 | + "delivery_address_same_as_billing": false, |
| 206 | + "phone": "", |
| 207 | + "fax": "", |
| 208 | + "email": "", |
| 209 | + "attention_to": { |
| 210 | + "name": "", |
| 211 | + "phone": "", |
| 212 | + "email": "" |
| 213 | + } |
| 214 | + }, |
| 215 | + "sales_info": { |
| 216 | + "salesperson_name": "", |
| 217 | + "salesperson_code": "", |
| 218 | + "salesperson_phone": "", |
| 219 | + "sales_agent": "", |
| 220 | + "sales_location": "", |
| 221 | + "sales_department": "", |
| 222 | + "outlet_name": "" |
| 223 | + }, |
| 224 | + "financials": { |
| 225 | + "subtotal": 15.57, |
| 226 | + "gross_amount": null, |
| 227 | + "total_discount_amount": null, |
| 228 | + "shipping_charge": null, |
| 229 | + "delivery_fee": null, |
| 230 | + "total_excl_tax": 15.57, |
| 231 | + "total_tax_amount": 3.11, |
| 232 | + "service_tax_amount": null, |
| 233 | + "total_incl_tax": 18.68, |
| 234 | + "rounding_adjustment": null, |
| 235 | + "total_payable": 18.68, |
| 236 | + "amount_paid": null, |
| 237 | + "amount_due": 18.68, |
| 238 | + "tax_details": [ |
| 239 | + { |
| 240 | + "tax_type": "VAT", |
| 241 | + "tax_rate": 20, |
| 242 | + "taxable_amount": 15.57, |
| 243 | + "tax_amount": 3.11 |
| 244 | + } |
| 245 | + ] |
| 246 | + }, |
| 247 | + "line_items": [ |
| 248 | + { |
| 249 | + "line_number": 1, |
| 250 | + "item_code": "", |
| 251 | + "stock_code": "", |
| 252 | + "barcode": "", |
| 253 | + "description": "OpenAl API usage credit", |
| 254 | + "classification_code": "", |
| 255 | + "country_of_origin": "", |
| 256 | + "quantity": 1, |
| 257 | + "free_quantity": null, |
| 258 | + "unit_of_measure": "unit", |
| 259 | + "unit_of_measure_raw": "", |
| 260 | + "pack_size": "", |
| 261 | + "total_units": null, |
| 262 | + "weight": null, |
| 263 | + "weight_uom": "", |
| 264 | + "unit_price": 15.57, |
| 265 | + "discount_percent": null, |
| 266 | + "discount_amount": null, |
| 267 | + "subtotal": 15.57, |
| 268 | + "tax_rate": 20, |
| 269 | + "tax_type": "VAT", |
| 270 | + "tax_amount": 3.11, |
| 271 | + "total_excl_tax": 15.57, |
| 272 | + "total_incl_tax": 18.68, |
| 273 | + "expiry_date": null, |
| 274 | + "batch_lot_number": "", |
| 275 | + "service_start_date": null, |
| 276 | + "service_end_date": null |
| 277 | + } |
| 278 | + ], |
| 279 | + "payment": { |
| 280 | + "payment_terms": "", |
| 281 | + "payment_terms_days": null, |
| 282 | + "payment_method": "", |
| 283 | + "payment_date": null, |
| 284 | + "payment_reference": "", |
| 285 | + "jompay_biller_code": "", |
| 286 | + "jompay_ref_1": "" |
| 287 | + }, |
| 288 | + "logistics": { |
| 289 | + "shipping_method": "", |
| 290 | + "vehicle_number": "", |
| 291 | + "driver_name": "", |
| 292 | + "delivery_zone": "", |
| 293 | + "delivery_time_constraint": "", |
| 294 | + "carton_count": null, |
| 295 | + "total_volume": null, |
| 296 | + "total_weight": null, |
| 297 | + "goods_received_confirmation": false, |
| 298 | + "received_by": "", |
| 299 | + "receiver_signature_present": false |
| 300 | + } |
| 301 | + } |
| 302 | + } |
| 303 | + } |
| 304 | +} |
| 305 | +``` |
| 306 | + |
| 307 | +--- |
| 308 | + |
| 309 | +## Changelog |
| 310 | + |
| 311 | +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. |
| 312 | + |
| 313 | +--- |
| 314 | + |
| 315 | +## Credits |
| 316 | + |
| 317 | +- [A2Z WEB LTD](https://github.com/a2zwebltd) |
| 318 | +- [Dawid Makowski](https://github.com/makowskid) |
| 319 | +- Boost your [PHP AI](https://sharpapi.com/) capabilities! |
| 320 | + |
| 321 | +--- |
| 322 | + |
| 323 | +## License |
| 324 | + |
| 325 | +[](LICENSE.md) |
| 326 | + |
| 327 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
| 328 | + |
| 329 | +--- |
| 330 | +## Social Media |
| 331 | + |
| 332 | +🚀 For the latest news, tutorials, and case studies, don't forget to follow us on: |
| 333 | +- [SharpAPI X (formerly Twitter)](https://x.com/SharpAPI) |
| 334 | +- [SharpAPI YouTube](https://www.youtube.com/@SharpAPI) |
| 335 | +- [SharpAPI Vimeo](https://vimeo.com/SharpAPI) |
| 336 | +- [SharpAPI LinkedIn](https://www.linkedin.com/products/a2z-web-ltd-sharpapicom-automate-with-aipowered-api/) |
| 337 | +- [SharpAPI Facebook](https://www.facebook.com/profile.php?id=61554115896974) |
0 commit comments