PHP code example of it-pirs / konnektive-api

1. Go to this page and download the library: Download it-pirs/konnektive-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

it-pirs / konnektive-api example snippets


use Konnektive\Dispatcher;

class OfferProcessor {
    public function addCustomerNote(){
        $dispatcher = new Dispatcher();
        /**
        * @var $request \Konnektive\Request\Customer\AddCustomerNoteRequest;
        */
        $request = new AddCustomerNoteRequest();
        $request->loginId = "SomeValidStringForID";
        $request->password = "SomeValidPassword";
        $request->customerId = "123123";
        $request->message = "TestMessage";
        /**
        * @var $response \Konnektive\Response\Response;
        */
        $response = $dispatcher->handle($request);
        if($response->isSuccessful()){
            //Do the thing.
        }
    }
}

use Konnektive\Contracts\IHandler;

class CustomHandler implements IHandler
{
    /**
    * @var $request \Konnektive\Request\Request
    * @return \Konnektive\Response\Response
    */
    public function handle(Request $request){
        //Handle that request
        return new Response(/* Some response data from cUrl */);
    }
}

$dispatcher = new Dispatcher(new CustomHandler());
////
$dispatcher->setHandler(new CustomHandler());

/**
* @var $request \Konnektive\Request\Customer\AddCustomerNoteRequest;
*/
$request = new AddCustomerNoteRequest();
$request->loginId = "SomeValidStringForID";
$request->message = "TestMessage";
try {
    $request->validate();
} catch(ValidationException $ex){
    //Fails for customerId and password
}