Colorado Timberline APIA Practical Guide to Successful Integration

PHP Client Library

Overview

The PHP client library is our reference implementation which you can use directly or as a guideline for an implementation in a language we currently don’t have an implementation for.

Library Requirements

There are a few pre-reqs to use the library

  • PHP version >= 5.2.4
  • PHP modules: curl, dom, xsl, spl

You can determine if your environment is sufficient by simply running the sanity.php script from the command line

Insufficient System
$ php bin/sanity.php
------------------
FAIL
------------------
REQUIRED EXTENSION - curl - NOT INSTALLED
Sufficient System
$ php sanity.php
------------------
SUCCESS
------------------
Your environment is ready to run the CT API Client!

Download

ct-php-api-v1.9.1.zip

Usage Overview

There are some files in the example directory for all the supported methods. Further reading in this section of the site will walk you through the examples, however sending CT a test order once you’ve unpacked the library is trivial. First off, the configuration defaults to the staging environment, so really all you have to do is edit config/envs.php and put your supplied AffiliateID in, then run the example order submission script. You will also have to change the order id to something random as the order id in the example script has already been submitted.

Submitting a test order

Editing envs.php

// ct hosted, non-live environment
'staging' => array(
'sHttpProtocol' => 'http',
'sDomain' => 'api.staging.co-timber.com',
'sBaseUrl' => 'v15',
'sAffiliateId' => 'CT_55555',  /// PLACE *YOUR* AFFILIATE_ID HERE
'sPassword' => '',
'sLogLevel' => ''
),

Changing Order Number; example/order/submit.php

//----------------------------------------------------
// create CtOrder, parameterize the scalar values
//----------------------------------------------------
$oCtOrder = new CtOrder();
$oCtOrder->setPoNumber(444444);  // EDIT THE VALUE HERE; CHANGE TO SOMETHING RANDOM
$oCtOrder->setShipToName('Marissa Ann Jones');

Submitting Your First Test Order

$ php example/order/submit.php
-----------------
SUBMITTING ORDER:
-----------------
<!--?xml version="1.0"?-->
Marissa Ann Jones
28 Sunset DriveBurlingtonUSMA01803DHLSMARTMAIL
10/22/2009<img alt="" />
97894m light<img alt="" />
97894x dark
---------
RESPONSE:
---------
<!--?xml version="1.0" encoding="UTF-8"?-->

XML was well formed
Order 333333 accepted
Error in submission? no