Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theinventor/8badec9a2696526c6b90 to your computer and use it in GitHub Desktop.
Save theinventor/8badec9a2696526c6b90 to your computer and use it in GitHub Desktop.
<?php
$subdomain = 'subdomain';
$api_key = 'api_key';
$api_version = '/api/v1';
$base_url = "https://$subdomain.repairshopr.com";
$subtotal = 150.00;
$number = '12345';
$invoice = array();
$invoice["date"] = date('Y-m-d H:i:s');
$invoice["paid"] = true;
$invoice["date_received"] = date('Y-m-d H:i:s');
$invoice["number"] = $number;
$invoice["phone"] = '4255551212';
$invoice["line_items"] = array(
array("item" => "Labor", "name" => "Field Service Labor", "cost" => 12.0, "price" => 100, "quantity" => 1),
array("item" => "Labor", "name" => "Field Service Labor Visit 2", "cost" => 12.0, "price" => 100, "quantity" => 0.5)
);
$data_string = json_encode($invoice);
$ch = curl_init("{$base_url}{$api_version}/invoices.json?api_key=$api_key");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
//get the result
$result = curl_exec($ch);
//close connection
curl_close($ch);
@techinaflash
Copy link

Just add these two lines around line 10 and it's perfect.

$customer_id = "123456";
$invoice["customer_id"] = $customer_id;

I think $subtotal isn't used at all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment