Skip to content

Instantly share code, notes, and snippets.

@softlayer
Created June 30, 2010 20:11
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 softlayer/459156 to your computer and use it in GitHub Desktop.
Save softlayer/459156 to your computer and use it in GitHub Desktop.
<?php
/**
* Retrieve an account's next invoice information.
*
* This script retrieves the data presented in the SoftLayer Customer Portal's
* show next invoice page
* (https://manage.softlayer.com/Administrative/showNextInvoice) using a single
* API call. Next invoice information is retrieved from the billing items
* related to the servers and service you own with SoftLayer. It represents what
* is gauranteed to show on your next invoice, but doesn't represent one-time
* charges generated with your invoice like bandwidth and storage overage
* charges. See below for more details.
*
* This assumes the SoftLayer API PHP client
* <http://github.com/softlayer/softlayer-api-php-client> is installed in the
* directory '/SoftLayer' in this script's path and that you wish to use the
* SOAP client instead of our XML-RPC client.
*
* @see http://sldn.softlayer.com/reference/datatypes/SoftLayer_Account
* @license <http://sldn.softlayer.com/article/License>
* @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
// Include XmlrpcClient.class.php if you'd like to use our XML-RPC client
// instead.
require_once(dirname(__FILE__) . '/SoftLayer/SoapClient.class.php');
/**
* Your SoftLayer API username and key.
*
* Generate an API key at the SoftLayer Customer Portal:
* https://manage.softlayer.com/Administrative/apiKeychain
*/
$apiUsername = 'set me!';
$apiKey = 'set me too!';
// Connect to the SoftLayer_Account service
$client = Softlayer_SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
/**
* Specify which information to retrieve.
*
* The easiest way to retrieve a lot of information related to a single object
* all at once is to call the getObject() method in your API service. In this
* case all of our next invoice's information (and much much more) relates to
* our account record as relational properties to the SoftLayer_Account data
* type. We can retrieve all of this information with a single call with a
* single object mask. Object masks let you nest related properties, so there's
* no need to loop through results and make extra API calls.
*
* Define an API mask with the following structure:
* - nextInvoiceTotalAmount
* // The total amount that you're estimated to be charged during your next
* // invoice.
* - nextInvoiceTotalRecurringAmount
* // The portion of your next invoice's total charge that is caused by
* // monthly recurring fees.
* - nextInvoiceTotalRecurringTaxAmount
* // The portion of your next invoice's total charge that is caused by tax
* // levied on monthly recurring fees.
* - nextInvoiceTotalOneTimeAmount
* // The portion of your next invoice's total charge that is cause by
* // one-time fees.
* - nextInvoiceTotalOneTimeTaxAmount
* // The portion of your next invoice' total charge that is caused by tax
* // levied on one-time fees.
* - nextInvoiceTopLevelBillingItems
* // The top-level line items that will appear on your next invoice. These
* // items are typically for things like dedicated servers, cloud computing
* // instances, subnets, virtual dedicated racks, and the like.
* - children
* // The child items related to your top level line items. These refer to
* // things ike individual server componenets and virtual dedicated rack
* // members.
* - resource
* // The actual item (SoftLayer_Hardware_Server and other records) being
* // billed.
* - nextInvoiceTotalRecurringAmount
* // The top-level line item's monthly charge.
* - nextInvoiceTotalRecurringTaxAmount
* // The tax levied on the lop-level line item's monthly charge.
* - nextInvoiceTotalOneTimeAmount
* // The one-time charge associated with this top-level item.
* - nextInvoiceTotalOneTmeTaxAmount
* // The tax levied on the top-level item's one-time charge.
*
* @var SoftLayer_ObjectMask
*/
$objectMask = new SoftLayer_ObjectMask();
$objectMask->nextInvoiceTotalAmount;
$objectMask->nextInvoiceTotalRecurringAmount;
$objectMask->nextInvoiceTotalRecurringTaxAmount;
$objectMask->nextInvoiceTotalOneTimeAmount;
$objectMask->nextInvoiceTotalOneTimeTaxAmount;
$objectMask->nextInvoiceTopLevelBillingItems->children;
$objectMask->nextInvoiceTopLevelBillingItems->resource;
$objectMask->nextInvoiceTopLevelBillingItems->nextInvoiceTotalRecurringAmount;
$objectMask->nextInvoiceTopLevelBillingItems->nextInvoiceTotalRecurringTaxAmount;
$objectMask->nextInvoiceTopLevelBillingItems->nextInvoiceTotalOneTimeAmount;
$objectMask->nextInvoiceTopLevelBillingItems->nextInvoiceTotalOneTimeTaxAmount;
$client->setObjectMask($objectMask);
try {
/**
* Retrieve our account's record plus all of our extra information.
*
* This retrieves a lot of information. It may take a moment to retrieve,
* and we recommend caching its result if you plan on making this call
* often.
*
* Since there are numerous ways we can analyze this data, this example
* script will simply print_r() the full call result.
*/
$account = $client->getObject();
print_r($account);
} catch (Exception $e) {
die('Unable to next invoice information: ' . $e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment