Using Invoice4U API with PHP

Invoice4U is an Israeli based service for creating invoices and receipts.
The documentation does not include an example of how to make the call using PHP.

Below is a short example of how to do so for the InvoiceReciept:Create call. I used the ConvertCharSet component to make the conversion from UTF-8 to windows-1255 (which is the encoding expected).

A note on mandatory fields: the 4 item fields (InvoiceItemCode, InvoiceItemDescription, InvoiceItemPrice, InvoiceItemQuantity) are mandatory. At the time of writing this post, this is not explicit in the documentation.

<?php
require_once 'ConvertCharset.class.php';

$cc=new ConvertCharset;

$current_encoding = 'UTF-8';
$new_encoding = 'windows-1255';

$data = '';
$data .= 'TransType=' . $cc->convert('IR:CREATE', $current_encoding, $new_encoding);
$data .= '&Username=' . $cc->convert('a4u_heb', $current_encoding, $new_encoding);
$data .= '&InvoiceSubject=' . $cc->convert('test', $current_encoding, $new_encoding);
$data .= '&InvoiceItemCode=' . $cc->convert('a1000001a', $current_encoding, $new_encoding);
$data .= '&InvoiceItemDescription=' . $cc->convert('description', $current_encoding, $new_encoding);
$data .= '&InvoiceItemQuantity=' . $cc->convert('1', $current_encoding, $new_encoding);
$data .= '&InvoiceItemPrice=' . $cc->convert('10', $current_encoding, $new_encoding);
$data .= '&CompanyInfo=' . $cc->convert('און בן-צבי', $current_encoding, $new_encoding);
$data .= '&MailTo=' . $cc->convert('onn.benzvi@gmail.com', $current_encoding, new_encoding);

$curl_url = 'https://www.invoice4u.co.il/public/HttpPost.aspx';

$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $curl_url);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0); // ignore ssl verification errors
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, 0); // ignore ssl verification errors
curl_setopt($cURL, CURLOPT_HEADER, 1); // Don't return header info.
curl_setopt($cURL, CURLOPT_RETURNTRANSFER,1); // Return into a variable.
curl_setopt($cURL, CURLOPT_POST, 1);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $data);//$pnp_post_values);
$val_from_curl = curl_exec($cURL);
?>

Leave a comment