Secure-eBook

Secure-eBook Documentation

PHP SDK version 1.1.0

The PHP SDK is a relatively straightforward encapsulation of the Secure-eBook XML API.

The definition for all SDK error codes can be found here:

Download

Step 1 - Including the SDK in your PHP project

In order to use the object, you must download the API and include the SDK in your PHP project.

Example

  // Include the PHP SDK.  Make sure the specified path fits your custom configuration.
  require_once('sebSDK.php');

Step 2 - Instantiating the SDK

The SDK is encapsulated in a simple to use class. The class name is SebSDK.

Secure-eBook SDK Constructor

function SebSDK($vendorCode, $sdkKey, $testMode = false, $sdkURL = false)
  ...
ParameterNameDescription
$vendorCodeThe Secure-eBook vendor codeThis code identifies the account under which the activation keys and download links will be generated. The Vendor Code can be found in the Secure-eBook Account Information. Look for Vendor Code in My Account → Account Information.
$sdkKeyThe Secure-eBook SDK secret keywordThis keyword must be set in your Secure-eBook account. The keyword is known by Secure-eBook and the third party application and is used to validate the identity of the software using the SDK. Look for SDK Secret Keyword in My Account → Account Information. [more]
$testModeEnable test modeDisabled by default. If turned on, the whole activation/download link process will work, but no actual keys or links will be generated and tokens will consumed from the vendor account. This mode is to help you test your integration with Secure-eBook SDK
$sdkURLThe URL of the Secure-eBook SDKAllows to connect to an alternative server. At the time of this documentation, no alternate Secure-eBook servers are available.

Example

// Create a SDK instance for account ADMI4176 in test mode.
$sdk = new SebSDK("ADMI4176", "a#$%^#6vkl3", true);

Step 3 - Request Activation Keys / Secured Download Links

The SDK allows you to request multiple keys and links in one transaction. This is done through the request method of the SebSDK class. Whether keys, links or both are returned is based in the product's configuration in its linked Secure-eBook account.

function request($products, $secureebookproductcode = true, $userdata = false, $orderinfo = false)
ParameterNameDescription
$productsArray of product informationThe product array is composed of any number of strings representing the Product Code for which a key or link is requested and arrays in which the first item is the Product code and the second item is the number of keys or links required. When no quantity is specified, 1 is always assumed.
$secureebookproductcode true,falseIf set to “true”, the specified product codes will be considered as Secure-eBook product codes. If set to “false”, product codes will be considered as shopping cart product codes.
$userdataString that identifies your transactionOptional. Will be stored with the transaction information in Secure-eBook
$orderinfoAssociative array containing order informationOptional. Information specified here will be stored with the transaction information in Secure-eBook. Accepted values are name, email, country (2 char. ISO 31661 country code, stateprov (state or province), note, total (incl. taxes), taxes, currency (USD, CAD, GBP, AUD), description

Example

$keys = $sdk->request(
  array('TEST', array('TEST2', 2)),  // Request one key for book 'TEST' and two keys for book 'TEST2'
true,                               // Uses the Secure-eBook product's code.    
'order1',                          // Our system labels this order as 'order1', which will be stored on the Secure-eBook server.
   array('name' => 'John Doe',       // We also send the client's name and email address.
	 'email' => 'johndoe@nowhere.com')
  );

Step 4 - Analysing Results

If all goes well, the request method returns an array containing activation keys and/or download links. However, if something goes wrong, it will return false. Error codes and messages can be retrieved through the SebSDK class' last_error and last_error_id fields.

last_errorGives a textual representation of the error
last_error_idGives a numerical representation of the error, allowing you to customize the feeback you want to show. Error codes are described in the definition of the error XML SDK response.

Example

if ($res === false)  // triple equal makes sure that we are really looking for 'false'
{
  echo "Error " . $sdk->last_error . " (" . $sdk->last_error_id . "}";
}

Step 5 - Receiving keys, links and Warnings

The request method returns an associative array (map) containing keys and warnings.

Receiving keys

The keys returned by the request method are stored in an array. This array is obtained by accessing the 'keys' value of the returned results.

The elements of this array are associative arrays in which the following values have been set:

productcodeThe Secure-eBook product's code or the Shopping Cart product’s code to which the key is bound
keyAn activation key

:!: Since Secure-eBook does not send emails for transactions that go through the SDK system, we strongly suggest that all proper activation and troubleshooting information is given to customers.

The activation guide can be found here: http://secure-ebook.com/help/ebook_activation
Troubleshooting guide can be found here: http://secure-ebook.com/help/ebook_activation_assistance

Receiving Links

The links returned by the request method are stored in an array. This array is obtained by accessing the 'links' value of the returned results.

The elements of this array are associative arrays in which the following values have been set:

productcodeThe Secure-eBook product's code or the Shopping Cart product’s code to which the key is bound
urlA secured download link
expirationA date in 'YYYY-MM-DD' format, in GMT time zone after which the link will be disabled.
max_downloadsThe number of times a download attempt can be made through this link. After the file download has been initiated this number of times, the link will be disabled.

:!: Since Secure-eBook does not send emails for transactions that go through the SDK system, we strongly suggest that all proper activation and troubleshooting information is given to customers.

The activation guide can be found here: http://secure-ebook.com/help/ebook_activation
Troubleshooting guide can be found here: http://secure-ebook.com/help/ebook_activation_assistance

Receiving Warnings

The warnings returned by the request method are stored in an array. This array is obtained by accessing the 'warnings' value of the returned results.

The elements of this array are associative arrays in which the following values have been set:

productcodeThe Secure-eBook product's code or the Shopping Cart product’s code to which the warning is related to.
messageidGives a numerical representation of the error, allowing you to customize the feeback you want to show. Error codes are described in the definition of the success XML SDK response.
textGives a textual representation of the warning

Example

if ($res === false)  // triple equal makes sure that we are really looking for 'false'
{
  echo "Error " . $sdk->last_error . " (" . $sdk->last_error_id . "}";
}
else
{  
   if ( $res['keys'] )
   {
      foreach($res['keys'] as $key)
      {
         echo $key['productcode'] . ' = ' . $key['key'] . '<br/>';
      }
   }
 
   // Generated links are returned here
   if ($res['links'])
   {
     foreach($res['links'] as $link)
     {
       echo "Link <strong>" . $link['url'] . "</strong> for <em>" . $link['productcode'] . "</em><br/>";
     }
   }
 
   if ( $res['warnings'] )
   {
      foreach($res['warnings'] as $warning)
      {
          echo $warning['productcode'] . ' = ' . $warning['messageid'] . '<br/>';          
	  echo $warning['text'] . "<br/>";
      }
   }	
}

Advanced Integration Techniques