Skip to content

cloudblue/connect-php-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect PHP SDK

CloudBlue Connect PHP fulfillment SDK

Getting Started

CloudBlue PHP SDK allows an easy and fast integration with CloudBlue Connect fulfillment API. Thanks to it you can automate the fulfillment of orders generated by your products.

In order to use this library, please ensure that you have read first the documentation available on CloudBlue Connect knowladge base article located here, this one will provide you a great information on the rest api that this library implements.

Class Features

This library may be consumed in your project in order to automate the fulfillment of requests, this class once imported into your project will allow you to:

  • Connect to CloudBlue Connect using your api credentials
  • List all requests, and even filter them:
    • for a Concrete product
    • for a concrete status
  • Process each request and obtain full details of the request
  • Modify for each request the activation parameters in order to:
    • Inquiry for changes
    • Store information into the fulfillment request
  • Change the status of the requests from it's initial pending state to either inquiring, failed or approved.
  • Generate logs
  • Collect debug logs in case of failure

Your code may use any scheduler to execute, from a simple cron to a cloud scheduler like the ones available in Azure, Google, Amazon or other cloud platforms.

Installation & loading

CloudBlue PHP SDK is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install CloudBlue PHP SDK. Just add this line to your composer.json file:

"cloudblue/connect-sdk": "~1.0"

or run

composer require cloudblue/connect-sdk

Note that the vendor folder and the vendor/autoload.php script are generated by Composer

A Simple Example

<?php

require_once "vendor/autoload.php";

/**
 * Class ProductRequests
 */
class ProductRequests extends \Connect\RequestsProcessor
{
    /**
     * ProductRequests constructor.
     * @param $config
     * @throws ReflectionException
     * @throws \Connect\ConfigException
     * @throws \Connect\ConfigPropertyInvalid
     * @throws \Connect\ConfigPropertyMissed
     */
    function __construct($config)
    {
        parent::__construct($config);
    }

    /**
     * @param \Connect\Request $request
     * @return string|void
     * @throws Exception
     * @throws \Connect\Exception
     * @throws \Connect\Fail
     * @throws \Connect\Skip
     */
    function processRequest($request)
    {
        Connect\Logger::get()->info("Processing Request: " . $request->id . " for asset: " . $request->asset->id);
        switch ($request->type) {
            case "purchase":
                if($request->asset->params['email']->value == ""){
                    throw new \Connect\Inquire(array(
                        $request->asset->params['email']->error("Email address has not been provided, please provide one")
                    ));
                }
                foreach ($request->asset->items as $item) {
                    if ($item->quantity > 1000000) {
                        Connect\Logger::get()->info("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
                        throw new \Connect\Fail("Is Not possible to purchase product " . $item->id . " more than 1000000 time, requested: " . $item->quantity);
                    }
                    else {
                        //Do some provisoning operation
                        //Update the parameters to store data
                        $paramsUpdate[] = new \Connect\Param('ActivationKey', 'somevalue');
                        return;
                    }
                }
            case "cancel":
                //Handle cancellation request
            case "change":
                //Handle change request
            default:
                throw new \Connect\Fail("Operation not supported:".$request->type);
        }
    }
}

//Main Code Block
try {
    $apiConfig = array(
        'apiKey' => 'Key_Available_in_ui',
        'apiEndpoint' => 'https://api.connect.cloud.im/public/v1',
        'products' => 'CN-631-322-641' #Optional value
    );
    $requests = new ProductRequests($apiConfig);
    $requests->process();
    
} catch (Exception $e) {
    print "Error processing requests:" . $e->getMessage();
}

Packages

No packages published

Contributors 5

Languages