header('Content-Type: text/plain');
require '../ChargeOverAPI.php';
//This url should be specific to your ChargeOver instance
$url = 'http://dev.chargeover.com/api/v3';
//$url = 'https://YOUR-INSTANCE-NAME.chargeover.com/api/v3';
$authmode = ChargeOverAPI::AUTHMODE_HTTP_BASIC;
$username = '******';
$password = '******';
$API = new ChargeOverAPI($url, $authmode, $username, $password);
// The invoice we want to update
$invoice_id = 10009;
// Build up the object
$Invoice = new ChargeOverAPI_Object_Invoice();
$Invoice->setDate('2015-06-08');
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setItemId(3);
$LineItem->setLineRate(29.95);
$LineItem->setLineQuantity(3);
$LineItem->setDescrip('Add this new line item to the invoice.');
$Invoice->addLineItems($LineItem);
// To keep the existing line item, you have to pass the line_item_id
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setLineItemId(2575);
$Invoice->addLineItems($LineItem);
$resp = $API->modify($invoice_id, $Invoice);
/*
print("\n\n\n\n");
print($API->lastRequest());
print("\n\n\n\n");
print($API->lastResponse());
print("\n\n\n\n");
$API = new ChargeOverAPI($url, $authmode, $username, $password);
$your_subscription_id = 'abcd1234' . mt_rand(0, 1000);
// Create a new billing package
$Package = new ChargeOverAPI_Object_Package();
$Package->setCustomerId(1);
// Tell the package to not invoice until the 1st
$Package->setHolduntilDatetime(date('Y-m-01', strtotime('+1 month')));
// Here is your unique subscription ID #
$Package->setExternalKey($your_subscription_id);
// This is for our data usage
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setItemId(13);
$Package->addLineItems($LineItem);
// This is for our extra # of devices
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setItemId(14);
$Package->addLineItems($LineItem);
$resp = $API->create($Package);
if ($resp->response->id) {
    // Created the package!
    // Now, every day you want to push new usage to it
    // Get the package
    $resp = $API->find('package', array('external_key:EQUALS:' . $your_subscription_id));
    $resp = $API->findById('package', $resp->response[0]->getPackageId());
    $Package = $resp->response;
    $Lines = $Package->getLineItems();
    foreach ($Lines as $Line) {
        if ($Line->getItemExternalKey() == 'data') {
            // @todo Go fetch the usage from your database for the # of gigabytes
            $usage_data = 5;
            // 5 gigabytes
//$url = 'https://YOUR-INSTANCE-NAME.chargeover.com/api/v3';
$authmode = ChargeOverAPI::AUTHMODE_HTTP_BASIC;
$username = '******';
$password = '******';
$API = new ChargeOverAPI($url, $authmode, $username, $password);
$Package = new ChargeOverAPI_Object_Package();
$Package->setCustomerId(18);
// Tell it to use whatever ACH account is on file for this customer
//$Package->setPaymethod('ach');
//$Package->setPaymethod('crd');  // ... or whichever credit card
// By default, ChargeOver will create MONTHLY recurring packages - but you can change this:
//$Package->setPaycycle('yrl');  // yearly
//$Package->setPaycycle('qtr');  // quarterly
// @todo more cycles docs
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setItemId(1);
//$LineItem->setDescrip('Test of a description goes here.');
$LineItem->setTrialDays(20);
$LineItem->setLineQuantity(15);
$Package->addLineItems($LineItem);
$resp = $API->create($Package);
if (!$API->isError($resp)) {
    $package_id = $resp->response->id;
    print 'SUCCESS! Package # is: ' . $package_id;
} else {
    print 'Error saving package via API' . "\n";
    print 'Error message was: ' . $resp->code . ': ' . $resp->message . "\n";
    print "\n\n\n\n";
    print $API->lastRequest();
    print "\n\n\n\n";
    print $API->lastResponse();
<?php

header('Content-Type: text/plain');
require '../ChargeOverAPI.php';
//This url should be specific to your ChargeOver instance
$url = 'http://dev.chargeover.com/api/v3';
//$url = 'https://YOUR-INSTANCE-NAME.chargeover.com/api/v3';
$authmode = ChargeOverAPI::AUTHMODE_HTTP_BASIC;
$username = '******';
$password = '******';
$API = new ChargeOverAPI($url, $authmode, $username, $password);
$Invoice = new ChargeOverAPI_Object_Invoice();
$Invoice->setCustomerId(1);
$Invoice->setDate('2014-01-02');
$LineItem = new ChargeOverAPI_Object_LineItem();
$LineItem->setItemId(4);
$LineItem->setLineRate(29.95);
$LineItem->setLineQuantity(3);
$LineItem->setDescrip('Test of a description goes here.');
$Invoice->addLineItems($LineItem);
$LineItem = clone $LineItem;
$LineItem->setLineQuantity(2);
$Invoice->addLineItems($LineItem);
//print_r($Invoice->__toString());
$resp = $API->create($Invoice);
/*
print("\n\n\n\n");
	print($API->lastRequest());
	print("\n\n\n\n");
	print($API->lastResponse());
	print("\n\n\n\n");