Created
August 11, 2014 18:31
-
-
Save theinventor/8badec9a2696526c6b90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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